@axisagent/cli 0.1.1 → 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/relayClient.js +48 -1
- package/package.json +1 -1
package/dist/relayClient.js
CHANGED
|
@@ -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
|
}
|