palmier 0.1.3 → 0.1.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/commands/serve.js +23 -13
- package/dist/index.js +6 -1
- package/package.json +1 -1
- package/src/commands/serve.ts +23 -12
- package/src/index.ts +7 -1
package/dist/commands/serve.js
CHANGED
|
@@ -41,24 +41,34 @@ export async function serveCommand() {
|
|
|
41
41
|
}
|
|
42
42
|
console.log("Agent serving. Waiting for RPC messages...");
|
|
43
43
|
for await (const msg of sub) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
// Derive RPC method from subject: ...rpc.<method parts>
|
|
45
|
+
const subjectTokens = msg.subject.split(".");
|
|
46
|
+
const rpcIdx = subjectTokens.indexOf("rpc");
|
|
47
|
+
const method = rpcIdx >= 0 ? subjectTokens.slice(rpcIdx + 1).join(".") : "";
|
|
48
|
+
// Parse params from message body (the PWA sends params directly, no wrapper)
|
|
49
|
+
let params = {};
|
|
50
|
+
if (msg.data && msg.data.length > 0) {
|
|
51
|
+
const raw = sc.decode(msg.data).trim();
|
|
52
|
+
if (raw.length > 0) {
|
|
53
|
+
try {
|
|
54
|
+
params = JSON.parse(raw);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
console.error(`Failed to parse RPC params for ${method}`);
|
|
58
|
+
if (msg.reply) {
|
|
59
|
+
msg.respond(sc.encode(JSON.stringify({ error: "Invalid JSON" })));
|
|
60
|
+
}
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
52
63
|
}
|
|
53
|
-
continue;
|
|
54
64
|
}
|
|
55
|
-
console.log(`RPC: ${
|
|
65
|
+
console.log(`RPC: ${method}`);
|
|
56
66
|
let response;
|
|
57
67
|
try {
|
|
58
|
-
response = await handleRpc(
|
|
68
|
+
response = await handleRpc({ method, params });
|
|
59
69
|
}
|
|
60
70
|
catch (err) {
|
|
61
|
-
console.error(`RPC error (${
|
|
71
|
+
console.error(`RPC error (${method}):`, err);
|
|
62
72
|
response = { error: String(err) };
|
|
63
73
|
}
|
|
64
74
|
if (msg.reply) {
|
|
@@ -137,7 +147,7 @@ export async function serveCommand() {
|
|
|
137
147
|
cwd: config.projectRoot,
|
|
138
148
|
timeout: 120_000,
|
|
139
149
|
});
|
|
140
|
-
return { ok: true, output };
|
|
150
|
+
return { ok: true, body: output };
|
|
141
151
|
}
|
|
142
152
|
catch (err) {
|
|
143
153
|
const error = err;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import "dotenv/config";
|
|
3
|
+
import { readFileSync } from "fs";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import { dirname, join } from "path";
|
|
3
6
|
import { Command } from "commander";
|
|
4
7
|
import { initCommand } from "./commands/init.js";
|
|
5
8
|
import { runCommand } from "./commands/run.js";
|
|
6
9
|
import { hookCommand } from "./commands/hook.js";
|
|
7
10
|
import { serveCommand } from "./commands/serve.js";
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
|
|
8
13
|
const program = new Command();
|
|
9
14
|
program
|
|
10
15
|
.name("palmier")
|
|
11
16
|
.description("Palmier agent CLI")
|
|
12
|
-
.version(
|
|
17
|
+
.version(pkg.version);
|
|
13
18
|
program
|
|
14
19
|
.command("init")
|
|
15
20
|
.description("Provision this agent with a provisioning token")
|
package/package.json
CHANGED
package/src/commands/serve.ts
CHANGED
|
@@ -49,24 +49,35 @@ export async function serveCommand(): Promise<void> {
|
|
|
49
49
|
console.log("Agent serving. Waiting for RPC messages...");
|
|
50
50
|
|
|
51
51
|
for await (const msg of sub) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
// Derive RPC method from subject: ...rpc.<method parts>
|
|
53
|
+
const subjectTokens = msg.subject.split(".");
|
|
54
|
+
const rpcIdx = subjectTokens.indexOf("rpc");
|
|
55
|
+
const method = rpcIdx >= 0 ? subjectTokens.slice(rpcIdx + 1).join(".") : "";
|
|
56
|
+
|
|
57
|
+
// Parse params from message body (the PWA sends params directly, no wrapper)
|
|
58
|
+
let params: Record<string, unknown> = {};
|
|
59
|
+
if (msg.data && msg.data.length > 0) {
|
|
60
|
+
const raw = sc.decode(msg.data).trim();
|
|
61
|
+
if (raw.length > 0) {
|
|
62
|
+
try {
|
|
63
|
+
params = JSON.parse(raw);
|
|
64
|
+
} catch {
|
|
65
|
+
console.error(`Failed to parse RPC params for ${method}`);
|
|
66
|
+
if (msg.reply) {
|
|
67
|
+
msg.respond(sc.encode(JSON.stringify({ error: "Invalid JSON" })));
|
|
68
|
+
}
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
59
71
|
}
|
|
60
|
-
continue;
|
|
61
72
|
}
|
|
62
73
|
|
|
63
|
-
console.log(`RPC: ${
|
|
74
|
+
console.log(`RPC: ${method}`);
|
|
64
75
|
|
|
65
76
|
let response: unknown;
|
|
66
77
|
try {
|
|
67
|
-
response = await handleRpc(
|
|
78
|
+
response = await handleRpc({ method, params });
|
|
68
79
|
} catch (err) {
|
|
69
|
-
console.error(`RPC error (${
|
|
80
|
+
console.error(`RPC error (${method}):`, err);
|
|
70
81
|
response = { error: String(err) };
|
|
71
82
|
}
|
|
72
83
|
|
|
@@ -176,7 +187,7 @@ export async function serveCommand(): Promise<void> {
|
|
|
176
187
|
cwd: config.projectRoot,
|
|
177
188
|
timeout: 120_000,
|
|
178
189
|
});
|
|
179
|
-
return { ok: true, output };
|
|
190
|
+
return { ok: true, body: output };
|
|
180
191
|
} catch (err: unknown) {
|
|
181
192
|
const error = err as { stdout?: string; stderr?: string };
|
|
182
193
|
return { error: "claude command failed", stdout: error.stdout, stderr: error.stderr };
|
package/src/index.ts
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import "dotenv/config";
|
|
4
|
+
import { readFileSync } from "fs";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import { dirname, join } from "path";
|
|
4
7
|
import { Command } from "commander";
|
|
5
8
|
import { initCommand } from "./commands/init.js";
|
|
6
9
|
import { runCommand } from "./commands/run.js";
|
|
7
10
|
import { hookCommand } from "./commands/hook.js";
|
|
8
11
|
import { serveCommand } from "./commands/serve.js";
|
|
9
12
|
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf-8"));
|
|
15
|
+
|
|
10
16
|
const program = new Command();
|
|
11
17
|
|
|
12
18
|
program
|
|
13
19
|
.name("palmier")
|
|
14
20
|
.description("Palmier agent CLI")
|
|
15
|
-
.version(
|
|
21
|
+
.version(pkg.version);
|
|
16
22
|
|
|
17
23
|
program
|
|
18
24
|
.command("init")
|