@agirails/sdk 2.5.3 → 2.5.5
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 +72 -23
- package/dist/ACTPClient.js.map +1 -1
- package/dist/adapters/BasicAdapter.d.ts +15 -0
- package/dist/adapters/BasicAdapter.d.ts.map +1 -1
- package/dist/adapters/BasicAdapter.js +33 -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 +90 -12
- 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 +10 -2
- package/dist/config/networks.d.ts.map +1 -1
- package/dist/config/networks.js +31 -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 +11 -1
- package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
- package/dist/wallet/AutoWalletProvider.js +84 -19
- package/dist/wallet/AutoWalletProvider.js.map +1 -1
- package/dist/wallet/IWalletProvider.d.ts +34 -0
- package/dist/wallet/IWalletProvider.d.ts.map +1 -1
- package/dist/wallet/SmartWalletRouter.d.ts +128 -0
- package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
- package/dist/wallet/SmartWalletRouter.js +248 -0
- package/dist/wallet/SmartWalletRouter.js.map +1 -0
- package/dist/wallet/aa/DualNonceManager.d.ts +26 -1
- package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
- package/dist/wallet/aa/DualNonceManager.js +140 -6
- 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
|
@@ -1,364 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deploy:check Command - Pre-deploy security audit (AIP-13)
|
|
3
|
-
*
|
|
4
|
-
* Scans the project for common deployment security issues:
|
|
5
|
-
* - Missing ignore files
|
|
6
|
-
* - Raw private keys in env files, Dockerfiles, CI configs
|
|
7
|
-
* - Symlinked keystore
|
|
8
|
-
* - Incorrect file permissions
|
|
9
|
-
*
|
|
10
|
-
* Exit code 0: all checks pass (warnings allowed)
|
|
11
|
-
* Exit code 1: at least one FAIL check
|
|
12
|
-
*
|
|
13
|
-
* @module cli/commands/deploy-check
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import * as fs from 'fs';
|
|
17
|
-
import * as path from 'path';
|
|
18
|
-
import { Command } from 'commander';
|
|
19
|
-
import { Output, ExitCode } from '../utils/output';
|
|
20
|
-
import { getActpDir } from '../utils/config';
|
|
21
|
-
|
|
22
|
-
// ============================================================================
|
|
23
|
-
// Types
|
|
24
|
-
// ============================================================================
|
|
25
|
-
|
|
26
|
-
type CheckSeverity = 'FAIL' | 'WARN';
|
|
27
|
-
type CheckResult = 'PASS' | 'FAIL' | 'WARN' | 'SKIP';
|
|
28
|
-
|
|
29
|
-
interface CheckOutput {
|
|
30
|
-
name: string;
|
|
31
|
-
result: CheckResult;
|
|
32
|
-
message?: string;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// ============================================================================
|
|
36
|
-
// Command Definition
|
|
37
|
-
// ============================================================================
|
|
38
|
-
|
|
39
|
-
export function createDeployCheckCommand(): Command {
|
|
40
|
-
const cmd = new Command('deploy:check')
|
|
41
|
-
.description('Pre-deploy security audit (AIP-13)')
|
|
42
|
-
.option('--json', 'Output as JSON')
|
|
43
|
-
.option('-q, --quiet', 'Only show failures')
|
|
44
|
-
.action(async (options) => {
|
|
45
|
-
const output = new Output(
|
|
46
|
-
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const exitCode = runDeployCheck(options, output);
|
|
51
|
-
process.exit(exitCode);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
output.errorResult({
|
|
54
|
-
code: 'DEPLOY_CHECK_FAILED',
|
|
55
|
-
message: (error as Error).message,
|
|
56
|
-
});
|
|
57
|
-
process.exit(ExitCode.ERROR);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return cmd;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// ============================================================================
|
|
65
|
-
// Implementation
|
|
66
|
-
// ============================================================================
|
|
67
|
-
|
|
68
|
-
/** Regex matching a raw private key pattern */
|
|
69
|
-
const RAW_KEY_PATTERN = /0x[0-9a-fA-F]{64}/;
|
|
70
|
-
const RAW_KEY_ENV_PATTERN = /ACTP_PRIVATE_KEY\s*=\s*0x/;
|
|
71
|
-
|
|
72
|
-
interface DeployCheckOptions {
|
|
73
|
-
json?: boolean;
|
|
74
|
-
quiet?: boolean;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function runDeployCheck(options: DeployCheckOptions, output: Output): number {
|
|
78
|
-
const projectRoot = process.cwd();
|
|
79
|
-
const actpDir = getActpDir(projectRoot);
|
|
80
|
-
const results: CheckOutput[] = [];
|
|
81
|
-
let failCount = 0;
|
|
82
|
-
let warnCount = 0;
|
|
83
|
-
let passCount = 0;
|
|
84
|
-
|
|
85
|
-
// ── FAIL checks ──────────────────────────────────────────────────────
|
|
86
|
-
|
|
87
|
-
// 1. .actp/ in .gitignore
|
|
88
|
-
results.push(checkIgnoreFile(projectRoot, '.gitignore', '.actp', 'FAIL'));
|
|
89
|
-
|
|
90
|
-
// 2. .actp/ in .dockerignore
|
|
91
|
-
results.push(checkIgnoreFile(projectRoot, '.dockerignore', '.actp', 'FAIL'));
|
|
92
|
-
|
|
93
|
-
// 3. No ACTP_PRIVATE_KEY in .env* files
|
|
94
|
-
results.push(checkNoRawKeysInEnvFiles(projectRoot));
|
|
95
|
-
|
|
96
|
-
// 4. No raw keys in Dockerfiles
|
|
97
|
-
results.push(checkNoRawKeysInFiles(
|
|
98
|
-
projectRoot,
|
|
99
|
-
['Dockerfile', 'Dockerfile.*', 'docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'],
|
|
100
|
-
'No raw keys in Dockerfiles'
|
|
101
|
-
));
|
|
102
|
-
|
|
103
|
-
// 5. No raw keys in CI/workflow files
|
|
104
|
-
results.push(checkNoRawKeysInCIFiles(projectRoot));
|
|
105
|
-
|
|
106
|
-
// 6. Keystore is not a symlink
|
|
107
|
-
results.push(checkKeystoreNotSymlink(actpDir));
|
|
108
|
-
|
|
109
|
-
// ── WARN checks ──────────────────────────────────────────────────────
|
|
110
|
-
|
|
111
|
-
// 7. ACTP_KEYSTORE_BASE64 or keystore.json exists
|
|
112
|
-
results.push(checkKeystoreAvailable(actpDir));
|
|
113
|
-
|
|
114
|
-
// 8. Keystore file permissions (POSIX only)
|
|
115
|
-
results.push(checkKeystorePermissions(actpDir));
|
|
116
|
-
|
|
117
|
-
// ── Output ───────────────────────────────────────────────────────────
|
|
118
|
-
|
|
119
|
-
for (const check of results) {
|
|
120
|
-
if (check.result === 'FAIL') failCount++;
|
|
121
|
-
else if (check.result === 'WARN') warnCount++;
|
|
122
|
-
else if (check.result === 'PASS') passCount++;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (options.json) {
|
|
126
|
-
output.result({
|
|
127
|
-
checks: results,
|
|
128
|
-
summary: { passed: passCount, warnings: warnCount, failed: failCount },
|
|
129
|
-
});
|
|
130
|
-
} else {
|
|
131
|
-
output.print('actp deploy:check');
|
|
132
|
-
for (const check of results) {
|
|
133
|
-
if (options.quiet && check.result !== 'FAIL') continue;
|
|
134
|
-
const tag = `[${check.result}]`;
|
|
135
|
-
const msg = check.message ? ` ${check.message}` : '';
|
|
136
|
-
output.print(` ${tag} ${check.name}${msg}`);
|
|
137
|
-
}
|
|
138
|
-
output.print('');
|
|
139
|
-
output.print(` ${passCount} passed, ${warnCount} warnings, ${failCount} failed`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return failCount > 0 ? ExitCode.ERROR : ExitCode.SUCCESS;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// ============================================================================
|
|
146
|
-
// Individual Checks
|
|
147
|
-
// ============================================================================
|
|
148
|
-
|
|
149
|
-
function checkIgnoreFile(
|
|
150
|
-
projectRoot: string,
|
|
151
|
-
fileName: string,
|
|
152
|
-
entry: string,
|
|
153
|
-
_severity: CheckSeverity
|
|
154
|
-
): CheckOutput {
|
|
155
|
-
const filePath = path.join(projectRoot, fileName);
|
|
156
|
-
const name = `${entry} in ${fileName}`;
|
|
157
|
-
|
|
158
|
-
if (!fs.existsSync(filePath)) {
|
|
159
|
-
return { name, result: 'FAIL', message: `${fileName} does not exist` };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
163
|
-
if (content.includes(entry)) {
|
|
164
|
-
return { name, result: 'PASS' };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return { name, result: 'FAIL', message: `${entry} not found in ${fileName}` };
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function checkNoRawKeysInEnvFiles(projectRoot: string): CheckOutput {
|
|
171
|
-
const name = 'No raw keys in .env files';
|
|
172
|
-
const envFiles = findMatchingFiles(projectRoot, ['.env', '.env.*', '.env.local', '.env.production']);
|
|
173
|
-
|
|
174
|
-
for (const file of envFiles) {
|
|
175
|
-
const content = safeReadFile(file);
|
|
176
|
-
if (content && (RAW_KEY_PATTERN.test(content) || RAW_KEY_ENV_PATTERN.test(content))) {
|
|
177
|
-
return { name, result: 'FAIL', message: `Raw key found in ${path.basename(file)}` };
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return { name, result: 'PASS' };
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function checkNoRawKeysInFiles(
|
|
185
|
-
projectRoot: string,
|
|
186
|
-
patterns: string[],
|
|
187
|
-
name: string
|
|
188
|
-
): CheckOutput {
|
|
189
|
-
const files = findMatchingFiles(projectRoot, patterns);
|
|
190
|
-
|
|
191
|
-
for (const file of files) {
|
|
192
|
-
const content = safeReadFile(file);
|
|
193
|
-
if (content && RAW_KEY_PATTERN.test(content)) {
|
|
194
|
-
return { name, result: 'FAIL', message: `Raw key found in ${path.basename(file)}` };
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return { name, result: 'PASS' };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function checkNoRawKeysInCIFiles(projectRoot: string): CheckOutput {
|
|
202
|
-
const name = 'No raw keys in CI/workflow files';
|
|
203
|
-
|
|
204
|
-
// Collect all CI-related files
|
|
205
|
-
const files: string[] = [];
|
|
206
|
-
|
|
207
|
-
// GitHub workflows
|
|
208
|
-
const workflowDir = path.join(projectRoot, '.github', 'workflows');
|
|
209
|
-
if (fs.existsSync(workflowDir)) {
|
|
210
|
-
try {
|
|
211
|
-
const entries = fs.readdirSync(workflowDir);
|
|
212
|
-
for (const entry of entries) {
|
|
213
|
-
if (entry.endsWith('.yml') || entry.endsWith('.yaml')) {
|
|
214
|
-
files.push(path.join(workflowDir, entry));
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
} catch { /* ignore read errors */ }
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Platform config files
|
|
221
|
-
const platformFiles = [
|
|
222
|
-
'railway.json', 'fly.toml', 'vercel.json',
|
|
223
|
-
'pm2.config.js', 'pm2.config.cjs', 'ecosystem.config.js', 'ecosystem.config.cjs',
|
|
224
|
-
];
|
|
225
|
-
for (const pf of platformFiles) {
|
|
226
|
-
const fp = path.join(projectRoot, pf);
|
|
227
|
-
if (fs.existsSync(fp)) files.push(fp);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
for (const file of files) {
|
|
231
|
-
const content = safeReadFile(file);
|
|
232
|
-
if (content && (RAW_KEY_PATTERN.test(content) || RAW_KEY_ENV_PATTERN.test(content))) {
|
|
233
|
-
return { name, result: 'FAIL', message: `Raw key found in ${path.relative(projectRoot, file)}` };
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return { name, result: 'PASS' };
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
function checkKeystoreNotSymlink(actpDir: string): CheckOutput {
|
|
241
|
-
const name = 'Keystore is not a symlink';
|
|
242
|
-
const keystorePath = path.join(actpDir, 'keystore.json');
|
|
243
|
-
|
|
244
|
-
if (!fs.existsSync(keystorePath)) {
|
|
245
|
-
return { name, result: 'PASS' };
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
try {
|
|
249
|
-
const stat = fs.lstatSync(keystorePath);
|
|
250
|
-
if (stat.isSymbolicLink()) {
|
|
251
|
-
return { name, result: 'FAIL', message: 'keystore.json is a symlink (security risk)' };
|
|
252
|
-
}
|
|
253
|
-
} catch { /* ignore */ }
|
|
254
|
-
|
|
255
|
-
return { name, result: 'PASS' };
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function checkKeystoreAvailable(actpDir: string): CheckOutput {
|
|
259
|
-
const name = 'Keystore available';
|
|
260
|
-
const keystorePath = path.join(actpDir, 'keystore.json');
|
|
261
|
-
|
|
262
|
-
if (process.env.ACTP_KEYSTORE_BASE64) {
|
|
263
|
-
return { name, result: 'PASS' };
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (fs.existsSync(keystorePath)) {
|
|
267
|
-
return { name, result: 'PASS' };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return { name, result: 'WARN', message: 'ACTP_KEYSTORE_BASE64 not set (OK for local dev)' };
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function checkKeystorePermissions(actpDir: string): CheckOutput {
|
|
274
|
-
const name = 'Keystore file permissions';
|
|
275
|
-
const keystorePath = path.join(actpDir, 'keystore.json');
|
|
276
|
-
|
|
277
|
-
// Skip on Windows
|
|
278
|
-
if (process.platform === 'win32') {
|
|
279
|
-
return { name, result: 'SKIP', message: 'Permission check skipped on Windows' };
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (!fs.existsSync(keystorePath)) {
|
|
283
|
-
return { name, result: 'PASS' };
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
try {
|
|
287
|
-
const stat = fs.statSync(keystorePath);
|
|
288
|
-
const mode = stat.mode & 0o777;
|
|
289
|
-
if (mode === 0o600) {
|
|
290
|
-
return { name, result: 'PASS' };
|
|
291
|
-
}
|
|
292
|
-
return { name, result: 'WARN', message: `Permissions are 0o${mode.toString(8)} (expected 0o600)` };
|
|
293
|
-
} catch {
|
|
294
|
-
return { name, result: 'WARN', message: 'Could not check file permissions' };
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
// ============================================================================
|
|
299
|
-
// Helpers
|
|
300
|
-
// ============================================================================
|
|
301
|
-
|
|
302
|
-
/** Directories to skip during recursive scan */
|
|
303
|
-
const SKIP_DIRS = new Set(['node_modules', '.git', '.actp', 'dist', 'build', '.next', 'coverage']);
|
|
304
|
-
|
|
305
|
-
/** Max recursion depth to prevent runaway scans */
|
|
306
|
-
const MAX_SCAN_DEPTH = 5;
|
|
307
|
-
|
|
308
|
-
function findMatchingFiles(projectRoot: string, patterns: string[], maxDepth = MAX_SCAN_DEPTH): string[] {
|
|
309
|
-
const files: string[] = [];
|
|
310
|
-
walkDir(projectRoot, patterns, files, 0, maxDepth);
|
|
311
|
-
return files;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function walkDir(dir: string, patterns: string[], files: string[], depth: number, maxDepth: number): void {
|
|
315
|
-
if (depth > maxDepth) return;
|
|
316
|
-
|
|
317
|
-
let entries: string[];
|
|
318
|
-
try {
|
|
319
|
-
entries = fs.readdirSync(dir);
|
|
320
|
-
} catch { return; }
|
|
321
|
-
|
|
322
|
-
for (const entry of entries) {
|
|
323
|
-
const fullPath = path.join(dir, entry);
|
|
324
|
-
|
|
325
|
-
// Match files against patterns
|
|
326
|
-
for (const pattern of patterns) {
|
|
327
|
-
if (matchPattern(entry, pattern)) {
|
|
328
|
-
try {
|
|
329
|
-
if (fs.statSync(fullPath).isFile()) {
|
|
330
|
-
files.push(fullPath);
|
|
331
|
-
}
|
|
332
|
-
} catch { /* ignore */ }
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Recurse into subdirectories (skip noise dirs)
|
|
338
|
-
if (!SKIP_DIRS.has(entry)) {
|
|
339
|
-
try {
|
|
340
|
-
if (fs.statSync(fullPath).isDirectory()) {
|
|
341
|
-
walkDir(fullPath, patterns, files, depth + 1, maxDepth);
|
|
342
|
-
}
|
|
343
|
-
} catch { /* ignore */ }
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
function matchPattern(filename: string, pattern: string): boolean {
|
|
349
|
-
// Simple glob: support * and exact match
|
|
350
|
-
if (pattern === filename) return true;
|
|
351
|
-
if (pattern.includes('*')) {
|
|
352
|
-
const regex = new RegExp('^' + pattern.replace(/\./g, '\\.').replace(/\*/g, '.*') + '$');
|
|
353
|
-
return regex.test(filename);
|
|
354
|
-
}
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function safeReadFile(filePath: string): string | null {
|
|
359
|
-
try {
|
|
360
|
-
return fs.readFileSync(filePath, 'utf-8');
|
|
361
|
-
} catch {
|
|
362
|
-
return null;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deploy:env Command - Generate deployment environment variables (AIP-13)
|
|
3
|
-
*
|
|
4
|
-
* Reads .actp/keystore.json, base64-encodes it, and outputs env vars
|
|
5
|
-
* ready for any deployment platform (Railway, Vercel, Fly.io, Hetzner, etc.).
|
|
6
|
-
*
|
|
7
|
-
* @module cli/commands/deploy-env
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import { Command } from 'commander';
|
|
13
|
-
import { Output, ExitCode } from '../utils/output';
|
|
14
|
-
import { getActpDir } from '../utils/config';
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Command Definition
|
|
18
|
-
// ============================================================================
|
|
19
|
-
|
|
20
|
-
export function createDeployEnvCommand(): Command {
|
|
21
|
-
const cmd = new Command('deploy:env')
|
|
22
|
-
.description('Generate deployment env vars from keystore (AIP-13)')
|
|
23
|
-
.option('--format <format>', 'Output format: shell (default), docker, json', 'shell')
|
|
24
|
-
.option('--json', 'Machine-readable JSON output')
|
|
25
|
-
.option('-q, --quiet', 'Output only the base64 string (for piping)')
|
|
26
|
-
.action(async (options) => {
|
|
27
|
-
const output = new Output(
|
|
28
|
-
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
runDeployEnv(options, output);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
output.errorResult({
|
|
35
|
-
code: 'DEPLOY_ENV_FAILED',
|
|
36
|
-
message: (error as Error).message,
|
|
37
|
-
});
|
|
38
|
-
process.exit(ExitCode.ERROR);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return cmd;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ============================================================================
|
|
46
|
-
// Implementation
|
|
47
|
-
// ============================================================================
|
|
48
|
-
|
|
49
|
-
interface DeployEnvOptions {
|
|
50
|
-
format: string;
|
|
51
|
-
json?: boolean;
|
|
52
|
-
quiet?: boolean;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function runDeployEnv(options: DeployEnvOptions, output: Output): void {
|
|
56
|
-
const projectRoot = process.cwd();
|
|
57
|
-
const actpDir = getActpDir(projectRoot);
|
|
58
|
-
const keystorePath = path.join(actpDir, 'keystore.json');
|
|
59
|
-
|
|
60
|
-
if (!fs.existsSync(keystorePath)) {
|
|
61
|
-
throw new Error(
|
|
62
|
-
'No keystore found at ' + keystorePath + '\n' +
|
|
63
|
-
'Run "actp init" first to generate a wallet.'
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const keystoreContent = fs.readFileSync(keystorePath, 'utf-8');
|
|
68
|
-
|
|
69
|
-
// Validate it's valid JSON
|
|
70
|
-
try {
|
|
71
|
-
JSON.parse(keystoreContent);
|
|
72
|
-
} catch {
|
|
73
|
-
throw new Error('Keystore file is corrupted (not valid JSON).');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const base64 = Buffer.from(keystoreContent).toString('base64');
|
|
77
|
-
|
|
78
|
-
// Quiet mode: just the base64 string (for piping)
|
|
79
|
-
if (options.quiet) {
|
|
80
|
-
output.result({ keystoreBase64: base64 }, { quietKey: 'keystoreBase64' });
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// JSON mode
|
|
85
|
-
if (options.json || options.format === 'json') {
|
|
86
|
-
output.result({
|
|
87
|
-
keystoreBase64: base64,
|
|
88
|
-
passwordVar: 'ACTP_KEY_PASSWORD',
|
|
89
|
-
});
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// Docker format
|
|
94
|
-
if (options.format === 'docker') {
|
|
95
|
-
output.print('# Add to your Dockerfile:');
|
|
96
|
-
output.print(`ENV ACTP_KEYSTORE_BASE64="${base64}"`);
|
|
97
|
-
output.print('ENV ACTP_KEY_PASSWORD="<your keystore password>"');
|
|
98
|
-
output.print('');
|
|
99
|
-
output.print('# WARNING: Prefer build args or secrets over ENV for sensitive values.');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Shell format (default)
|
|
104
|
-
output.print('# Set these environment variables on your deployment platform:');
|
|
105
|
-
output.print(`ACTP_KEYSTORE_BASE64=${base64}`);
|
|
106
|
-
output.print('ACTP_KEY_PASSWORD=<your keystore password>');
|
|
107
|
-
output.print('');
|
|
108
|
-
output.print('# SECURITY BEST PRACTICE:');
|
|
109
|
-
output.print('# Store ACTP_KEYSTORE_BASE64 and ACTP_KEY_PASSWORD in SEPARATE secret scopes');
|
|
110
|
-
output.print('# where your platform supports it (e.g., different secret groups, vaults, or teams).');
|
|
111
|
-
output.print('# This preserves the two-factor security model.');
|
|
112
|
-
output.print('#');
|
|
113
|
-
output.print('# WARNING: Never echo these values in CI/CD logs or commit them to git.');
|
|
114
|
-
output.print('');
|
|
115
|
-
output.print('# Platform-specific examples:');
|
|
116
|
-
output.print(`# Railway: railway variables set ACTP_KEYSTORE_BASE64="${base64}"`);
|
|
117
|
-
output.print('# Vercel: vercel env add ACTP_KEYSTORE_BASE64');
|
|
118
|
-
output.print(`# Fly.io: fly secrets set ACTP_KEYSTORE_BASE64="${base64}"`);
|
|
119
|
-
output.print('# Hetzner: Add to your .env on the server (ensure .env is in .gitignore)');
|
|
120
|
-
}
|
package/src/cli/commands/diff.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Diff Command - Compare local AGIRAILS.md with on-chain config
|
|
3
|
-
*
|
|
4
|
-
* Shows sync status between local file and AgentRegistry state.
|
|
5
|
-
* Terraform-style: never auto-overwrites, just shows differences.
|
|
6
|
-
*
|
|
7
|
-
* @module cli/commands/diff
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { Command } from 'commander';
|
|
11
|
-
import { Output, ExitCode } from '../utils/output';
|
|
12
|
-
import { mapError } from '../utils/client';
|
|
13
|
-
import { resolve } from 'path';
|
|
14
|
-
import { ethers } from 'ethers';
|
|
15
|
-
import { diff } from '../../config/syncOperations';
|
|
16
|
-
import { getNetwork } from '../../config/networks';
|
|
17
|
-
|
|
18
|
-
// ============================================================================
|
|
19
|
-
// Command Definition
|
|
20
|
-
// ============================================================================
|
|
21
|
-
|
|
22
|
-
export function createDiffCommand(): Command {
|
|
23
|
-
const cmd = new Command('diff')
|
|
24
|
-
.description('Compare local AGIRAILS.md with on-chain config')
|
|
25
|
-
.argument('[path]', 'Path to AGIRAILS.md', './AGIRAILS.md')
|
|
26
|
-
.option('-n, --network <network>', 'Network (base-sepolia | base-mainnet)', 'base-sepolia')
|
|
27
|
-
.option('-a, --address <address>', 'Agent address to compare with')
|
|
28
|
-
.option('--json', 'Output as JSON')
|
|
29
|
-
.option('-q, --quiet', 'Output only sync status')
|
|
30
|
-
.action(async (path, options) => {
|
|
31
|
-
const output = new Output(
|
|
32
|
-
options.json ? 'json' : options.quiet ? 'quiet' : 'human'
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
await runDiff(path, options, output);
|
|
37
|
-
} catch (error) {
|
|
38
|
-
const structuredError = mapError(error);
|
|
39
|
-
output.errorResult({
|
|
40
|
-
code: structuredError.code,
|
|
41
|
-
message: structuredError.message,
|
|
42
|
-
details: structuredError.details,
|
|
43
|
-
});
|
|
44
|
-
process.exit(ExitCode.ERROR);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return cmd;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// ============================================================================
|
|
52
|
-
// Implementation
|
|
53
|
-
// ============================================================================
|
|
54
|
-
|
|
55
|
-
interface DiffCommandOptions {
|
|
56
|
-
network: string;
|
|
57
|
-
address?: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function runDiff(
|
|
61
|
-
filePath: string,
|
|
62
|
-
options: DiffCommandOptions,
|
|
63
|
-
output: Output
|
|
64
|
-
): Promise<void> {
|
|
65
|
-
const resolvedPath = resolve(filePath);
|
|
66
|
-
|
|
67
|
-
// Determine agent address
|
|
68
|
-
let agentAddress = options.address;
|
|
69
|
-
if (!agentAddress) {
|
|
70
|
-
const privateKey = process.env.ACTP_PRIVATE_KEY || process.env.PRIVATE_KEY;
|
|
71
|
-
if (!privateKey) {
|
|
72
|
-
output.error('Agent address required. Use --address or set ACTP_PRIVATE_KEY env var.');
|
|
73
|
-
process.exit(ExitCode.INVALID_INPUT);
|
|
74
|
-
}
|
|
75
|
-
agentAddress = new ethers.Wallet(privateKey).address;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const networkConfig = getNetwork(options.network);
|
|
79
|
-
if (!networkConfig.contracts.agentRegistry) {
|
|
80
|
-
output.error(`AgentRegistry not deployed on ${options.network}`);
|
|
81
|
-
process.exit(ExitCode.ERROR);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const spinner = output.spinner('Comparing local and on-chain config...');
|
|
85
|
-
|
|
86
|
-
try {
|
|
87
|
-
const provider = new ethers.JsonRpcProvider(networkConfig.rpcUrl);
|
|
88
|
-
|
|
89
|
-
const result = await diff({
|
|
90
|
-
path: resolvedPath,
|
|
91
|
-
agentAddress,
|
|
92
|
-
registryAddress: networkConfig.contracts.agentRegistry,
|
|
93
|
-
provider,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
spinner.stop(true);
|
|
97
|
-
|
|
98
|
-
output.result(
|
|
99
|
-
{
|
|
100
|
-
status: result.status,
|
|
101
|
-
inSync: result.inSync,
|
|
102
|
-
localHash: result.localHash,
|
|
103
|
-
onChainHash: result.onChainHash,
|
|
104
|
-
onChainCID: result.onChainCID || null,
|
|
105
|
-
hasLocalFile: result.hasLocalFile,
|
|
106
|
-
hasOnChainConfig: result.hasOnChainConfig,
|
|
107
|
-
network: options.network,
|
|
108
|
-
agent: agentAddress,
|
|
109
|
-
},
|
|
110
|
-
{ quietKey: 'status' }
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
output.blank();
|
|
114
|
-
|
|
115
|
-
// Human-friendly status messages
|
|
116
|
-
switch (result.status) {
|
|
117
|
-
case 'in-sync':
|
|
118
|
-
output.success('Local and on-chain configs are in sync.');
|
|
119
|
-
break;
|
|
120
|
-
case 'local-ahead':
|
|
121
|
-
output.warning('Local changes not yet published. Run: actp publish');
|
|
122
|
-
break;
|
|
123
|
-
case 'remote-ahead':
|
|
124
|
-
output.warning('On-chain config is newer. Run: actp pull');
|
|
125
|
-
break;
|
|
126
|
-
case 'diverged':
|
|
127
|
-
output.warning('Local and on-chain configs have diverged.');
|
|
128
|
-
output.print(' Resolve by running: actp publish (to push local) or actp pull --force (to accept remote)');
|
|
129
|
-
break;
|
|
130
|
-
case 'no-local':
|
|
131
|
-
output.info('No local AGIRAILS.md found. Run: actp pull');
|
|
132
|
-
break;
|
|
133
|
-
case 'no-remote':
|
|
134
|
-
output.info('No config published on-chain. Run: actp publish');
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
} catch (error) {
|
|
138
|
-
spinner.stop(false);
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
}
|