@demicodes/shell 0.1.0 → 0.2.0
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/{host-BfjoIvF3.d.mts → host-DIg4RxcL.d.mts} +5 -0
- package/dist/host-fs.d.mts +1 -2
- package/dist/host-fs.mjs +4 -4
- package/dist/index.d.mts +50 -32
- package/dist/index.mjs +314 -282
- package/dist/storage-MeB35Df6.d.mts +105 -0
- package/dist/storage.d.mts +1 -1
- package/package.json +3 -3
- package/dist/storage-DJxxqyZA.d.mts +0 -111
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { u as HostStore } from "./host-DIg4RxcL.mjs";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/command.d.ts
|
|
4
|
+
type CommandInputSpec = Record<string, z.ZodType>;
|
|
5
|
+
interface CommandOutputSpec {
|
|
6
|
+
json?: z.ZodType;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* One CLI tree node. Routing (`subcommands`) and execution (`run`) are
|
|
10
|
+
* independent optional capabilities — registration requires at least one.
|
|
11
|
+
*/
|
|
12
|
+
interface Command {
|
|
13
|
+
name: string;
|
|
14
|
+
summary: string;
|
|
15
|
+
/** Present when this node routes to named children. */
|
|
16
|
+
subcommands?: Command[];
|
|
17
|
+
/**
|
|
18
|
+
* Present when this node is executable with its own args/flags.
|
|
19
|
+
* Execution-only fields below are only meaningful when `run` is set.
|
|
20
|
+
*/
|
|
21
|
+
run?: (ctx: CommandRunContext) => Promise<CommandRunResult> | CommandRunResult;
|
|
22
|
+
effects?: string;
|
|
23
|
+
successOutput?: string;
|
|
24
|
+
failureOutput?: string;
|
|
25
|
+
input?: CommandInputSpec;
|
|
26
|
+
positionals?: string[];
|
|
27
|
+
stdinField?: string;
|
|
28
|
+
output?: CommandOutputSpec;
|
|
29
|
+
/** Required when `run` is set; an empty array renders no examples section. */
|
|
30
|
+
examples?: string[];
|
|
31
|
+
}
|
|
32
|
+
interface ParsedCommandInput {
|
|
33
|
+
/**
|
|
34
|
+
* Path from root through the selected node, including the root name.
|
|
35
|
+
* For help: path of the node help was requested for.
|
|
36
|
+
*/
|
|
37
|
+
path: string[];
|
|
38
|
+
/** True when the invocation requested `--help`. */
|
|
39
|
+
help: boolean;
|
|
40
|
+
values: Record<string, unknown>;
|
|
41
|
+
json: boolean;
|
|
42
|
+
}
|
|
43
|
+
interface CommandRunContext {
|
|
44
|
+
argv: string[];
|
|
45
|
+
parsed: ParsedCommandInput;
|
|
46
|
+
stdin: CommandStdin;
|
|
47
|
+
env: Record<string, string>;
|
|
48
|
+
cwd: string;
|
|
49
|
+
io: CommandIO;
|
|
50
|
+
storage: CommandStorage;
|
|
51
|
+
}
|
|
52
|
+
interface CommandRunResult {
|
|
53
|
+
exitCode: number;
|
|
54
|
+
metadata?: unknown;
|
|
55
|
+
}
|
|
56
|
+
interface CommandStdin {
|
|
57
|
+
/** Stdin decoded as UTF-8 text (lossy for non-text input). */
|
|
58
|
+
text: string;
|
|
59
|
+
/** Raw stdin bytes, byte-identical to what the pipe delivered. */
|
|
60
|
+
bytes: Uint8Array;
|
|
61
|
+
}
|
|
62
|
+
declare function emptyStdin(): CommandStdin;
|
|
63
|
+
interface CommandIO {
|
|
64
|
+
stdout(data: string | Uint8Array): Promise<void> | void;
|
|
65
|
+
stderr(data: string | Uint8Array): Promise<void> | void;
|
|
66
|
+
}
|
|
67
|
+
interface CommandStorage {
|
|
68
|
+
readJson<T>(key: string): Promise<T | null>;
|
|
69
|
+
writeJson<T>(key: string, value: T): Promise<void>;
|
|
70
|
+
delete(key: string): Promise<void>;
|
|
71
|
+
list(prefix: string): Promise<string[]>;
|
|
72
|
+
}
|
|
73
|
+
interface CommandExecutionContext {
|
|
74
|
+
argv: string[];
|
|
75
|
+
stdin?: CommandStdin;
|
|
76
|
+
env: Record<string, string>;
|
|
77
|
+
cwd: string;
|
|
78
|
+
io: CommandIO;
|
|
79
|
+
storage: CommandStorage;
|
|
80
|
+
}
|
|
81
|
+
declare class CommandRegistry {
|
|
82
|
+
private readonly commands;
|
|
83
|
+
register(command: Command): void;
|
|
84
|
+
get(name: string): Command | null;
|
|
85
|
+
list(): Command[];
|
|
86
|
+
renderHelp(): string;
|
|
87
|
+
}
|
|
88
|
+
declare const COMMAND_HELP_DEFAULTS = "Unless a command states otherwise: success prints raw text on stdout, failure writes an error message to stderr and exits non-zero. Pass --help at any level to print a command's documentation.";
|
|
89
|
+
declare function parseCommandInput(root: Command, argv: string[], stdin?: CommandStdin): ParsedCommandInput;
|
|
90
|
+
declare function runRegisteredCommand(root: Command, ctx: CommandExecutionContext): Promise<CommandRunResult>;
|
|
91
|
+
declare function renderCommandHelp(command: Command, parentPath?: string): string;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/storage.d.ts
|
|
94
|
+
declare class AgentSessionCommandStorage implements CommandStorage {
|
|
95
|
+
private readonly store;
|
|
96
|
+
private readonly agentSessionPrefix;
|
|
97
|
+
constructor(store: HostStore, agentSessionId: string);
|
|
98
|
+
readJson<T>(key: string): Promise<T | null>;
|
|
99
|
+
writeJson<T>(key: string, value: T): Promise<void>;
|
|
100
|
+
delete(key: string): Promise<void>;
|
|
101
|
+
list(prefix: string): Promise<string[]>;
|
|
102
|
+
private key;
|
|
103
|
+
}
|
|
104
|
+
//#endregion
|
|
105
|
+
export { runRegisteredCommand as _, CommandIO as a, CommandRegistry as c, CommandStdin as d, CommandStorage as f, renderCommandHelp as g, parseCommandInput as h, CommandExecutionContext as i, CommandRunContext as l, emptyStdin as m, COMMAND_HELP_DEFAULTS as n, CommandInputSpec as o, ParsedCommandInput as p, Command as r, CommandOutputSpec as s, AgentSessionCommandStorage as t, CommandRunResult as u };
|
package/dist/storage.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as AgentSessionCommandStorage } from "./storage-
|
|
1
|
+
import { t as AgentSessionCommandStorage } from "./storage-MeB35Df6.mjs";
|
|
2
2
|
export { AgentSessionCommandStorage };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@demicodes/shell",
|
|
3
3
|
"description": "Sandboxable bash engine and Host contract for Demi.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@demicodes/utils": "
|
|
26
|
-
"@demicodes/just-bash": "
|
|
25
|
+
"@demicodes/utils": "0.2.0",
|
|
26
|
+
"@demicodes/just-bash": "3.0.1-demi.4",
|
|
27
27
|
"zod": "^4.0.0"
|
|
28
28
|
},
|
|
29
29
|
"license": "Apache-2.0",
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { u as HostStore } from "./host-BfjoIvF3.mjs";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
|
|
4
|
-
//#region src/command.d.ts
|
|
5
|
-
type CommandInputSpec = Record<string, z.ZodType>;
|
|
6
|
-
/**
|
|
7
|
-
* A command is a tree of arbitrary depth, matching standard CLI semantics
|
|
8
|
-
* (cobra/click): group nodes (`CommandSpec`) route and render help, leaf nodes
|
|
9
|
-
* (`CommandSubcommandSpec`) carry the input schema and the executable. The
|
|
10
|
-
* registry registers root groups; `<path...> prompt` renders help at any group.
|
|
11
|
-
*/
|
|
12
|
-
interface CommandSpec {
|
|
13
|
-
name: string;
|
|
14
|
-
summary: string;
|
|
15
|
-
subcommands: CommandNode[];
|
|
16
|
-
}
|
|
17
|
-
type CommandNode = CommandSpec | CommandSubcommandSpec;
|
|
18
|
-
declare function isCommandGroup(node: CommandNode): node is CommandSpec;
|
|
19
|
-
interface CommandSubcommandSpec {
|
|
20
|
-
name: string;
|
|
21
|
-
summary: string;
|
|
22
|
-
effects?: string;
|
|
23
|
-
successOutput?: string;
|
|
24
|
-
failureOutput?: string;
|
|
25
|
-
input?: CommandInputSpec;
|
|
26
|
-
positionals?: string[];
|
|
27
|
-
stdinField?: string;
|
|
28
|
-
output?: CommandOutputSpec;
|
|
29
|
-
examples: string[];
|
|
30
|
-
run(ctx: CommandRunContext): Promise<CommandRunResult> | CommandRunResult;
|
|
31
|
-
}
|
|
32
|
-
interface CommandOutputSpec {
|
|
33
|
-
json?: z.ZodType;
|
|
34
|
-
}
|
|
35
|
-
interface ParsedCommandInput {
|
|
36
|
-
/** Leaf subcommand name, or 'prompt' for the help pseudo-subcommand. */
|
|
37
|
-
subcommand: string;
|
|
38
|
-
/**
|
|
39
|
-
* Segments after the root command name: group names down to the leaf. For
|
|
40
|
-
* 'prompt' it is the path of the group the help applies to (empty = root).
|
|
41
|
-
*/
|
|
42
|
-
path: string[];
|
|
43
|
-
values: Record<string, unknown>;
|
|
44
|
-
json: boolean;
|
|
45
|
-
}
|
|
46
|
-
interface CommandRunContext {
|
|
47
|
-
argv: string[];
|
|
48
|
-
parsed: ParsedCommandInput;
|
|
49
|
-
stdin: CommandStdin;
|
|
50
|
-
env: Record<string, string>;
|
|
51
|
-
cwd: string;
|
|
52
|
-
io: CommandIO;
|
|
53
|
-
storage: CommandStorage;
|
|
54
|
-
}
|
|
55
|
-
interface CommandRunResult {
|
|
56
|
-
exitCode: number;
|
|
57
|
-
metadata?: unknown;
|
|
58
|
-
}
|
|
59
|
-
interface CommandStdin {
|
|
60
|
-
text: string;
|
|
61
|
-
}
|
|
62
|
-
/** A non-text content item a command emits to the model, peer to stdout text. */
|
|
63
|
-
type CommandAsset = {
|
|
64
|
-
type: 'image';
|
|
65
|
-
mediaType: string;
|
|
66
|
-
data: string;
|
|
67
|
-
};
|
|
68
|
-
interface CommandIO {
|
|
69
|
-
stdout(data: string | Uint8Array): Promise<void> | void;
|
|
70
|
-
stderr(data: string | Uint8Array): Promise<void> | void;
|
|
71
|
-
asset(asset: CommandAsset): Promise<void> | void;
|
|
72
|
-
}
|
|
73
|
-
interface CommandStorage {
|
|
74
|
-
readJson<T>(key: string): Promise<T | null>;
|
|
75
|
-
writeJson<T>(key: string, value: T): Promise<void>;
|
|
76
|
-
delete(key: string): Promise<void>;
|
|
77
|
-
list(prefix: string): Promise<string[]>;
|
|
78
|
-
}
|
|
79
|
-
interface CommandExecutionContext {
|
|
80
|
-
argv: string[];
|
|
81
|
-
stdin?: CommandStdin;
|
|
82
|
-
env: Record<string, string>;
|
|
83
|
-
cwd: string;
|
|
84
|
-
io: CommandIO;
|
|
85
|
-
storage: CommandStorage;
|
|
86
|
-
}
|
|
87
|
-
declare class CommandRegistry {
|
|
88
|
-
private readonly commands;
|
|
89
|
-
register(spec: CommandSpec): void;
|
|
90
|
-
get(name: string): CommandSpec | null;
|
|
91
|
-
list(): CommandSpec[];
|
|
92
|
-
renderPrompt(): string;
|
|
93
|
-
}
|
|
94
|
-
declare const COMMAND_PROMPT_DEFAULTS = "Unless a subcommand states otherwise: success prints raw text on stdout, failure writes an error message to stderr and exits non-zero.";
|
|
95
|
-
declare function parseCommandInput(spec: CommandSpec, argv: string[], stdin?: CommandStdin): ParsedCommandInput;
|
|
96
|
-
declare function runRegisteredCommand(spec: CommandSpec, ctx: CommandExecutionContext): Promise<CommandRunResult>;
|
|
97
|
-
declare function renderCommandPrompt(spec: CommandSpec, parentPath?: string): string;
|
|
98
|
-
//#endregion
|
|
99
|
-
//#region src/storage.d.ts
|
|
100
|
-
declare class AgentSessionCommandStorage implements CommandStorage {
|
|
101
|
-
private readonly store;
|
|
102
|
-
private readonly agentSessionPrefix;
|
|
103
|
-
constructor(store: HostStore, agentSessionId: string);
|
|
104
|
-
readJson<T>(key: string): Promise<T | null>;
|
|
105
|
-
writeJson<T>(key: string, value: T): Promise<void>;
|
|
106
|
-
delete(key: string): Promise<void>;
|
|
107
|
-
list(prefix: string): Promise<string[]>;
|
|
108
|
-
private key;
|
|
109
|
-
}
|
|
110
|
-
//#endregion
|
|
111
|
-
export { isCommandGroup as _, CommandIO as a, runRegisteredCommand as b, CommandOutputSpec as c, CommandRunResult as d, CommandSpec as f, ParsedCommandInput as g, CommandSubcommandSpec as h, CommandExecutionContext as i, CommandRegistry as l, CommandStorage as m, COMMAND_PROMPT_DEFAULTS as n, CommandInputSpec as o, CommandStdin as p, CommandAsset as r, CommandNode as s, AgentSessionCommandStorage as t, CommandRunContext as u, parseCommandInput as v, renderCommandPrompt as y };
|