argsbarg 1.4.3 → 2.0.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/.cursor/plans/cliprogram_capabilities_refactor_081e1737.plan.md +224 -0
- package/.private/scratch.md +1 -1
- package/CHANGELOG.md +39 -1
- package/README.md +29 -21
- package/docs/ai-skills.md +24 -52
- package/docs/install.md +84 -0
- package/docs/mcp.md +8 -8
- package/examples/mcp-test.ts +3 -3
- package/examples/minimal.ts +3 -3
- package/examples/nested.ts +3 -3
- package/examples/option-required.ts +3 -3
- package/index.d.ts +44 -50
- package/package.json +1 -1
- package/src/builtins/builtins.test.ts +101 -0
- package/src/builtins/completion-bash.ts +240 -0
- package/src/builtins/completion-fish.ts +73 -0
- package/src/builtins/completion-group.ts +50 -0
- package/src/builtins/completion-zsh.ts +244 -0
- package/src/builtins/dispatch.ts +138 -0
- package/src/builtins/export.ts +53 -0
- package/src/builtins/index.ts +10 -0
- package/src/builtins/install.ts +99 -0
- package/src/builtins/mcp.ts +13 -0
- package/src/builtins/presentation.ts +50 -0
- package/src/builtins/scopes.ts +46 -0
- package/src/builtins/shell-helpers.ts +24 -0
- package/src/capabilities.ts +32 -0
- package/src/completion.ts +10 -693
- package/src/context.ts +21 -6
- package/src/help.ts +21 -9
- package/src/index.test.ts +114 -118
- package/src/index.ts +2 -1
- package/src/install/binary.ts +82 -0
- package/src/install/compiled.ts +15 -0
- package/src/install/completions.ts +52 -0
- package/src/install/detect-installed.ts +67 -0
- package/src/install/index.ts +196 -0
- package/src/install/install.test.ts +124 -0
- package/src/install/mcp-config.ts +70 -0
- package/src/install/paths.ts +69 -0
- package/src/install/plan.ts +183 -0
- package/src/install/shell.ts +56 -0
- package/src/install/status.ts +63 -0
- package/src/install/uninstall.ts +111 -0
- package/src/invoke.ts +14 -5
- package/src/mcp/server.ts +3 -3
- package/src/mcp/tools.ts +17 -17
- package/src/mcp.ts +2 -2
- package/src/parse.ts +55 -27
- package/src/runtime.ts +47 -100
- package/src/schema.ts +10 -52
- package/src/skill/generate.ts +10 -10
- package/src/skill/install.ts +21 -19
- package/src/types.test.ts +40 -0
- package/src/types.ts +59 -49
- package/src/validate.ts +89 -83
- package/src/ai.ts +0 -7
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CliCapabilities } from "../capabilities.ts";
|
|
2
|
+
import { resolveCapabilities } from "../capabilities.ts";
|
|
3
|
+
import type { CliLeaf, CliNode, CliProgram, CliRouter } from "../types.ts";
|
|
4
|
+
import { isCliLeaf, isCliRouter } from "../types.ts";
|
|
5
|
+
import { cliBuiltinCompletionGroup } from "./completion-group.ts";
|
|
6
|
+
import { cliBuiltinInstallCommand } from "./install.ts";
|
|
7
|
+
import { cliBuiltinMcpCommand } from "./mcp.ts";
|
|
8
|
+
|
|
9
|
+
/** Built-in command nodes injected for help, schema, and completions. */
|
|
10
|
+
export function presentationBuiltins(program: CliProgram, caps: CliCapabilities): CliNode[] {
|
|
11
|
+
const builtins: CliNode[] = [cliBuiltinCompletionGroup(program.key)];
|
|
12
|
+
if (caps.install) {
|
|
13
|
+
builtins.push(cliBuiltinInstallCommand(program));
|
|
14
|
+
}
|
|
15
|
+
if (caps.mcp) {
|
|
16
|
+
builtins.push(cliBuiltinMcpCommand());
|
|
17
|
+
}
|
|
18
|
+
return builtins;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns a schema suitable for help display, including capability-built-in subtrees.
|
|
23
|
+
* Routing programs get builtins merged; leaf programs are wrapped as a tiny router.
|
|
24
|
+
*/
|
|
25
|
+
export function cliPresentationRoot(program: CliProgram): CliRouter {
|
|
26
|
+
const caps = resolveCapabilities(program);
|
|
27
|
+
const builtins = presentationBuiltins(program, caps);
|
|
28
|
+
|
|
29
|
+
if (isCliLeaf(program)) {
|
|
30
|
+
return {
|
|
31
|
+
key: program.key,
|
|
32
|
+
description: program.description,
|
|
33
|
+
options: program.options,
|
|
34
|
+
commands: builtins,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
key: program.key,
|
|
40
|
+
description: program.description,
|
|
41
|
+
notes: program.notes,
|
|
42
|
+
options: program.options,
|
|
43
|
+
fallbackCommand: program.fallbackCommand,
|
|
44
|
+
fallbackMode: program.fallbackMode,
|
|
45
|
+
commands: [...program.commands, ...builtins],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Presentation tree may include builtin leaf stubs. */
|
|
50
|
+
export type CliPresentationNode = CliNode | CliLeaf;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Shared completion scope walk used by bash, zsh, and fish emitters.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { type CliNode, type CliRouter, isCliLeaf, isCliRouter } from "../types.ts";
|
|
6
|
+
|
|
7
|
+
/** One tab-completion scope: child commands, options, and path key for the schema walk. */
|
|
8
|
+
export interface ScopeRec {
|
|
9
|
+
kids: CliNode[];
|
|
10
|
+
opts: import("../types.ts").CliOption[];
|
|
11
|
+
path: string;
|
|
12
|
+
wantsFiles: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hasPositionalArguments(cmd: CliNode): boolean {
|
|
16
|
+
return isCliLeaf(cmd) && (cmd.positionals ?? []).length > 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function walkScopes(cmdPath: string, cmd: CliNode, acc: ScopeRec[]): void {
|
|
20
|
+
const kids = isCliRouter(cmd) ? cmd.commands : [];
|
|
21
|
+
acc.push({
|
|
22
|
+
kids,
|
|
23
|
+
opts: cmd.options ?? [],
|
|
24
|
+
path: cmdPath,
|
|
25
|
+
wantsFiles: hasPositionalArguments(cmd),
|
|
26
|
+
});
|
|
27
|
+
for (const ch of kids) {
|
|
28
|
+
const nextPath = cmdPath === "" ? ch.key : cmdPath + "/" + ch.key;
|
|
29
|
+
walkScopes(nextPath, ch, acc);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Flattens the schema into a list of completion scopes (root + every command path). */
|
|
34
|
+
export function collectScopes(schema: CliRouter): ScopeRec[] {
|
|
35
|
+
const acc: ScopeRec[] = [];
|
|
36
|
+
acc.push({
|
|
37
|
+
kids: schema.commands ?? [],
|
|
38
|
+
opts: schema.options ?? [],
|
|
39
|
+
path: "",
|
|
40
|
+
wantsFiles: false,
|
|
41
|
+
});
|
|
42
|
+
for (const c of schema.commands ?? []) {
|
|
43
|
+
walkScopes(c.key, c, acc);
|
|
44
|
+
}
|
|
45
|
+
return acc;
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Produces a shell-safe identifier from the app or command name (alnum → `_`). */
|
|
2
|
+
export function identToken(s: string): string {
|
|
3
|
+
return s.replace(/[^a-zA-Z0-9]/g, "_");
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Escapes a string for use inside single quotes in generated shell scripts. */
|
|
7
|
+
export function escShellSingleQuoted(s: string): string {
|
|
8
|
+
return s.replace(/'/g, "'\\''");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Escapes a string for use inside fish single-quoted strings. */
|
|
12
|
+
export function escFishSingleQuoted(s: string): string {
|
|
13
|
+
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Sanitizes the app key for generated shell function names (non-alnum removed). */
|
|
17
|
+
export function mainName(schemaName: string): string {
|
|
18
|
+
return schemaName.replace(/[^a-zA-Z0-9]/g, "_");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const kHelpLong = "--help";
|
|
22
|
+
export const kHelpShort = "-h";
|
|
23
|
+
export const kSchemaLong = "--schema";
|
|
24
|
+
export const kSchemaDesc = "Print the full command tree as JSON.";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Internal capability resolver — decides which platform builtins are active for a program.
|
|
3
|
+
Not exported from the public package barrel.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { CliProgram } from "./types.ts";
|
|
7
|
+
import { isCompiledExecutable } from "./install/compiled.ts";
|
|
8
|
+
|
|
9
|
+
/** Platform builtins derived from program config and runtime. */
|
|
10
|
+
export interface CliCapabilities {
|
|
11
|
+
completion: true;
|
|
12
|
+
mcp: boolean;
|
|
13
|
+
install: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Resolves which capabilities are enabled for a program. */
|
|
17
|
+
export function resolveCapabilities(program: CliProgram): CliCapabilities {
|
|
18
|
+
return {
|
|
19
|
+
completion: true,
|
|
20
|
+
mcp: program.mcpServer !== undefined,
|
|
21
|
+
install: isCompiledExecutable() && program.install?.enabled !== false,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Reserved top-level command names for the given capabilities. */
|
|
26
|
+
export function reservedCommandNames(caps: CliCapabilities): string[] {
|
|
27
|
+
const names = ["completion", "install"];
|
|
28
|
+
if (caps.mcp) {
|
|
29
|
+
names.push("mcp");
|
|
30
|
+
}
|
|
31
|
+
return names;
|
|
32
|
+
}
|