@axisagent/cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -23,13 +23,36 @@ function printHelp() {
23
23
  Commands:
24
24
  list [--chain Base] [--json]
25
25
  inspect <skill-id> [--json]
26
- install <skill-id> [--target .axis/skills]
27
- scan <skill-dir>
26
+ install <skill-id> [--target .axis/skills] [--scan] [--json]
27
+ scan <skill-dir> [--json]
28
28
  validate
29
29
  connect [--pair AXIS-4821] [--api https://api.axisagent.xyz] [--once]
30
30
  serve [--port 8788]
31
31
  `);
32
32
  }
33
+ function severityIcon(severity) {
34
+ if (severity === "safe")
35
+ return "OK";
36
+ if (severity === "warning")
37
+ return "REVIEW";
38
+ return "BLOCKED";
39
+ }
40
+ function formatScanReport(skillDir, result) {
41
+ const lines = [
42
+ `Axis Scan ${result.ok ? "passed" : "blocked"}`,
43
+ `Path: ${skillDir}`,
44
+ ""
45
+ ];
46
+ if (result.policy) {
47
+ lines.push("Policy", ` Skill: ${result.policy.id ?? "unknown"}`, ` Risk: ${result.policy.risk ?? "unknown"}`, ` Mode: ${result.policy.executionMode ?? "unknown"}`, ` Approval: ${result.policy.requiresApproval ? "required" : "not required"}`, ` Wallet write: ${result.policy.walletWrite ? "declared" : "none"}`, ` Max spend: ${result.policy.maxSpendUsd == null ? "none" : `$${result.policy.maxSpendUsd}`}`, ` Permissions: ${(result.policy.permissions ?? []).join(", ") || "none"}`, "");
48
+ }
49
+ lines.push("Checks");
50
+ for (const finding of result.findings) {
51
+ lines.push(` [${severityIcon(finding.severity)}] ${finding.label}: ${finding.value}`);
52
+ }
53
+ lines.push("", "Next", result.ok ? " Return to Axis and review the Axis Check before execution." : " Fix blocked checks before using this skill.", " Never approve wallet or market actions without reading the preview.");
54
+ return lines.join("\n");
55
+ }
33
56
  async function run() {
34
57
  if (command === "help" || command === "--help" || command === "-h") {
35
58
  printHelp();
@@ -64,17 +87,36 @@ async function run() {
64
87
  const target = resolve(userCwd, getOption("--target", ".axis/skills") ?? ".axis/skills");
65
88
  await mkdir(target, { recursive: true });
66
89
  const result = await writeSkillPackage(id, target);
67
- console.log(`Installed ${result.skill.id}`);
90
+ const scan = hasFlag("--scan") ? await scanSkillPackage(result.skillDir) : null;
91
+ if (hasFlag("--json")) {
92
+ console.log(JSON.stringify({ installed: result.skill.id, path: result.skillDir, files: result.files, scan }, null, 2));
93
+ if (scan && !scan.ok)
94
+ process.exitCode = 1;
95
+ return;
96
+ }
97
+ console.log(`Axis Install complete`);
98
+ console.log(`Skill: ${result.skill.id}`);
68
99
  console.log(`Path: ${result.skillDir}`);
69
100
  console.log(`Files: ${result.files.join(", ")}`);
101
+ if (scan) {
102
+ console.log("");
103
+ console.log(formatScanReport(result.skillDir, scan));
104
+ if (!scan.ok)
105
+ process.exitCode = 1;
106
+ }
107
+ else {
108
+ console.log("");
109
+ console.log(`Next: npx @axisagent/cli scan ${result.skillDir}`);
110
+ }
70
111
  return;
71
112
  }
72
113
  if (command === "scan") {
73
114
  const target = args[1];
74
115
  if (!target)
75
116
  throw new Error("Missing skill directory.");
76
- const result = await scanSkillPackage(resolve(userCwd, target));
77
- console.log(JSON.stringify(result, null, 2));
117
+ const skillDir = resolve(userCwd, target);
118
+ const result = await scanSkillPackage(skillDir);
119
+ console.log(hasFlag("--json") ? JSON.stringify(result, null, 2) : formatScanReport(skillDir, result));
78
120
  if (!result.ok)
79
121
  process.exitCode = 1;
80
122
  return;
@@ -1,3 +1,20 @@
1
+ export type ScanResult = {
2
+ ok: boolean;
3
+ findings: Array<{
4
+ label: string;
5
+ severity: "safe" | "warning" | "blocked";
6
+ value: string;
7
+ }>;
8
+ policy?: {
9
+ id?: string;
10
+ risk?: string;
11
+ executionMode?: string;
12
+ permissions?: string[];
13
+ requiresApproval?: boolean;
14
+ walletWrite?: boolean;
15
+ maxSpendUsd?: number | null;
16
+ };
17
+ };
1
18
  export declare function writeSkillPackage(skillId: string, targetDir: string): Promise<{
2
19
  skill: {
3
20
  id: string;
@@ -31,11 +48,4 @@ export declare function writeSkillPackage(skillId: string, targetDir: string): P
31
48
  skillDir: string;
32
49
  files: string[];
33
50
  }>;
34
- export declare function scanSkillPackage(skillDir: string): Promise<{
35
- ok: boolean;
36
- findings: {
37
- label: string;
38
- severity: "safe" | "warning" | "blocked";
39
- value: string;
40
- }[];
41
- }>;
51
+ export declare function scanSkillPackage(skillDir: string): Promise<ScanResult>;
@@ -43,6 +43,15 @@ export async function scanSkillPackage(skillDir) {
43
43
  }
44
44
  return {
45
45
  ok: findings.every((finding) => finding.severity !== "blocked"),
46
- findings
46
+ findings,
47
+ policy: {
48
+ id: policyJson.id,
49
+ risk: policyJson.risk,
50
+ executionMode: policyJson.executionMode,
51
+ permissions: policyJson.permissions ?? [],
52
+ requiresApproval: policyJson.policy?.requiresApproval,
53
+ walletWrite: policyJson.policy?.walletWrite,
54
+ maxSpendUsd: policyJson.policy?.maxSpendUsd
55
+ }
47
56
  };
48
57
  }
@@ -1,4 +1,4 @@
1
- import { access, readdir } from "node:fs/promises";
1
+ import { access, mkdir, readdir, writeFile } from "node:fs/promises";
2
2
  import { homedir } from "node:os";
3
3
  import { join } from "node:path";
4
4
  import { getRegistryStats } from "./skillRegistry.js";
@@ -73,6 +73,50 @@ async function postJson(url, body, token) {
73
73
  }
74
74
  return payload;
75
75
  }
76
+ function safeTaskFileName(task) {
77
+ const title = task.title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 64) || "task";
78
+ return `${new Date(task.createdAt).toISOString().replace(/[:.]/g, "-")}-${title}.md`;
79
+ }
80
+ async function writeTaskInbox(baseDir, task) {
81
+ const inboxDir = join(baseDir, ".axis", "inbox");
82
+ await mkdir(inboxDir, { recursive: true });
83
+ const filePath = join(inboxDir, safeTaskFileName(task));
84
+ const body = [
85
+ `# ${task.title}`,
86
+ "",
87
+ `- Task: ${task.id}`,
88
+ `- Kind: ${task.kind}`,
89
+ `- Target: ${task.targetAgent}`,
90
+ `- Skill: ${task.skillId ?? "n/a"}`,
91
+ `- Created: ${task.createdAt}`,
92
+ "",
93
+ task.command ? "## Command\n" : "",
94
+ task.command ? `\`\`\`bash\n${task.command}\n\`\`\`\n` : "",
95
+ "## Prompt",
96
+ "",
97
+ task.prompt,
98
+ "",
99
+ "## Axis Rule",
100
+ "",
101
+ "Do not execute wallet, API, market, or payment actions until the user approves the Axis review ticket."
102
+ ].filter(Boolean).join("\n");
103
+ await writeFile(filePath, body, "utf8");
104
+ return filePath;
105
+ }
106
+ async function processRelayTasks(baseDir, tasks) {
107
+ for (const task of tasks) {
108
+ const filePath = await writeTaskInbox(baseDir, task);
109
+ console.log("");
110
+ console.log(`Axis task received: ${task.title}`);
111
+ console.log(`Target: ${task.targetAgent}`);
112
+ if (task.command)
113
+ console.log(`Command: ${task.command}`);
114
+ console.log(`Inbox: ${filePath}`);
115
+ console.log("Prompt:");
116
+ console.log(task.prompt);
117
+ console.log("");
118
+ }
119
+ }
76
120
  async function createRelayPayload(baseDir, pairingCode) {
77
121
  return {
78
122
  pairingCode,
@@ -105,5 +149,8 @@ export async function connectRelay(options) {
105
149
  const heartbeatPayload = await createRelayPayload(options.baseDir, pairingCode);
106
150
  const heartbeat = await postJson(`${apiUrl}/v1/relay/${pairingCode}/heartbeat`, heartbeatPayload, connected.relayToken);
107
151
  console.log(`[${heartbeat.session.lastSeenAt}] relay ${heartbeat.session.status}`);
152
+ if (heartbeat.tasks?.length) {
153
+ await processRelayTasks(options.baseDir, heartbeat.tasks);
154
+ }
108
155
  }
109
156
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@axisagent/cli",
3
3
  "private": false,
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "type": "module",
6
6
  "description": "Local Axis runtime, skill registry, policy validator, and CLI.",
7
7
  "license": "MIT",