@agentis-hq/cli 0.4.0 → 0.4.1
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/index.js +85 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1730,6 +1730,83 @@ Recurring order cancelled for ${agent.name}`);
|
|
|
1730
1730
|
console.log("Usage: agentis <tokens|swap|portfolio|recurring> ...");
|
|
1731
1731
|
}
|
|
1732
1732
|
|
|
1733
|
+
// src/lib/command-validation.ts
|
|
1734
|
+
var commandTree = {
|
|
1735
|
+
login: null,
|
|
1736
|
+
logout: null,
|
|
1737
|
+
whoami: null,
|
|
1738
|
+
version: null,
|
|
1739
|
+
wallet: ["create", "list"],
|
|
1740
|
+
agent: ["create", "send", "balance"],
|
|
1741
|
+
fetch: null,
|
|
1742
|
+
earn: ["deposit", "withdraw", "positions", "sweep"],
|
|
1743
|
+
tokens: ["search"],
|
|
1744
|
+
swap: ["quote", "execute"],
|
|
1745
|
+
portfolio: null,
|
|
1746
|
+
recurring: ["list", "create", "cancel"],
|
|
1747
|
+
facilitator: ["create", "list", "publish"],
|
|
1748
|
+
privacy: ["status", "register", "balance", "deposit", "withdraw", "create-utxo", "scan", "claim-latest"],
|
|
1749
|
+
policy: ["get", "set", "init-onchain"]
|
|
1750
|
+
};
|
|
1751
|
+
var CliCommandError = class extends Error {
|
|
1752
|
+
constructor(message, helpCommand = "agentis --help") {
|
|
1753
|
+
super(message);
|
|
1754
|
+
this.helpCommand = helpCommand;
|
|
1755
|
+
this.name = "CliCommandError";
|
|
1756
|
+
}
|
|
1757
|
+
helpCommand;
|
|
1758
|
+
};
|
|
1759
|
+
function editDistance(left, right) {
|
|
1760
|
+
const previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
1761
|
+
for (let i = 1; i <= left.length; i++) {
|
|
1762
|
+
const current = [i];
|
|
1763
|
+
for (let j = 1; j <= right.length; j++) {
|
|
1764
|
+
current[j] = Math.min(
|
|
1765
|
+
current[j - 1] + 1,
|
|
1766
|
+
previous[j] + 1,
|
|
1767
|
+
previous[j - 1] + (left[i - 1] === right[j - 1] ? 0 : 1)
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
previous.splice(0, previous.length, ...current);
|
|
1771
|
+
}
|
|
1772
|
+
return previous[right.length];
|
|
1773
|
+
}
|
|
1774
|
+
function closestMatch(value, choices) {
|
|
1775
|
+
const ranked = choices.map((choice) => ({ choice, distance: editDistance(value, choice) })).sort((a, b) => a.distance - b.distance);
|
|
1776
|
+
const best = ranked[0];
|
|
1777
|
+
if (!best) return null;
|
|
1778
|
+
const threshold = Math.max(1, Math.floor(Math.max(value.length, best.choice.length) / 3));
|
|
1779
|
+
return best.distance <= threshold ? best.choice : null;
|
|
1780
|
+
}
|
|
1781
|
+
function unknownMessage(kind, value, suggestion, parent) {
|
|
1782
|
+
const context = kind === "subcommand" ? ` for "${parent}"` : "";
|
|
1783
|
+
return `Unknown ${kind} "${value}"${context}.${suggestion ? ` Did you mean "${suggestion}"?` : ""}`;
|
|
1784
|
+
}
|
|
1785
|
+
function validateCommand(args2) {
|
|
1786
|
+
const command = args2[0];
|
|
1787
|
+
if (!command || command === "--version" || command === "-v" || command === "--help" || command === "-h") return;
|
|
1788
|
+
const subcommands = commandTree[command];
|
|
1789
|
+
if (subcommands === void 0) {
|
|
1790
|
+
throw new CliCommandError(
|
|
1791
|
+
unknownMessage("command", command, closestMatch(command, Object.keys(commandTree)))
|
|
1792
|
+
);
|
|
1793
|
+
}
|
|
1794
|
+
if (!subcommands) return;
|
|
1795
|
+
const subcommand = args2[1];
|
|
1796
|
+
const hasHelp = args2.includes("--help") || args2.includes("-h");
|
|
1797
|
+
if (!subcommand) {
|
|
1798
|
+
if (hasHelp) return;
|
|
1799
|
+
throw new CliCommandError(`Missing command for "${command}".`, `agentis ${command} --help`);
|
|
1800
|
+
}
|
|
1801
|
+
if (subcommand.startsWith("-") && hasHelp) return;
|
|
1802
|
+
if (!subcommands.includes(subcommand)) {
|
|
1803
|
+
throw new CliCommandError(
|
|
1804
|
+
unknownMessage("subcommand", subcommand, closestMatch(subcommand, subcommands), command),
|
|
1805
|
+
`agentis ${command} --help`
|
|
1806
|
+
);
|
|
1807
|
+
}
|
|
1808
|
+
}
|
|
1809
|
+
|
|
1733
1810
|
// src/index.ts
|
|
1734
1811
|
var args = process.argv.slice(2);
|
|
1735
1812
|
var cmd = args[0];
|
|
@@ -2155,6 +2232,7 @@ function showCommandHelp(path) {
|
|
|
2155
2232
|
console.log();
|
|
2156
2233
|
}
|
|
2157
2234
|
async function main() {
|
|
2235
|
+
validateCommand(args);
|
|
2158
2236
|
if (cmd === "--version" || cmd === "-v" || cmd === "version") {
|
|
2159
2237
|
console.log(version);
|
|
2160
2238
|
return;
|
|
@@ -2181,8 +2259,6 @@ async function main() {
|
|
|
2181
2259
|
case "list":
|
|
2182
2260
|
await walletList(args.slice(2));
|
|
2183
2261
|
break;
|
|
2184
|
-
default:
|
|
2185
|
-
console.log("Usage: agentis wallet <create|list>");
|
|
2186
2262
|
}
|
|
2187
2263
|
break;
|
|
2188
2264
|
case "agent":
|
|
@@ -2196,8 +2272,6 @@ async function main() {
|
|
|
2196
2272
|
case "balance":
|
|
2197
2273
|
await agentBalance(args[2]);
|
|
2198
2274
|
break;
|
|
2199
|
-
default:
|
|
2200
|
-
console.log("Usage: agentis agent <create|send|balance>");
|
|
2201
2275
|
}
|
|
2202
2276
|
break;
|
|
2203
2277
|
case "policy":
|
|
@@ -2211,8 +2285,6 @@ async function main() {
|
|
|
2211
2285
|
case "init-onchain":
|
|
2212
2286
|
await policyInitOnchain(args[2]);
|
|
2213
2287
|
break;
|
|
2214
|
-
default:
|
|
2215
|
-
console.log("Usage: agentis policy <get|set|init-onchain>");
|
|
2216
2288
|
}
|
|
2217
2289
|
break;
|
|
2218
2290
|
case "fetch":
|
|
@@ -2233,11 +2305,15 @@ async function main() {
|
|
|
2233
2305
|
case "recurring":
|
|
2234
2306
|
await financialCommand(args);
|
|
2235
2307
|
break;
|
|
2236
|
-
default:
|
|
2237
|
-
showHelp();
|
|
2238
2308
|
}
|
|
2239
2309
|
}
|
|
2240
2310
|
main().catch((err) => {
|
|
2241
|
-
|
|
2311
|
+
if (err instanceof CliCommandError) {
|
|
2312
|
+
console.error(`Error: ${err.message}
|
|
2313
|
+
|
|
2314
|
+
Run \`${err.helpCommand}\` for usage.`);
|
|
2315
|
+
} else {
|
|
2316
|
+
console.error("Error:", err instanceof Error ? err.message : String(err));
|
|
2317
|
+
}
|
|
2242
2318
|
process.exit(1);
|
|
2243
2319
|
});
|