@agentrade/cli 0.1.2 → 0.1.3

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.
Files changed (3) hide show
  1. package/dist/index.js +475 -189
  2. package/package.json +16 -15
  3. package/LICENSE +0 -22
package/dist/index.js CHANGED
@@ -3,91 +3,6 @@
3
3
  // src/program.ts
4
4
  import { Command } from "commander";
5
5
 
6
- // src/operation-bindings.ts
7
- var cliOperationBindings = {
8
- "activities list": "activitiesListV2",
9
- "admin bridge export": "adminBridgeExportV2",
10
- "admin cycles close": "adminCloseCycleV2",
11
- "admin disputes override": "adminOverrideDisputeV2",
12
- "agents list": "agentsListV2",
13
- "agents profile get": "agentsGetProfileV2",
14
- "agents profile update": "agentsUpdateProfileV2",
15
- "agents stats": "agentsGetStatsV2",
16
- "auth challenge": "authChallengeV2",
17
- "auth verify": "authVerifyV2",
18
- "cycles active": "cyclesGetActiveV2",
19
- "cycles get": "cyclesGetV2",
20
- "cycles list": "cyclesListV2",
21
- "cycles rewards": "cyclesGetRewardsV2",
22
- "dashboard summary": "dashboardSummaryV2",
23
- "dashboard trends": "dashboardTrendsV2",
24
- "disputes get": "disputesGetV2",
25
- "disputes list": "disputesListV2",
26
- "disputes open": "disputesOpenV2",
27
- "disputes vote": "disputesVoteV2",
28
- "economy params": "economyGetParamsV2",
29
- "ledger get": "ledgerGetV2",
30
- "submissions get": "submissionsGetV2",
31
- "submissions list": "submissionsListV2",
32
- "submissions confirm": "submissionsConfirmV2",
33
- "submissions reject": "submissionsRejectV2",
34
- "system health": "systemHealthV2",
35
- "tasks create": "tasksCreateV2",
36
- "tasks get": "tasksGetV2",
37
- "tasks intend": "tasksAddIntentionV2",
38
- "tasks intentions": "tasksListIntentionsV2",
39
- "tasks list": "tasksListV2",
40
- "tasks submit": "tasksSubmitV2",
41
- "tasks terminate": "tasksTerminateV2"
42
- };
43
-
44
- // src/text-input.ts
45
- import { readFileSync } from "fs";
46
-
47
- // src/errors.ts
48
- var CliValidationError = class extends Error {
49
- constructor(message) {
50
- super(message);
51
- this.name = "CliValidationError";
52
- }
53
- };
54
- var CliConfigError = class extends Error {
55
- constructor(message) {
56
- super(message);
57
- this.name = "CliConfigError";
58
- }
59
- };
60
-
61
- // src/text-input.ts
62
- var resolveTextInput = (options) => {
63
- const { inlineValue, filePath, fieldName, required = true, allowEmpty = false } = options;
64
- if (inlineValue !== void 0 && filePath !== void 0) {
65
- throw new CliValidationError(`--${fieldName} and --${fieldName}-file are mutually exclusive`);
66
- }
67
- let value;
68
- if (filePath !== void 0) {
69
- try {
70
- value = readFileSync(filePath, "utf8");
71
- } catch (error) {
72
- throw new CliValidationError(
73
- `failed to read --${fieldName}-file: ${error instanceof Error ? error.message : String(error)}`
74
- );
75
- }
76
- } else {
77
- value = inlineValue;
78
- }
79
- if (value === void 0) {
80
- if (required) {
81
- throw new CliValidationError(`--${fieldName} or --${fieldName}-file is required`);
82
- }
83
- return void 0;
84
- }
85
- if (!allowEmpty && value.trim().length === 0) {
86
- throw new CliValidationError(`--${fieldName} must be non-empty`);
87
- }
88
- return value;
89
- };
90
-
91
6
  // ../../packages/types/src/index.ts
92
7
  var TaskStatus = /* @__PURE__ */ ((TaskStatus2) => {
93
8
  TaskStatus2["OPEN"] = "OPEN";
@@ -125,12 +40,85 @@ var ActivityEventType = /* @__PURE__ */ ((ActivityEventType2) => {
125
40
  ActivityEventType2["TASK_COMPLETED"] = "TASK_COMPLETED";
126
41
  ActivityEventType2["DISPUTE_OPENED"] = "DISPUTE_OPENED";
127
42
  ActivityEventType2["TASK_TERMINATED"] = "TASK_TERMINATED";
43
+ ActivityEventType2["ADMIN_AUDIT"] = "ADMIN_AUDIT";
128
44
  return ActivityEventType2;
129
45
  })(ActivityEventType || {});
130
46
 
47
+ // src/errors.ts
48
+ var CliValidationError = class extends Error {
49
+ constructor(message) {
50
+ super(message);
51
+ this.name = "CliValidationError";
52
+ }
53
+ };
54
+ var CliConfigError = class extends Error {
55
+ constructor(message) {
56
+ super(message);
57
+ this.name = "CliConfigError";
58
+ }
59
+ };
60
+
61
+ // src/operation-bindings.ts
62
+ var cliOperationBindings = {
63
+ "activities list": "activitiesListV2",
64
+ "agents list": "agentsListV2",
65
+ "agents profile get": "agentsGetProfileV2",
66
+ "agents profile update": "agentsUpdateProfileV2",
67
+ "agents stats": "agentsGetStatsV2",
68
+ "auth challenge": "authChallengeV2",
69
+ "auth verify": "authVerifyV2",
70
+ "cycles active": "cyclesGetActiveV2",
71
+ "cycles get": "cyclesGetV2",
72
+ "cycles list": "cyclesListV2",
73
+ "cycles rewards": "cyclesGetRewardsV2",
74
+ "dashboard summary": "dashboardSummaryV2",
75
+ "dashboard trends": "dashboardTrendsV2",
76
+ "disputes get": "disputesGetV2",
77
+ "disputes list": "disputesListV2",
78
+ "disputes open": "disputesOpenV2",
79
+ "disputes vote": "disputesVoteV2",
80
+ "economy params": "economyGetParamsV2",
81
+ "ledger get": "ledgerGetV2",
82
+ "submissions get": "submissionsGetV2",
83
+ "submissions list": "submissionsListV2",
84
+ "submissions confirm": "submissionsConfirmV2",
85
+ "submissions reject": "submissionsRejectV2",
86
+ "system health": "systemHealthV2",
87
+ "system metrics": "systemMetricsV2",
88
+ "system settings get": "systemSettingsGetV2",
89
+ "system settings history": "systemSettingsHistoryV2",
90
+ "system settings reset": "systemSettingsResetV2",
91
+ "system settings update": "systemSettingsUpdateV2",
92
+ "tasks create": "tasksCreateV2",
93
+ "tasks get": "tasksGetV2",
94
+ "tasks intend": "tasksAddIntentionV2",
95
+ "tasks intentions": "tasksListIntentionsV2",
96
+ "tasks list": "tasksListV2",
97
+ "tasks submit": "tasksSubmitV2",
98
+ "tasks terminate": "tasksTerminateV2"
99
+ };
100
+
131
101
  // src/validators.ts
132
102
  var ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/;
133
103
  var ISO_DATETIME_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/;
104
+ var RUNTIME_EDITABLE_KEYS = /* @__PURE__ */ new Set([
105
+ "cycleDurationHours",
106
+ "mintPerCycle",
107
+ "taxRateBps",
108
+ "taskCompletionPublisherWorkload",
109
+ "taskCompletionWorkerWorkload",
110
+ "disputeQuorum",
111
+ "disputeApprovalBps",
112
+ "terminationPenaltyBps",
113
+ "submissionTimeoutHours",
114
+ "resubmitCooldownMinutes",
115
+ "reputationWeightPublisherBps",
116
+ "reputationWeightWorkerBps",
117
+ "reputationWeightSupervisorBps",
118
+ "scoreWeightReputationBps",
119
+ "scoreWeightCompletionBps",
120
+ "scoreWeightQualityBps"
121
+ ]);
134
122
  var parseInteger = (raw, flag) => {
135
123
  if (!/^[-]?\d+$/.test(raw.trim())) {
136
124
  throw new CliValidationError(`${flag} must be an integer`);
@@ -213,23 +201,37 @@ var ensureVoteChoice = (raw) => {
213
201
  }
214
202
  return normalized;
215
203
  };
216
- var ensureOverrideResult = (raw) => {
217
- const normalized = raw.trim().toUpperCase();
218
- if (normalized !== "COMPLETED" && normalized !== "NOT_COMPLETED") {
219
- throw new CliValidationError("--result must be COMPLETED or NOT_COMPLETED");
204
+ var ensureRuntimeSettingsApplyTo = (raw, flag = "--apply-to") => {
205
+ const normalized = raw.trim().toLowerCase();
206
+ if (normalized !== "current" && normalized !== "next") {
207
+ throw new CliValidationError(`${flag} must be current or next`);
220
208
  }
221
209
  return normalized;
222
210
  };
223
- var parseOptionalAddressList = (raw, flag) => {
224
- if (!raw || raw.trim().length === 0) {
225
- return void 0;
211
+ var ensureRuntimeSettingsPatchJson = (raw, flag = "--patch-json") => {
212
+ let parsed;
213
+ try {
214
+ parsed = JSON.parse(raw);
215
+ } catch {
216
+ throw new CliValidationError(`${flag} must be a valid JSON object`);
226
217
  }
227
- const values = raw.split(/[\s,]+/).map((item) => item.trim()).filter((item) => item.length > 0);
228
- if (values.length === 0) {
229
- return void 0;
218
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
219
+ throw new CliValidationError(`${flag} must be a JSON object`);
220
+ }
221
+ const patch = {};
222
+ for (const [key, value] of Object.entries(parsed)) {
223
+ if (!RUNTIME_EDITABLE_KEYS.has(key)) {
224
+ throw new CliValidationError(`${flag} contains unsupported key: ${key}`);
225
+ }
226
+ if (typeof value !== "number" || !Number.isFinite(value)) {
227
+ throw new CliValidationError(`${flag}.${key} must be a finite number`);
228
+ }
229
+ patch[key] = value;
230
+ }
231
+ if (Object.keys(patch).length === 0) {
232
+ throw new CliValidationError(`${flag} must include at least one editable rule`);
230
233
  }
231
- const unique = [...new Set(values)];
232
- return unique.map((value) => ensureAddress(value, flag));
234
+ return patch;
233
235
  };
234
236
 
235
237
  // ../../packages/contracts/src/schemas.ts
@@ -1202,6 +1204,7 @@ var publicEconomyParamsSchema = defineSchema(
1202
1204
  rewardMin: z.number().int(),
1203
1205
  initialAgentBalance: z.number().int(),
1204
1206
  mintPerCycle: z.number().int(),
1207
+ cycleDurationHours: z.number().int(),
1205
1208
  terminationPenaltyBps: z.number().int(),
1206
1209
  submissionTimeoutHours: z.number().int(),
1207
1210
  resubmitCooldownMinutes: z.number().int(),
@@ -1243,6 +1246,7 @@ var publicEconomyParamsSchema = defineSchema(
1243
1246
  "rewardMin",
1244
1247
  "initialAgentBalance",
1245
1248
  "mintPerCycle",
1249
+ "cycleDurationHours",
1246
1250
  "terminationPenaltyBps",
1247
1251
  "submissionTimeoutHours",
1248
1252
  "resubmitCooldownMinutes",
@@ -1281,6 +1285,7 @@ var publicEconomyParamsSchema = defineSchema(
1281
1285
  rewardMin: { ...integerField },
1282
1286
  initialAgentBalance: { ...integerField },
1283
1287
  mintPerCycle: { ...integerField },
1288
+ cycleDurationHours: { ...integerField },
1284
1289
  terminationPenaltyBps: { ...integerField },
1285
1290
  submissionTimeoutHours: { ...integerField },
1286
1291
  resubmitCooldownMinutes: { ...integerField },
@@ -1300,6 +1305,212 @@ var publicEconomyParamsSchema = defineSchema(
1300
1305
  }
1301
1306
  }
1302
1307
  );
1308
+ var runtimeEditableRulesSchema = defineSchema(
1309
+ "RuntimeEditableRules",
1310
+ z.object({
1311
+ cycleDurationHours: z.number().int(),
1312
+ mintPerCycle: z.number().int(),
1313
+ taxRateBps: z.number().int(),
1314
+ taskCompletionPublisherWorkload: z.number(),
1315
+ taskCompletionWorkerWorkload: z.number(),
1316
+ disputeQuorum: z.number().int(),
1317
+ disputeApprovalBps: z.number().int(),
1318
+ terminationPenaltyBps: z.number().int(),
1319
+ submissionTimeoutHours: z.number().int(),
1320
+ resubmitCooldownMinutes: z.number().int(),
1321
+ reputationWeightPublisherBps: z.number().int(),
1322
+ reputationWeightWorkerBps: z.number().int(),
1323
+ reputationWeightSupervisorBps: z.number().int(),
1324
+ scoreWeightReputationBps: z.number().int(),
1325
+ scoreWeightCompletionBps: z.number().int(),
1326
+ scoreWeightQualityBps: z.number().int()
1327
+ }),
1328
+ {
1329
+ type: "object",
1330
+ additionalProperties: false,
1331
+ required: [
1332
+ "cycleDurationHours",
1333
+ "mintPerCycle",
1334
+ "taxRateBps",
1335
+ "taskCompletionPublisherWorkload",
1336
+ "taskCompletionWorkerWorkload",
1337
+ "disputeQuorum",
1338
+ "disputeApprovalBps",
1339
+ "terminationPenaltyBps",
1340
+ "submissionTimeoutHours",
1341
+ "resubmitCooldownMinutes",
1342
+ "reputationWeightPublisherBps",
1343
+ "reputationWeightWorkerBps",
1344
+ "reputationWeightSupervisorBps",
1345
+ "scoreWeightReputationBps",
1346
+ "scoreWeightCompletionBps",
1347
+ "scoreWeightQualityBps"
1348
+ ],
1349
+ properties: {
1350
+ cycleDurationHours: { ...integerField },
1351
+ mintPerCycle: { ...integerField },
1352
+ taxRateBps: { ...integerField },
1353
+ taskCompletionPublisherWorkload: { ...numberField },
1354
+ taskCompletionWorkerWorkload: { ...numberField },
1355
+ disputeQuorum: { ...integerField },
1356
+ disputeApprovalBps: { ...integerField },
1357
+ terminationPenaltyBps: { ...integerField },
1358
+ submissionTimeoutHours: { ...integerField },
1359
+ resubmitCooldownMinutes: { ...integerField },
1360
+ reputationWeightPublisherBps: { ...integerField },
1361
+ reputationWeightWorkerBps: { ...integerField },
1362
+ reputationWeightSupervisorBps: { ...integerField },
1363
+ scoreWeightReputationBps: { ...integerField },
1364
+ scoreWeightCompletionBps: { ...integerField },
1365
+ scoreWeightQualityBps: { ...integerField }
1366
+ }
1367
+ }
1368
+ );
1369
+ var runtimeEditableRulesPatchSchema = defineSchema(
1370
+ "RuntimeEditableRulesPatch",
1371
+ runtimeEditableRulesSchema.schema.partial(),
1372
+ {
1373
+ type: "object",
1374
+ additionalProperties: false,
1375
+ properties: {
1376
+ cycleDurationHours: { ...integerField },
1377
+ mintPerCycle: { ...integerField },
1378
+ taxRateBps: { ...integerField },
1379
+ taskCompletionPublisherWorkload: { ...numberField },
1380
+ taskCompletionWorkerWorkload: { ...numberField },
1381
+ disputeQuorum: { ...integerField },
1382
+ disputeApprovalBps: { ...integerField },
1383
+ terminationPenaltyBps: { ...integerField },
1384
+ submissionTimeoutHours: { ...integerField },
1385
+ resubmitCooldownMinutes: { ...integerField },
1386
+ reputationWeightPublisherBps: { ...integerField },
1387
+ reputationWeightWorkerBps: { ...integerField },
1388
+ reputationWeightSupervisorBps: { ...integerField },
1389
+ scoreWeightReputationBps: { ...integerField },
1390
+ scoreWeightCompletionBps: { ...integerField },
1391
+ scoreWeightQualityBps: { ...integerField }
1392
+ }
1393
+ }
1394
+ );
1395
+ var runtimeSettingsStateSchema = defineSchema(
1396
+ "RuntimeSettingsState",
1397
+ z.object({
1398
+ currentRules: runtimeEditableRulesSchema.schema,
1399
+ pendingNextPatch: runtimeEditableRulesPatchSchema.schema.nullable(),
1400
+ nextRules: runtimeEditableRulesSchema.schema,
1401
+ updatedAt: isoDateSchema
1402
+ }),
1403
+ {
1404
+ type: "object",
1405
+ additionalProperties: false,
1406
+ required: ["currentRules", "pendingNextPatch", "nextRules", "updatedAt"],
1407
+ properties: {
1408
+ currentRules: schemaRef(runtimeEditableRulesSchema),
1409
+ pendingNextPatch: { ...schemaRef(runtimeEditableRulesPatchSchema), nullable: true },
1410
+ nextRules: schemaRef(runtimeEditableRulesSchema),
1411
+ updatedAt: { ...isoDateField }
1412
+ }
1413
+ }
1414
+ );
1415
+ var runtimeSettingsUpdateRequestSchema = defineSchema(
1416
+ "RuntimeSettingsUpdateRequest",
1417
+ z.object({
1418
+ applyTo: z.enum(["current", "next"]),
1419
+ patch: runtimeEditableRulesPatchSchema.schema.refine(
1420
+ (value) => Object.keys(value).length > 0,
1421
+ "patch must contain at least one editable rule"
1422
+ ),
1423
+ reason: z.string().trim().min(1).max(1e3).optional()
1424
+ }),
1425
+ {
1426
+ type: "object",
1427
+ additionalProperties: false,
1428
+ required: ["applyTo", "patch"],
1429
+ properties: {
1430
+ applyTo: { type: "string", enum: ["current", "next"] },
1431
+ patch: schemaRef(runtimeEditableRulesPatchSchema),
1432
+ reason: { ...stringField, minLength: 1, maxLength: 1e3 }
1433
+ }
1434
+ }
1435
+ );
1436
+ var runtimeSettingsResetRequestSchema = defineSchema(
1437
+ "RuntimeSettingsResetRequest",
1438
+ z.object({
1439
+ applyTo: z.enum(["current", "next"]),
1440
+ reason: z.string().trim().min(1).max(1e3).optional()
1441
+ }),
1442
+ {
1443
+ type: "object",
1444
+ additionalProperties: false,
1445
+ required: ["applyTo"],
1446
+ properties: {
1447
+ applyTo: { type: "string", enum: ["current", "next"] },
1448
+ reason: { ...stringField, minLength: 1, maxLength: 1e3 }
1449
+ }
1450
+ }
1451
+ );
1452
+ var runtimeRuleAuditRecordSchema = defineSchema(
1453
+ "RuntimeRuleAuditRecord",
1454
+ z.object({
1455
+ id: z.string(),
1456
+ eventType: z.enum(["UPDATE", "RESET", "AUTO_APPLY_NEXT"]),
1457
+ applyTo: z.enum(["current", "next"]).nullable(),
1458
+ reason: z.string().nullable(),
1459
+ actor: z.string().nullable(),
1460
+ cycleId: z.string().nullable(),
1461
+ beforeRules: runtimeEditableRulesSchema.schema.nullable(),
1462
+ afterRules: runtimeEditableRulesSchema.schema.nullable(),
1463
+ patch: runtimeEditableRulesPatchSchema.schema.nullable(),
1464
+ pendingNextPatch: runtimeEditableRulesPatchSchema.schema.nullable(),
1465
+ createdAt: isoDateSchema
1466
+ }),
1467
+ {
1468
+ type: "object",
1469
+ additionalProperties: false,
1470
+ required: [
1471
+ "id",
1472
+ "eventType",
1473
+ "applyTo",
1474
+ "reason",
1475
+ "actor",
1476
+ "cycleId",
1477
+ "beforeRules",
1478
+ "afterRules",
1479
+ "patch",
1480
+ "pendingNextPatch",
1481
+ "createdAt"
1482
+ ],
1483
+ properties: {
1484
+ id: { ...stringField },
1485
+ eventType: { type: "string", enum: ["UPDATE", "RESET", "AUTO_APPLY_NEXT"] },
1486
+ applyTo: { type: "string", enum: ["current", "next"], nullable: true },
1487
+ reason: { ...stringField, nullable: true },
1488
+ actor: { ...stringField, nullable: true },
1489
+ cycleId: { ...stringField, nullable: true },
1490
+ beforeRules: { ...schemaRef(runtimeEditableRulesSchema), nullable: true },
1491
+ afterRules: { ...schemaRef(runtimeEditableRulesSchema), nullable: true },
1492
+ patch: { ...schemaRef(runtimeEditableRulesPatchSchema), nullable: true },
1493
+ pendingNextPatch: { ...schemaRef(runtimeEditableRulesPatchSchema), nullable: true },
1494
+ createdAt: { ...isoDateField }
1495
+ }
1496
+ }
1497
+ );
1498
+ var paginatedRuntimeRuleAuditResponseSchema = defineSchema(
1499
+ "PaginatedRuntimeRuleAuditResponse",
1500
+ z.object({
1501
+ items: z.array(runtimeRuleAuditRecordSchema.schema),
1502
+ nextCursor: z.string().nullable()
1503
+ }),
1504
+ {
1505
+ type: "object",
1506
+ additionalProperties: false,
1507
+ required: ["items", "nextCursor"],
1508
+ properties: {
1509
+ items: { type: "array", items: schemaRef(runtimeRuleAuditRecordSchema) },
1510
+ nextCursor: { type: "string", nullable: true }
1511
+ }
1512
+ }
1513
+ );
1303
1514
  var createTaskRequestSchema = defineSchema(
1304
1515
  "CreateTaskRequest",
1305
1516
  z.object({
@@ -1529,6 +1740,10 @@ var cycleListQuerySchemaV2 = z.object({
1529
1740
  cursor: z.string().optional(),
1530
1741
  limit: z.coerce.number().int().min(1).max(100).default(20)
1531
1742
  });
1743
+ var runtimeRuleAuditHistoryQuerySchemaV2 = z.object({
1744
+ cursor: z.string().optional(),
1745
+ limit: z.coerce.number().int().min(1).max(100).default(20)
1746
+ });
1532
1747
  var idPathSchema = z.object({
1533
1748
  id: nonEmptyStringSchema
1534
1749
  });
@@ -1576,6 +1791,13 @@ var namedSchemas = [
1576
1791
  bridgeExportItemSchema,
1577
1792
  bridgeExportResponseSchema,
1578
1793
  publicEconomyParamsSchema,
1794
+ runtimeEditableRulesSchema,
1795
+ runtimeEditableRulesPatchSchema,
1796
+ runtimeSettingsStateSchema,
1797
+ runtimeSettingsUpdateRequestSchema,
1798
+ runtimeSettingsResetRequestSchema,
1799
+ runtimeRuleAuditRecordSchema,
1800
+ paginatedRuntimeRuleAuditResponseSchema,
1579
1801
  createTaskRequestSchema,
1580
1802
  submitTaskRequestSchema,
1581
1803
  openDisputeRequestSchema,
@@ -1744,6 +1966,7 @@ var dashboardTrendParameters = [
1744
1966
  queryStringParam("window", { type: "string", enum: ["7d", "30d"], default: "7d" }, { en: "Trend window", zh: "\u8D8B\u52BF\u7A97\u53E3" })
1745
1967
  ];
1746
1968
  var cycleListParametersV2 = [queryCursorParam, queryLimitParam];
1969
+ var runtimeRuleHistoryParametersV2 = [queryCursorParam, queryLimitParam];
1747
1970
  var apiOperations = [
1748
1971
  defineOperationSpec({
1749
1972
  baseOperationId: "systemHealth",
@@ -1760,13 +1983,63 @@ var apiOperations = [
1760
1983
  baseOperationId: "systemMetrics",
1761
1984
  method: "GET",
1762
1985
  tag: "System",
1763
- auth: "admin",
1986
+ auth: "bearer",
1764
1987
  summary: { en: "Get service metrics", zh: "\u8BFB\u53D6\u670D\u52A1\u6307\u6807" },
1765
1988
  pathTemplate: "/v2/system/metrics",
1766
1989
  responseSchema: serviceMetricsResponseSchema.schema,
1767
1990
  responseComponent: serviceMetricsResponseSchema,
1768
1991
  errorStatuses: [401, 500]
1769
1992
  }),
1993
+ defineOperationSpec({
1994
+ baseOperationId: "systemSettingsGet",
1995
+ method: "GET",
1996
+ tag: "System",
1997
+ auth: "bearer",
1998
+ summary: { en: "Get runtime settings", zh: "\u8BFB\u53D6\u8FD0\u884C\u89C4\u5219\u8BBE\u7F6E" },
1999
+ pathTemplate: "/v2/system/settings",
2000
+ responseSchema: runtimeSettingsStateSchema.schema,
2001
+ responseComponent: runtimeSettingsStateSchema,
2002
+ errorStatuses: [401, 500]
2003
+ }),
2004
+ defineOperationSpec({
2005
+ baseOperationId: "systemSettingsUpdate",
2006
+ method: "PATCH",
2007
+ tag: "System",
2008
+ auth: "bearer_admin",
2009
+ summary: { en: "Update runtime settings", zh: "\u66F4\u65B0\u8FD0\u884C\u89C4\u5219\u8BBE\u7F6E" },
2010
+ pathTemplate: "/v2/system/settings",
2011
+ bodySchema: runtimeSettingsUpdateRequestSchema.schema,
2012
+ requestBodyComponent: runtimeSettingsUpdateRequestSchema,
2013
+ responseSchema: runtimeSettingsStateSchema.schema,
2014
+ responseComponent: runtimeSettingsStateSchema,
2015
+ errorStatuses: [400, 401, 500]
2016
+ }),
2017
+ defineOperationSpec({
2018
+ baseOperationId: "systemSettingsReset",
2019
+ method: "POST",
2020
+ tag: "System",
2021
+ auth: "bearer_admin",
2022
+ summary: { en: "Reset runtime settings", zh: "\u91CD\u7F6E\u8FD0\u884C\u89C4\u5219\u8BBE\u7F6E" },
2023
+ pathTemplate: "/v2/system/settings/reset",
2024
+ bodySchema: runtimeSettingsResetRequestSchema.schema,
2025
+ requestBodyComponent: runtimeSettingsResetRequestSchema,
2026
+ responseSchema: runtimeSettingsStateSchema.schema,
2027
+ responseComponent: runtimeSettingsStateSchema,
2028
+ errorStatuses: [400, 401, 500]
2029
+ }),
2030
+ defineOperationSpec({
2031
+ baseOperationId: "systemSettingsHistory",
2032
+ method: "GET",
2033
+ tag: "System",
2034
+ auth: "bearer",
2035
+ summary: { en: "List runtime settings history", zh: "\u8BFB\u53D6\u8FD0\u884C\u89C4\u5219\u53D8\u66F4\u5386\u53F2" },
2036
+ pathTemplate: "/v2/system/settings/history",
2037
+ querySchema: runtimeRuleAuditHistoryQuerySchemaV2,
2038
+ responseSchema: paginatedRuntimeRuleAuditResponseSchema.schema,
2039
+ responseComponent: paginatedRuntimeRuleAuditResponseSchema,
2040
+ parameters: runtimeRuleHistoryParametersV2,
2041
+ errorStatuses: [401, 500]
2042
+ }),
1770
2043
  defineOperationSpec({
1771
2044
  baseOperationId: "authChallenge",
1772
2045
  method: "POST",
@@ -2159,49 +2432,6 @@ var apiOperations = [
2159
2432
  responseSchema: publicEconomyParamsSchema.schema,
2160
2433
  responseComponent: publicEconomyParamsSchema,
2161
2434
  errorStatuses: [500]
2162
- }),
2163
- defineOperationSpec({
2164
- baseOperationId: "adminCloseCycle",
2165
- method: "POST",
2166
- tag: "Admin",
2167
- auth: "admin",
2168
- summary: { en: "Close current cycle", zh: "\u5173\u95ED\u5F53\u524D\u5468\u671F" },
2169
- pathTemplate: "/v2/admin/cycles/close",
2170
- responseSchema: closeCycleResultSchema.schema,
2171
- responseComponent: closeCycleResultSchema,
2172
- errorStatuses: [401, 409, 500]
2173
- }),
2174
- defineOperationSpec({
2175
- baseOperationId: "adminOverrideDispute",
2176
- method: "POST",
2177
- tag: "Admin",
2178
- auth: "admin",
2179
- summary: { en: "Override dispute", zh: "\u7BA1\u7406\u5458\u8986\u76D6\u4E89\u8BAE\u7ED3\u679C" },
2180
- description: {
2181
- en: "NOT_COMPLETED reopens dispute to OPEN. If another OPEN dispute already exists for the same submission, returns 409 OPEN_DISPUTE_ALREADY_EXISTS.",
2182
- zh: "NOT_COMPLETED \u4F1A\u5C06\u4E89\u8BAE\u91CD\u5F00\u4E3A OPEN\u3002\u82E5\u540C\u4E00 submission \u5DF2\u5B58\u5728\u5176\u4ED6 OPEN \u4E89\u8BAE\uFF0C\u5219\u8FD4\u56DE 409 OPEN_DISPUTE_ALREADY_EXISTS\u3002"
2183
- },
2184
- pathTemplate: "/v2/admin/disputes/{id}/override",
2185
- pathParamsSchema: idPathSchema,
2186
- bodySchema: overrideDisputeRequestSchema.schema,
2187
- requestBodyComponent: overrideDisputeRequestSchema,
2188
- responseSchema: disputeSchema.schema,
2189
- responseComponent: disputeSchema,
2190
- parameters: [pathStringParam("id", { en: "Dispute id", zh: "\u4E89\u8BAE id" })],
2191
- errorStatuses: [401, 404, 409, 500]
2192
- }),
2193
- defineOperationSpec({
2194
- baseOperationId: "adminBridgeExport",
2195
- method: "POST",
2196
- tag: "Admin",
2197
- auth: "admin",
2198
- summary: { en: "Export bridge batch", zh: "\u5BFC\u51FA\u6865\u63A5\u6279\u6B21" },
2199
- pathTemplate: "/v2/admin/bridge/export",
2200
- bodySchema: bridgeExportRequestSchema.schema,
2201
- requestBodyComponent: bridgeExportRequestSchema,
2202
- responseSchema: bridgeExportResponseSchema.schema,
2203
- responseComponent: bridgeExportResponseSchema,
2204
- errorStatuses: [400, 401, 500]
2205
2435
  })
2206
2436
  ];
2207
2437
  var supportedApiVersions = [...new Set(apiOperations.map((operation) => operation.version))];
@@ -2347,13 +2577,21 @@ var AgentradeApiClient = class {
2347
2577
  }
2348
2578
  return { authorization: `Bearer ${this.token}` };
2349
2579
  }
2350
- if (auth === "admin") {
2580
+ if (auth === "bearer_admin") {
2581
+ if (!this.token) {
2582
+ throw new ApiClientError("missing bearer token for authenticated request", {
2583
+ apiError: "MISSING_BEARER_TOKEN"
2584
+ });
2585
+ }
2351
2586
  if (!this.adminKey) {
2352
- throw new ApiClientError("missing admin service key for admin request", {
2587
+ throw new ApiClientError("missing admin service key for admin-authenticated request", {
2353
2588
  apiError: "MISSING_ADMIN_KEY"
2354
2589
  });
2355
2590
  }
2356
- return { "x-admin-service-key": this.adminKey };
2591
+ return {
2592
+ authorization: `Bearer ${this.token}`,
2593
+ "x-admin-service-key": this.adminKey
2594
+ };
2357
2595
  }
2358
2596
  return {};
2359
2597
  }
@@ -2597,24 +2835,31 @@ var AgentradeApiClient = class {
2597
2835
  getEconomyParams() {
2598
2836
  return this.requestOperation("economyGetParamsV2");
2599
2837
  }
2600
- closeCurrentCycleAdmin() {
2601
- return this.requestOperation("adminCloseCycleV2");
2838
+ getRuntimeSettings() {
2839
+ return this.requestOperation("systemSettingsGetV2");
2602
2840
  }
2603
- overrideDisputeAdmin(disputeId, payload) {
2604
- return this.requestOperation("adminOverrideDisputeV2", {
2605
- pathParams: { id: disputeId },
2841
+ updateRuntimeSettings(payload) {
2842
+ return this.requestOperation("systemSettingsUpdateV2", {
2606
2843
  body: payload
2607
2844
  });
2608
2845
  }
2609
- exportBridgeBatchAdmin(payload = {}) {
2610
- return this.requestOperation("adminBridgeExportV2", {
2846
+ resetRuntimeSettings(payload) {
2847
+ return this.requestOperation("systemSettingsResetV2", {
2611
2848
  body: payload
2612
2849
  });
2613
2850
  }
2851
+ getRuntimeSettingsHistory(params) {
2852
+ return this.requestOperation(
2853
+ "systemSettingsHistoryV2",
2854
+ {
2855
+ query: params
2856
+ }
2857
+ );
2858
+ }
2614
2859
  };
2615
2860
 
2616
2861
  // src/cli-config.ts
2617
- import { existsSync, mkdirSync, readFileSync as readFileSync2, unlinkSync, writeFileSync } from "fs";
2862
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
2618
2863
  import { homedir } from "os";
2619
2864
  import { dirname, isAbsolute, join, resolve } from "path";
2620
2865
  var CLI_DEFAULT_BASE_URL = "https://agentrade.info/api";
@@ -2774,7 +3019,7 @@ var loadCliPersistedConfig = () => {
2774
3019
  }
2775
3020
  let rawText;
2776
3021
  try {
2777
- rawText = readFileSync2(path, "utf8");
3022
+ rawText = readFileSync(path, "utf8");
2778
3023
  } catch (error) {
2779
3024
  throw new CliConfigError(
2780
3025
  `unable to read CLI config at ${path}: ${error instanceof Error ? error.message : String(error)}`
@@ -3066,46 +3311,13 @@ var executeBearerOperationCommand = async (command, operationId, buildInput) =>
3066
3311
  };
3067
3312
  var executeAdminOperationCommand = async (command, operationId, buildInput) => {
3068
3313
  await executeJsonCommand(command, async (ctx) => {
3314
+ ctx.requireToken();
3069
3315
  ctx.requireAdminKey();
3070
3316
  const input = buildInput ? await buildInput(ctx) : {};
3071
3317
  return ctx.client.requestOperation(operationId, input);
3072
3318
  });
3073
3319
  };
3074
3320
 
3075
- // src/commands/admin.ts
3076
- var registerAdminCommands = (program) => {
3077
- const admin = program.command("admin").description("Admin-only commands");
3078
- const adminCycles = admin.command("cycles").description("Cycle admin commands");
3079
- adminCycles.command("close").description("Close current cycle").action(async (_options, command) => {
3080
- await executeAdminOperationCommand(command, cliOperationBindings["admin cycles close"]);
3081
- });
3082
- const adminDisputes = admin.command("disputes").description("Dispute admin commands");
3083
- adminDisputes.command("override").description("Override dispute result").requiredOption("--dispute <id>", "dispute id").requiredOption("--result <result>", "COMPLETED or NOT_COMPLETED").action(async (options, command) => {
3084
- await executeAdminOperationCommand(command, cliOperationBindings["admin disputes override"], async () => ({
3085
- pathParams: { id: ensureNonEmpty(String(options.dispute), "--dispute") },
3086
- body: {
3087
- result: ensureOverrideResult(String(options.result))
3088
- }
3089
- }));
3090
- });
3091
- const adminBridge = admin.command("bridge").description("Bridge export commands");
3092
- adminBridge.command("export").description("Export bridge balances").option("--addresses <list>", "comma or whitespace separated addresses").option("--addresses-file <path>", "file containing comma or whitespace separated addresses").action(async (options, command) => {
3093
- await executeAdminOperationCommand(command, cliOperationBindings["admin bridge export"], async () => {
3094
- const rawAddresses = resolveTextInput({
3095
- inlineValue: options.addresses,
3096
- filePath: options.addressesFile,
3097
- fieldName: "addresses",
3098
- required: false,
3099
- allowEmpty: true
3100
- });
3101
- const addresses = parseOptionalAddressList(rawAddresses, "--addresses");
3102
- return {
3103
- body: addresses ? { addresses } : {}
3104
- };
3105
- });
3106
- });
3107
- };
3108
-
3109
3321
  // src/commands/activities.ts
3110
3322
  var ensureActivityType = (raw) => {
3111
3323
  const normalized = raw.trim().toUpperCase();
@@ -3139,6 +3351,37 @@ var registerActivityCommands = (program) => {
3139
3351
  });
3140
3352
  };
3141
3353
 
3354
+ // src/text-input.ts
3355
+ import { readFileSync as readFileSync2 } from "fs";
3356
+ var resolveTextInput = (options) => {
3357
+ const { inlineValue, filePath, fieldName, required = true, allowEmpty = false } = options;
3358
+ if (inlineValue !== void 0 && filePath !== void 0) {
3359
+ throw new CliValidationError(`--${fieldName} and --${fieldName}-file are mutually exclusive`);
3360
+ }
3361
+ let value;
3362
+ if (filePath !== void 0) {
3363
+ try {
3364
+ value = readFileSync2(filePath, "utf8");
3365
+ } catch (error) {
3366
+ throw new CliValidationError(
3367
+ `failed to read --${fieldName}-file: ${error instanceof Error ? error.message : String(error)}`
3368
+ );
3369
+ }
3370
+ } else {
3371
+ value = inlineValue;
3372
+ }
3373
+ if (value === void 0) {
3374
+ if (required) {
3375
+ throw new CliValidationError(`--${fieldName} or --${fieldName}-file is required`);
3376
+ }
3377
+ return void 0;
3378
+ }
3379
+ if (!allowEmpty && value.trim().length === 0) {
3380
+ throw new CliValidationError(`--${fieldName} must be non-empty`);
3381
+ }
3382
+ return value;
3383
+ };
3384
+
3142
3385
  // src/commands/agents.ts
3143
3386
  var registerAgentCommands = (program) => {
3144
3387
  const agents = program.command("agents").description("Agent profile and stats commands");
@@ -3578,6 +3821,50 @@ var registerSystemCommands = (program) => {
3578
3821
  system.command("health").description("Get API health status").action(async (_options, command) => {
3579
3822
  await executeOperationCommand(command, cliOperationBindings["system health"]);
3580
3823
  });
3824
+ system.command("metrics").description("Get API metrics (token required)").action(async (_options, command) => {
3825
+ await executeBearerOperationCommand(command, cliOperationBindings["system metrics"]);
3826
+ });
3827
+ const settings = system.command("settings").description("Runtime settings commands");
3828
+ settings.command("get").description("Get runtime settings").action(async (_options, command) => {
3829
+ await executeBearerOperationCommand(command, cliOperationBindings["system settings get"]);
3830
+ });
3831
+ settings.command("update").description("Update runtime settings patch").requiredOption("--apply-to <target>", "current or next").requiredOption("--patch-json <json>", "JSON patch object with editable runtime rule fields").option("--reason <reason>", "optional update reason").action(async (options, command) => {
3832
+ await executeAdminOperationCommand(
3833
+ command,
3834
+ cliOperationBindings["system settings update"],
3835
+ async () => ({
3836
+ body: {
3837
+ applyTo: ensureRuntimeSettingsApplyTo(String(options.applyTo), "--apply-to"),
3838
+ patch: ensureRuntimeSettingsPatchJson(String(options.patchJson), "--patch-json"),
3839
+ ...options.reason ? { reason: ensureNonEmpty(String(options.reason), "--reason") } : {}
3840
+ }
3841
+ })
3842
+ );
3843
+ });
3844
+ settings.command("reset").description("Reset runtime settings to environment defaults").requiredOption("--apply-to <target>", "current or next").option("--reason <reason>", "optional reset reason").action(async (options, command) => {
3845
+ await executeAdminOperationCommand(
3846
+ command,
3847
+ cliOperationBindings["system settings reset"],
3848
+ async () => ({
3849
+ body: {
3850
+ applyTo: ensureRuntimeSettingsApplyTo(String(options.applyTo), "--apply-to"),
3851
+ ...options.reason ? { reason: ensureNonEmpty(String(options.reason), "--reason") } : {}
3852
+ }
3853
+ })
3854
+ );
3855
+ });
3856
+ settings.command("history").description("List runtime settings audit history").option("--cursor <cursor>", "pagination cursor").option("--limit <n>", "page size (1-100)").action(async (options, command) => {
3857
+ await executeBearerOperationCommand(
3858
+ command,
3859
+ cliOperationBindings["system settings history"],
3860
+ async () => ({
3861
+ query: {
3862
+ ...options.cursor ? { cursor: ensureNonEmpty(String(options.cursor), "--cursor") } : {},
3863
+ ...options.limit ? { limit: ensurePositiveInteger(String(options.limit), "--limit") } : {}
3864
+ }
3865
+ })
3866
+ );
3867
+ });
3581
3868
  };
3582
3869
 
3583
3870
  // src/commands/tasks.ts
@@ -3726,7 +4013,7 @@ var detectCommandFromArgv = (argv) => {
3726
4013
  };
3727
4014
  var buildProgram = () => {
3728
4015
  const program = new Command();
3729
- program.name("agentrade").description("Agentrade CLI for complete agent/admin lifecycle operations").version("0.1.2").option("--base-url <url>", "API base URL").option("--token <token>", "bearer token for authenticated routes").option("--admin-key <key>", "admin service key for admin routes").option("--timeout-ms <ms>", "request timeout in milliseconds").option("--retries <count>", "retry count for network/429/5xx errors").option("--pretty", "pretty-print JSON output", false).showHelpAfterError(false).configureOutput({
4016
+ program.name("agentrade").description("Agentrade CLI for complete authenticated lifecycle operations").version("0.1.2").option("--base-url <url>", "API base URL").option("--token <token>", "bearer token for authenticated routes").option("--admin-key <key>", "admin service key for privileged routes").option("--timeout-ms <ms>", "request timeout in milliseconds").option("--retries <count>", "retry count for network/429/5xx errors").option("--pretty", "pretty-print JSON output", false).showHelpAfterError(false).configureOutput({
3730
4017
  writeErr: () => void 0
3731
4018
  }).addHelpText("after", HELP_APPENDIX).exitOverride();
3732
4019
  registerAuthCommands(program);
@@ -3741,7 +4028,6 @@ var buildProgram = () => {
3741
4028
  registerLedgerCommands(program);
3742
4029
  registerCycleCommands(program);
3743
4030
  registerEconomyCommands(program);
3744
- registerAdminCommands(program);
3745
4031
  return program;
3746
4032
  };
3747
4033
  var runCli = async (argv = process.argv) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentrade/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "agentrade": "dist/index.js"
@@ -11,27 +11,28 @@
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },
14
+ "scripts": {
15
+ "clean": "rm -rf dist",
16
+ "dev": "tsx src/index.ts",
17
+ "build": "tsup --config tsup.config.ts",
18
+ "prepublishOnly": "pnpm run build",
19
+ "test": "tsx --test test/**/*.test.ts",
20
+ "test:persistence": "tsx --test --test-concurrency=1 test/persistence.stress.test.ts",
21
+ "lint": "tsc -p tsconfig.json --noEmit"
22
+ },
14
23
  "dependencies": {
15
24
  "commander": "^13.1.0",
16
25
  "viem": "^2.23.5",
17
26
  "zod": "^3.24.2"
18
27
  },
19
28
  "devDependencies": {
29
+ "@agentrade/config": "workspace:*",
30
+ "@agentrade/contracts": "workspace:*",
31
+ "@agentrade/sdk": "workspace:*",
32
+ "@agentrade/types": "workspace:*",
20
33
  "@types/node": "^22.13.10",
21
34
  "tsup": "^8.2.4",
22
35
  "tsx": "^4.19.3",
23
- "typescript": "^5.7.3",
24
- "@agentrade/config": "0.1.0",
25
- "@agentrade/sdk": "0.1.0",
26
- "@agentrade/contracts": "0.1.0",
27
- "@agentrade/types": "0.1.0"
28
- },
29
- "scripts": {
30
- "clean": "rm -rf dist",
31
- "dev": "tsx src/index.ts",
32
- "build": "tsup --config tsup.config.ts",
33
- "test": "tsx --test test/**/*.test.ts",
34
- "test:persistence": "tsx --test --test-concurrency=1 test/persistence.stress.test.ts",
35
- "lint": "tsc -p tsconfig.json --noEmit"
36
+ "typescript": "^5.7.3"
36
37
  }
37
- }
38
+ }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Agentrade Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-