@elpapi42/pi-fleet-cli 0.2.1 → 0.3.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/README.md +1 -1
- package/dist/main.js +76 -51
- package/dist/main.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -18,4 +18,4 @@ pif create named --cwd "$PWD" -- --session-id my-session
|
|
|
18
18
|
|
|
19
19
|
Arguments after `--` pass through to Pi. Pi-fleet adds `--mode rpc` and rejects `--mode` and `--no-session`. Pi owns session lookup, working-directory selection, prompts, and failures.
|
|
20
20
|
|
|
21
|
-
Commands
|
|
21
|
+
Commands print human-readable output. Use `pif --help` or `pif COMMAND --help` for generated usage. By default, pi-fleet stores its LMDB state and IPC sockets in `~/.pi-fleet`. Pre-stable releases do not migrate state from earlier locations automatically. This CLI requires Node.js 22.12 or later. Slice 1 supports Unix-like hosts with ZeroMQ `ipc://` support. It provides `create`, `list`, and `status`. Sending work, event streaming, recovery, retirement, compact, and destroy come in later slices.
|
package/dist/main.js
CHANGED
|
@@ -1,66 +1,91 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { connectPiFleet } from "@elpapi42/pi-fleet-sdk";
|
|
4
|
+
const version = "0.3.1";
|
|
5
|
+
function splitPiArgs(args) {
|
|
6
|
+
const separator = args.indexOf("--");
|
|
7
|
+
if (separator < 0)
|
|
8
|
+
return { pifArgs: args, piArgs: [] };
|
|
9
|
+
return {
|
|
10
|
+
pifArgs: args.slice(0, separator),
|
|
11
|
+
piArgs: args.slice(separator + 1),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function printAgent(id, name, state) {
|
|
15
|
+
console.log(`ID: ${id}`);
|
|
16
|
+
console.log(`Name: ${name}`);
|
|
17
|
+
console.log(`State: ${state}`);
|
|
18
|
+
}
|
|
19
|
+
function printAgentList(agents) {
|
|
20
|
+
if (agents.length === 0) {
|
|
21
|
+
console.log("No agents.");
|
|
16
22
|
return;
|
|
17
23
|
}
|
|
24
|
+
const sorted = [...agents].sort((left, right) => left.name.localeCompare(right.name));
|
|
25
|
+
const nameWidth = Math.max("NAME".length, ...sorted.map((agent) => agent.name.length));
|
|
26
|
+
const stateWidth = Math.max("STATE".length, ...sorted.map((agent) => agent.state.length));
|
|
27
|
+
console.log(`${"NAME".padEnd(nameWidth)} ${"STATE".padEnd(stateWidth)} ID`);
|
|
28
|
+
for (const agent of sorted) {
|
|
29
|
+
console.log(`${agent.name.padEnd(nameWidth)} ${agent.state.padEnd(stateWidth)} ${agent.id}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async function withClient(action) {
|
|
18
33
|
const client = await connectPiFleet();
|
|
19
34
|
try {
|
|
20
|
-
|
|
21
|
-
case "create": {
|
|
22
|
-
const [name, ...remaining] = args.slice(1);
|
|
23
|
-
if (!name)
|
|
24
|
-
throw new Error("Usage: pif create NAME [INSTRUCTIONS] [--cwd PATH] [-- PI_ARGS...]");
|
|
25
|
-
const instructions = remaining[0] && !remaining[0].startsWith("--") ? remaining.shift() : undefined;
|
|
26
|
-
const separator = remaining.indexOf("--");
|
|
27
|
-
const options = separator < 0 ? remaining : remaining.slice(0, separator);
|
|
28
|
-
const piArgs = separator < 0 ? [] : remaining.slice(separator + 1);
|
|
29
|
-
const cwdIndex = options.indexOf("--cwd");
|
|
30
|
-
if (cwdIndex >= 0 && (cwdIndex + 1 >= options.length || options.length !== 2)) {
|
|
31
|
-
throw new Error("Usage: pif create NAME [INSTRUCTIONS] [--cwd PATH] [-- PI_ARGS...]");
|
|
32
|
-
}
|
|
33
|
-
if (cwdIndex < 0 && options.length !== 0)
|
|
34
|
-
throw new Error("Usage: pif create NAME [INSTRUCTIONS] [--cwd PATH] [-- PI_ARGS...]");
|
|
35
|
-
const cwd = cwdIndex < 0 ? process.cwd() : options[cwdIndex + 1];
|
|
36
|
-
const agent = await client.create({ name, instructions, cwd, piArgs });
|
|
37
|
-
console.log(JSON.stringify({ id: agent.id, name: agent.name }));
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
case "status": {
|
|
41
|
-
const name = args[1];
|
|
42
|
-
if (!name || args.length !== 2)
|
|
43
|
-
throw new Error("Usage: pif status NAME");
|
|
44
|
-
console.log(JSON.stringify(await (await client.get(name)).status()));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
case "list":
|
|
48
|
-
if (args.length !== 1)
|
|
49
|
-
throw new Error("Usage: pif list");
|
|
50
|
-
for (const agent of await client.list())
|
|
51
|
-
console.log(JSON.stringify(agent));
|
|
52
|
-
return;
|
|
53
|
-
default:
|
|
54
|
-
throw new Error(`Unknown command: ${args[0]}`);
|
|
55
|
-
}
|
|
35
|
+
return await action(client);
|
|
56
36
|
}
|
|
57
37
|
finally {
|
|
58
38
|
await client.close();
|
|
59
39
|
}
|
|
60
40
|
}
|
|
41
|
+
function createProgram(piArgs) {
|
|
42
|
+
const program = new Command();
|
|
43
|
+
program
|
|
44
|
+
.name("pif")
|
|
45
|
+
.description("Manage durable, host-local Pi agents")
|
|
46
|
+
.version(version)
|
|
47
|
+
.showSuggestionAfterError()
|
|
48
|
+
.showHelpAfterError();
|
|
49
|
+
program
|
|
50
|
+
.command("create <name> [instructions]")
|
|
51
|
+
.description("Create a durable Pi agent")
|
|
52
|
+
.option("--cwd <path>", "working directory", process.cwd())
|
|
53
|
+
.addHelpText("after", "\nArguments after -- pass through to Pi.")
|
|
54
|
+
.action(async (name, instructions, options) => {
|
|
55
|
+
const agent = await withClient((client) => client.create({ name, instructions, cwd: options.cwd, piArgs }));
|
|
56
|
+
console.log(`Created agent ${agent.name}`);
|
|
57
|
+
printAgent(agent.id, agent.name, "idle");
|
|
58
|
+
});
|
|
59
|
+
program
|
|
60
|
+
.command("status <name>")
|
|
61
|
+
.description("Show an agent's current state")
|
|
62
|
+
.action(async (name) => {
|
|
63
|
+
const status = await withClient(async (client) => (await client.get(name)).status());
|
|
64
|
+
printAgent(status.id, status.name, status.state);
|
|
65
|
+
});
|
|
66
|
+
program
|
|
67
|
+
.command("list")
|
|
68
|
+
.description("List durable Pi agents")
|
|
69
|
+
.action(async () => {
|
|
70
|
+
printAgentList(await withClient((client) => client.list()));
|
|
71
|
+
});
|
|
72
|
+
return program;
|
|
73
|
+
}
|
|
74
|
+
async function main(args) {
|
|
75
|
+
const { pifArgs, piArgs } = splitPiArgs(args);
|
|
76
|
+
const program = createProgram(piArgs);
|
|
77
|
+
if (piArgs.length > 0 && pifArgs[0] !== "create") {
|
|
78
|
+
program.error("Arguments after -- are supported only by pif create");
|
|
79
|
+
}
|
|
80
|
+
if (pifArgs.length === 0) {
|
|
81
|
+
program.help();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
await program.parseAsync(["node", "pif", ...pifArgs]);
|
|
85
|
+
}
|
|
61
86
|
void main(process.argv.slice(2)).catch((error) => {
|
|
62
87
|
const message = error instanceof Error ? error.message : String(error);
|
|
63
|
-
|
|
88
|
+
console.error(message);
|
|
64
89
|
process.exitCode = 1;
|
|
65
90
|
});
|
|
66
91
|
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAEvD,MAAM,OAAO,GAAG,OAAO,CAAA;AAEvB,SAAS,WAA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AC,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAA;IACtE,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,IAAI,EAAE,CAAA;QACd,OAAM;IACR,CAAC;IACD,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,CAAC,CAAA;AACvD,CAAC;AAED,KAAK,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC/C,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IACtE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACtB,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAA;AACtB,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elpapi42/pi-fleet-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "CLI for durable, host-local Pi agents",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
12
|
"engines": {
|
|
13
|
-
"node": ">=22"
|
|
13
|
+
"node": ">=22.12.0"
|
|
14
14
|
},
|
|
15
15
|
"bin": {
|
|
16
16
|
"pif": "./dist/main.js"
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"test": "node --test test/*.test.mjs"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@elpapi42/pi-fleet-sdk": "0.2.
|
|
27
|
+
"@elpapi42/pi-fleet-sdk": "0.2.2",
|
|
28
|
+
"commander": "15.0.0"
|
|
28
29
|
}
|
|
29
30
|
}
|