@phreshos/cli 0.1.47 → 0.1.49

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.
@@ -1,68 +0,0 @@
1
- import { Option } from "commander";
2
- import { commandContract } from "../command-contract.js";
3
- import { outputOptions } from "./options.js";
4
- import { bounded, connected, integer, output, page, programView, requireProgram, wait } from "./shared.js";
5
- export default function programCommands(root, connect) {
6
- const program = commandContract(root.command("program")
7
- .description("discover PhreshOS Programs and their agent documentation"));
8
- outputOptions(program.command("list")
9
- .description("list Programs with bounded filtering")
10
- .option("--installed-only", "return only installed Programs")
11
- .option("--search <text>", "case-insensitive identity, name, or description search")
12
- .option("--limit <count>", "maximum returned Programs", integer, 30)
13
- .option("--offset <count>", "number of matching Programs to skip", integer, 0))
14
- .action(async (options) => connected(connect, async (system) => {
15
- const programs = await system.program.list(options.installedOnly === true);
16
- const selected = page(programs, options.search, bounded(options.offset, "--offset", 0), bounded(options.limit, "--limit", 1, 100), value => `${value.identity}\n${value.name}\n${value.description ?? ""}`);
17
- output({ ...selected, data: await Promise.all(selected.data.map(programView)) }, options.compact);
18
- }));
19
- outputOptions(program.command("inspect")
20
- .description("read one Program declaration and installed state")
21
- .requiredOption("--program <identity>", "Program identity"))
22
- .action(async (options) => connected(connect, async (system) => {
23
- output(await programView(await requireProgram(system, options.program)), options.compact);
24
- }));
25
- outputOptions(program.command("agent")
26
- .description("read a Program's own agent operating policy")
27
- .requiredOption("--program <identity>", "Program identity"))
28
- .action(async (options) => connected(connect, async (system) => {
29
- const program = await requireProgram(system, options.program);
30
- const content = await program.agent();
31
- if (content === null)
32
- throw new Error(`Program "${program.identity}" has no agent documentation`);
33
- output({ program: program.identity, content }, options.compact);
34
- }));
35
- outputOptions(program.command("wait")
36
- .description("wait for one Program registry event")
37
- .addOption(new Option("--event <event>", "Program lifecycle event")
38
- .choices(["create", "forget", "install", "uninstall"])
39
- .makeOptionMandatory())
40
- .option("--program <identity>", "scope forget or uninstall to one Program")
41
- .option("--timeout <milliseconds>", "maximum wait in milliseconds", integer))
42
- .action(async (options) => connected(connect, async (system) => {
43
- if (options.program && options.event !== "forget" && options.event !== "uninstall") {
44
- throw new Error("An individual Program emits only forget and uninstall");
45
- }
46
- const target = options.program ? await requireProgram(system, options.program) : system.program;
47
- const message = await wait(target, options.event, timeout(options.timeout));
48
- output({
49
- scope: options.program ? `program:${options.program}` : "program",
50
- event: options.event,
51
- payload: await eventView(options.event, message, options.program ? target : undefined)
52
- }, options.compact);
53
- }));
54
- }
55
- async function eventView(event, message, scoped) {
56
- if (event === "uninstall") {
57
- if (scoped)
58
- return { program: await programView(scoped), everything: message === true };
59
- const value = message;
60
- return { program: await programView(value.program), everything: value.everything };
61
- }
62
- if (scoped)
63
- return programView(scoped);
64
- return programView(message);
65
- }
66
- function timeout(value) {
67
- return value === undefined ? undefined : bounded(value, "--timeout", 1);
68
- }
@@ -1,84 +0,0 @@
1
- import { Option } from "commander";
2
- import { commandContract } from "../command-contract.js";
3
- import { outputOptions, processOptions } from "./options.js";
4
- import { bounded, connected, integer, output, position, requireProcess, size, wait, windowOf, windowView } from "./shared.js";
5
- export default function windowCommands(root, connect) {
6
- const windows = commandContract(root.command("window")
7
- .description("inspect and control authoritative Client Windows"));
8
- outputOptions(processOptions(windows.command("inspect")
9
- .description("read the complete current Window state")))
10
- .action(async (options) => withWindow(connect, options, async (process) => {
11
- output(await windowView(process), options.compact);
12
- }));
13
- outputOptions(processOptions(windows.command("move")
14
- .description("change Window position")
15
- .requiredOption("--x <value>", "horizontal pixels or workspace-relative expression")
16
- .requiredOption("--y <value>", "vertical pixels or workspace-relative expression")))
17
- .action(async (options) => withWindow(connect, options, async (process) => {
18
- await windowOf(process).move(position(options.x, options.y));
19
- output(await windowView(process), options.compact);
20
- }));
21
- outputOptions(processOptions(windows.command("resize")
22
- .description("change Window size")
23
- .requiredOption("--width <value>", "width in pixels or a workspace-relative expression")
24
- .requiredOption("--height <value>", "height in pixels or a workspace-relative expression")))
25
- .action(async (options) => withWindow(connect, options, async (process) => {
26
- await windowOf(process).resize(size(options.width, options.height));
27
- output(await windowView(process), options.compact);
28
- }));
29
- outputOptions(processOptions(windows.command("setGeometry")
30
- .alias("set-geometry")
31
- .description("change Window position and size atomically")
32
- .requiredOption("--x <value>", "horizontal pixels or workspace-relative expression")
33
- .requiredOption("--y <value>", "vertical pixels or workspace-relative expression")
34
- .requiredOption("--width <value>", "width in pixels or a workspace-relative expression")
35
- .requiredOption("--height <value>", "height in pixels or a workspace-relative expression")))
36
- .action(async (options) => withWindow(connect, options, async (process) => {
37
- await windowOf(process).setGeometry({
38
- position: position(options.x, options.y),
39
- size: size(options.width, options.height)
40
- });
41
- output(await windowView(process), options.compact);
42
- }));
43
- outputOptions(processOptions(windows.command("minimize")
44
- .description("set Window visibility without changing its order")
45
- .option("--restore", "restore rather than minimize the Window")))
46
- .action(async (options) => withWindow(connect, options, async (process) => {
47
- await windowOf(process).minimize(options.restore !== true);
48
- output(await windowView(process), options.compact);
49
- }));
50
- outputOptions(processOptions(windows.command("changeTitle")
51
- .alias("change-title")
52
- .description("change the human-readable Window title")
53
- .requiredOption("--title <title>", "new Window title")))
54
- .action(async (options) => withWindow(connect, options, async (process) => {
55
- await windowOf(process).changeTitle(options.title);
56
- output(await windowView(process), options.compact);
57
- }));
58
- outputOptions(processOptions(windows.command("raise")
59
- .description("raise the Window within its own layer")))
60
- .action(async (options) => withWindow(connect, options, async (process) => {
61
- await windowOf(process).raise();
62
- output(await windowView(process), options.compact);
63
- }));
64
- outputOptions(processOptions(windows.command("wait")
65
- .description("wait for one authoritative Window change")
66
- .addOption(new Option("--event <event>", "Window event")
67
- .choices(["move", "resize", "geometry", "minimize", "changeTitle", "front"])
68
- .makeOptionMandatory())
69
- .option("--timeout <milliseconds>", "maximum wait in milliseconds", integer)))
70
- .action(async (options) => withWindow(connect, options, async (process) => {
71
- output({
72
- scope: `window:${process.identity}`,
73
- event: options.event,
74
- payload: await wait(windowOf(process), options.event, options.timeout === undefined
75
- ? undefined
76
- : bounded(options.timeout, "--timeout", 1))
77
- }, options.compact);
78
- }));
79
- }
80
- async function withWindow(connect, options, action) {
81
- await connected(connect, async (system) => {
82
- await action(await requireProcess(system, options.process, options.program));
83
- });
84
- }
@@ -1,56 +0,0 @@
1
- import { commandContract, readCommandContract } from "./command-contract.js";
2
- import { blank } from "./style.js";
3
- /** Add one machine-readable description entry point for the complete CLI tree. */
4
- export default function describeCommands(program) {
5
- commandContract(program.command("describe")
6
- .description("describe any Phresh capability as machine-readable data")
7
- .argument("[path...]", "command path to describe")
8
- .option("--compact", "write JSON on one line")
9
- .action(function (path, options) {
10
- const command = resolveCommand(program, path);
11
- const description = describe(command, path);
12
- console.log(JSON.stringify(description, null, options.compact ? undefined : 2));
13
- blank();
14
- }), { guidance: ["Omit the path to discover all top-level commands, then describe progressively deeper paths."] });
15
- }
16
- function resolveCommand(root, path) {
17
- let command = root;
18
- for (const name of path) {
19
- const child = command.commands.find(candidate => candidate.name() === name);
20
- if (!child)
21
- throw new Error(`Unknown command path "${path.join(" ")}"`);
22
- command = child;
23
- }
24
- return command;
25
- }
26
- function describe(command, path) {
27
- const registered = readCommandContract(command);
28
- return {
29
- path,
30
- name: command.name(),
31
- description: command.description(),
32
- arguments: command.registeredArguments.map(argumentDescription),
33
- options: command.options.map(optionDescription),
34
- commands: command.commands.map(child => ({ name: child.name(), description: child.description() })),
35
- ...(registered?.guidance ? { guidance: registered.guidance } : {})
36
- };
37
- }
38
- function argumentDescription(argument) {
39
- return {
40
- name: argument.name(),
41
- description: argument.description,
42
- required: argument.required,
43
- variadic: argument.variadic,
44
- ...(argument.defaultValue === undefined ? {} : { default: argument.defaultValue })
45
- };
46
- }
47
- function optionDescription(option) {
48
- return {
49
- flags: option.flags,
50
- description: option.description,
51
- value: option.required ? "required" : option.optional ? "optional" : "none",
52
- variadic: option.variadic,
53
- ...(option.defaultValue === undefined ? {} : { default: option.defaultValue }),
54
- ...(option.argChoices === undefined ? {} : { choices: option.argChoices })
55
- };
56
- }