@outfitter/cli 0.5.2 → 1.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/README.md +179 -60
- package/dist/actions.d.ts +5 -2
- package/dist/actions.js +2 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +8 -1
- package/dist/colors/index.js +1 -17
- package/dist/command.d.ts +3 -43
- package/dist/command.js +241 -13
- package/dist/envelope.d.ts +5 -0
- package/dist/envelope.js +160 -0
- package/dist/flags.d.ts +5 -189
- package/dist/flags.js +5 -1
- package/dist/hints.d.ts +34 -0
- package/dist/hints.js +26 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -17
- package/dist/input.d.ts +3 -124
- package/dist/input.js +14 -359
- package/dist/internal/envelope-helpers.d.ts +4 -0
- package/dist/internal/envelope-helpers.js +24 -0
- package/dist/internal/envelope-types.d.ts +3 -0
- package/dist/internal/flag-builders.d.ts +3 -0
- package/dist/internal/flag-builders.js +155 -0
- package/dist/internal/flag-types.d.ts +3 -0
- package/dist/internal/flag-types.js +13 -0
- package/dist/internal/hint-action-graph.d.ts +5 -0
- package/dist/internal/hint-action-graph.js +11 -0
- package/dist/internal/hint-command-tree.d.ts +5 -0
- package/dist/internal/hint-command-tree.js +9 -0
- package/dist/internal/hint-error-recovery.d.ts +2 -0
- package/dist/internal/hint-error-recovery.js +7 -0
- package/dist/internal/hint-types.d.ts +4 -0
- package/dist/internal/hint-types.js +1 -0
- package/dist/internal/input-helpers.d.ts +18 -0
- package/dist/internal/input-helpers.js +11 -0
- package/dist/internal/input-normalization.d.ts +3 -0
- package/dist/internal/input-normalization.js +9 -0
- package/dist/internal/input-parsers.d.ts +3 -0
- package/dist/internal/input-parsers.js +19 -0
- package/dist/internal/input-security.d.ts +22 -0
- package/dist/internal/input-security.js +11 -0
- package/dist/internal/output-formatting.d.ts +3 -0
- package/dist/internal/output-formatting.js +21 -0
- package/dist/internal/presets.d.ts +3 -0
- package/dist/{shared/@outfitter/cli-pdb7znbq.js → internal/presets.js} +49 -223
- package/dist/internal/schema-commands.d.ts +3 -0
- package/dist/{shared/@outfitter/cli-0cjts94k.js → internal/schema-commands.js} +12 -100
- package/dist/internal/schema-formatting.d.ts +2 -0
- package/dist/internal/schema-formatting.js +7 -0
- package/dist/internal/schema-types.d.ts +2 -0
- package/dist/internal/schema-types.js +1 -0
- package/dist/output.d.ts +4 -3
- package/dist/output.js +10 -2
- package/dist/pagination.d.ts +1 -1
- package/dist/query.d.ts +84 -2
- package/dist/query.js +8 -45
- package/dist/schema-input.d.ts +80 -0
- package/dist/schema-input.js +15 -0
- package/dist/schema.d.ts +4 -1
- package/dist/schema.js +1 -1
- package/dist/shared/@outfitter/cli-10wxfc78.d.ts +45 -0
- package/dist/shared/@outfitter/cli-16wg5mka.d.ts +71 -0
- package/dist/shared/@outfitter/cli-1q5redaj.js +267 -0
- package/dist/shared/@outfitter/cli-2dfxs239.js +98 -0
- package/dist/shared/@outfitter/cli-30mt7c5w.d.ts +112 -0
- package/dist/shared/@outfitter/cli-3jta1h1h.js +134 -0
- package/dist/shared/@outfitter/cli-4h85mpth.js +76 -0
- package/dist/shared/@outfitter/cli-6shkwxdc.js +28 -0
- package/dist/shared/@outfitter/cli-89335n9a.js +16 -0
- package/dist/shared/@outfitter/cli-8999qjdd.js +3 -0
- package/dist/shared/@outfitter/cli-8cfxdady.js +60 -0
- package/dist/shared/@outfitter/cli-bcajqy33.d.ts +25 -0
- package/dist/shared/@outfitter/cli-c09332vm.d.ts +39 -0
- package/dist/shared/@outfitter/cli-cgha038c.d.ts +3 -0
- package/dist/shared/@outfitter/{cli-zahqsaby.js → cli-d40m2x1d.js} +19 -3
- package/dist/shared/@outfitter/{cli-7wp5nj0s.js → cli-dg0cz7rw.js} +39 -81
- package/dist/shared/@outfitter/cli-dv8kk4jw.d.ts +24 -0
- package/dist/shared/@outfitter/cli-g43887b7.js +20 -0
- package/dist/shared/@outfitter/cli-gqtkhgw4.js +52 -0
- package/dist/shared/@outfitter/cli-h4ejpmjs.d.ts +104 -0
- package/dist/shared/@outfitter/cli-htzez8v2.js +70 -0
- package/dist/shared/@outfitter/cli-hvg2m5gf.js +79 -0
- package/dist/shared/@outfitter/cli-n54zs151.d.ts +78 -0
- package/dist/shared/@outfitter/cli-nbpgw7z7.d.ts +15 -0
- package/dist/shared/@outfitter/cli-nkt399zf.d.ts +94 -0
- package/dist/shared/@outfitter/cli-pmd04gtv.d.ts +60 -0
- package/dist/shared/@outfitter/{cli-xy3gs50c.d.ts → cli-q6csxmeh.d.ts} +19 -12
- package/dist/shared/@outfitter/cli-qcskd96y.d.ts +11 -0
- package/dist/shared/@outfitter/cli-ry7btmy4.js +118 -0
- package/dist/shared/@outfitter/cli-sy99pjyj.js +32 -0
- package/dist/shared/@outfitter/cli-tm2fzngs.d.ts +23 -0
- package/dist/shared/@outfitter/cli-vvvhjwks.js +106 -0
- package/dist/shared/@outfitter/cli-wjv7g1aq.d.ts +16 -0
- package/dist/shared/@outfitter/{cli-98aa9104.d.ts → cli-x6qr7bnd.d.ts} +338 -16
- package/dist/shared/@outfitter/cli-xde45xcc.d.ts +53 -0
- package/dist/shared/@outfitter/cli-xw8ys1je.d.ts +123 -0
- package/dist/shared/@outfitter/cli-yfewnyc2.d.ts +43 -0
- package/dist/shared/@outfitter/cli-zkzj0q4q.js +99 -0
- package/dist/shared/@outfitter/cli-zv3ah6f0.js +3 -0
- package/dist/streaming.d.ts +47 -0
- package/dist/streaming.js +13 -0
- package/dist/terminal/index.js +1 -19
- package/dist/truncation.d.ts +104 -0
- package/dist/truncation.js +111 -0
- package/dist/types.d.ts +2 -2
- package/dist/types.js +0 -5
- package/dist/verbs.d.ts +1 -1
- package/package.json +66 -36
- package/dist/shared/@outfitter/cli-n1k0d23k.d.ts +0 -33
- /package/dist/{shared/@outfitter/cli-zw75pdk8.js → internal/envelope-types.js} +0 -0
package/dist/flags.js
CHANGED
|
@@ -4,12 +4,14 @@ import {
|
|
|
4
4
|
colorPreset,
|
|
5
5
|
composePresets,
|
|
6
6
|
createPreset,
|
|
7
|
+
createSchemaPreset,
|
|
7
8
|
cwdPreset,
|
|
8
9
|
dryRunPreset,
|
|
9
10
|
enumFlagPreset,
|
|
10
11
|
executionPreset,
|
|
11
12
|
forcePreset,
|
|
12
13
|
interactionPreset,
|
|
14
|
+
isSchemaPreset,
|
|
13
15
|
numberFlagPreset,
|
|
14
16
|
paginationPreset,
|
|
15
17
|
projectionPreset,
|
|
@@ -17,7 +19,7 @@ import {
|
|
|
17
19
|
stringListFlagPreset,
|
|
18
20
|
timeWindowPreset,
|
|
19
21
|
verbosePreset
|
|
20
|
-
} from "./shared/@outfitter/cli-
|
|
22
|
+
} from "./shared/@outfitter/cli-8999qjdd.js";
|
|
21
23
|
export {
|
|
22
24
|
verbosePreset,
|
|
23
25
|
timeWindowPreset,
|
|
@@ -26,12 +28,14 @@ export {
|
|
|
26
28
|
projectionPreset,
|
|
27
29
|
paginationPreset,
|
|
28
30
|
numberFlagPreset,
|
|
31
|
+
isSchemaPreset,
|
|
29
32
|
interactionPreset,
|
|
30
33
|
forcePreset,
|
|
31
34
|
executionPreset,
|
|
32
35
|
enumFlagPreset,
|
|
33
36
|
dryRunPreset,
|
|
34
37
|
cwdPreset,
|
|
38
|
+
createSchemaPreset,
|
|
35
39
|
createPreset,
|
|
36
40
|
composePresets,
|
|
37
41
|
colorPreset,
|
package/dist/hints.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { buildCommandTree, commandTreeHints } from "./shared/@outfitter/cli-yfewnyc2.js";
|
|
2
|
+
import { buildActionGraph, graphErrorHints, graphSuccessHints } from "./shared/@outfitter/cli-pmd04gtv.js";
|
|
3
|
+
import { ActionGraph, ActionGraphEdge, CommandTree, CommandTreeNode, CommandTreeOption } from "./shared/@outfitter/cli-16wg5mka.js";
|
|
4
|
+
import { errorRecoveryHints } from "./shared/@outfitter/cli-tm2fzngs.js";
|
|
5
|
+
import "./shared/@outfitter/cli-xde45xcc.js";
|
|
6
|
+
import "./shared/@outfitter/cli-x6qr7bnd.js";
|
|
7
|
+
/**
|
|
8
|
+
* Populate hint params from a Zod input schema (Tier 3).
|
|
9
|
+
*
|
|
10
|
+
* Introspects the schema fields and produces a params record where each
|
|
11
|
+
* key is a field name and each value is the field's description (or type
|
|
12
|
+
* name as fallback).
|
|
13
|
+
*
|
|
14
|
+
* Enables agents to understand the expected parameter shapes for a command
|
|
15
|
+
* without needing to parse the schema definition themselves.
|
|
16
|
+
*
|
|
17
|
+
* @param schema - A Zod object schema (or ZodObjectLike)
|
|
18
|
+
* @returns A params record mapping field names to their descriptions/types
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const schema = z.object({
|
|
23
|
+
* env: z.string().describe("Target environment"),
|
|
24
|
+
* force: z.boolean().describe("Force deployment"),
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* const params = schemaHintParams(schema);
|
|
28
|
+
* // { env: "Target environment", force: "Force deployment" }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
declare function schemaHintParams(schema: {
|
|
32
|
+
shape: Record<string, unknown>;
|
|
33
|
+
}): Record<string, unknown>;
|
|
34
|
+
export { schemaHintParams, graphSuccessHints, graphErrorHints, errorRecoveryHints, commandTreeHints, buildCommandTree, buildActionGraph, CommandTreeOption, CommandTreeNode, CommandTree, ActionGraphEdge, ActionGraph };
|
package/dist/hints.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
schemaHintParams
|
|
4
|
+
} from "./shared/@outfitter/cli-89335n9a.js";
|
|
5
|
+
import {
|
|
6
|
+
buildCommandTree,
|
|
7
|
+
commandTreeHints
|
|
8
|
+
} from "./shared/@outfitter/cli-htzez8v2.js";
|
|
9
|
+
import {
|
|
10
|
+
buildActionGraph,
|
|
11
|
+
graphErrorHints,
|
|
12
|
+
graphSuccessHints
|
|
13
|
+
} from "./shared/@outfitter/cli-hvg2m5gf.js";
|
|
14
|
+
import {
|
|
15
|
+
errorRecoveryHints
|
|
16
|
+
} from "./shared/@outfitter/cli-2dfxs239.js";
|
|
17
|
+
import"./shared/@outfitter/cli-3jta1h1h.js";
|
|
18
|
+
export {
|
|
19
|
+
schemaHintParams,
|
|
20
|
+
graphSuccessHints,
|
|
21
|
+
graphErrorHints,
|
|
22
|
+
errorRecoveryHints,
|
|
23
|
+
commandTreeHints,
|
|
24
|
+
buildCommandTree,
|
|
25
|
+
buildActionGraph
|
|
26
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "./shared/@outfitter/cli-qz47jk6d.js";
|
|
2
2
|
import { ANSI, Theme, Tokens, createTheme } from "./shared/@outfitter/cli-j2x88att.js";
|
|
3
|
-
import { exitWithError, output } from "./shared/@outfitter/cli-
|
|
4
|
-
import
|
|
3
|
+
import { exitWithError, output } from "./shared/@outfitter/cli-q6csxmeh.js";
|
|
4
|
+
import "./shared/@outfitter/cli-10wxfc78.js";
|
|
5
|
+
import { OutputMode } from "./shared/@outfitter/cli-x6qr7bnd.js";
|
|
5
6
|
export { output, exitWithError, createTheme, Tokens, Theme, OutputMode, ANSI };
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ANSI,
|
|
5
|
-
createTheme
|
|
6
|
-
} from "./shared/@outfitter/cli-rk9zagkm.js";
|
|
7
|
-
import"./shared/@outfitter/cli-jbj78ac5.js";
|
|
8
|
-
import {
|
|
9
|
-
exitWithError,
|
|
10
|
-
output
|
|
11
|
-
} from "./shared/@outfitter/cli-7wp5nj0s.js";
|
|
12
|
-
export {
|
|
13
|
-
output,
|
|
14
|
-
exitWithError,
|
|
15
|
-
createTheme,
|
|
16
|
-
ANSI
|
|
17
|
-
};
|
|
1
|
+
export { ANSI, createTheme } from "./colors/index.js";
|
|
2
|
+
export { exitWithError, output } from "./output.js";
|
package/dist/input.d.ts
CHANGED
|
@@ -1,130 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { expandFileArg, parseFilter, parseGlob, parseKeyValue, parseRange, parseSortSpec } from "./shared/@outfitter/cli-h4ejpmjs.js";
|
|
2
|
+
import { collectIds } from "./shared/@outfitter/cli-bcajqy33.js";
|
|
3
|
+
import { NormalizeIdOptions } from "./shared/@outfitter/cli-x6qr7bnd.js";
|
|
2
4
|
import { ValidationError } from "@outfitter/contracts";
|
|
3
5
|
import { Result } from "better-result";
|
|
4
6
|
/**
|
|
5
|
-
* Collect IDs from various input formats.
|
|
6
|
-
*
|
|
7
|
-
* Handles space-separated, comma-separated, repeated flags, @file, and stdin.
|
|
8
|
-
*
|
|
9
|
-
* @param input - Raw input from CLI arguments
|
|
10
|
-
* @param options - Collection options
|
|
11
|
-
* @returns Array of collected IDs
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* // All these produce the same result:
|
|
16
|
-
* // wm show id1 id2 id3
|
|
17
|
-
* // wm show id1,id2,id3
|
|
18
|
-
* // wm show --ids id1 --ids id2
|
|
19
|
-
* // wm show @ids.txt
|
|
20
|
-
* const ids = await collectIds(args.ids, {
|
|
21
|
-
* allowFile: true,
|
|
22
|
-
* allowStdin: true,
|
|
23
|
-
* });
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
declare function collectIds(input: string | readonly string[], options?: CollectIdsOptions): Promise<string[]>;
|
|
27
|
-
/**
|
|
28
|
-
* Expand @file references to file contents.
|
|
29
|
-
*
|
|
30
|
-
* If the input starts with @, reads the file and returns its contents.
|
|
31
|
-
* Otherwise, returns the input unchanged.
|
|
32
|
-
*
|
|
33
|
-
* @param input - Raw input that may be a @file reference
|
|
34
|
-
* @param options - Expansion options
|
|
35
|
-
* @returns File contents or original input
|
|
36
|
-
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
|
-
* // wm create @template.md
|
|
40
|
-
* const content = await expandFileArg(args.content);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare function expandFileArg(input: string, options?: ExpandFileOptions): Promise<string>;
|
|
44
|
-
/**
|
|
45
|
-
* Parse and expand glob patterns.
|
|
46
|
-
*
|
|
47
|
-
* Uses Bun.Glob with workspace constraints.
|
|
48
|
-
*
|
|
49
|
-
* @param pattern - Glob pattern to expand
|
|
50
|
-
* @param options - Glob options
|
|
51
|
-
* @returns Array of matched file paths
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* // wm index "src/**\/*.ts"
|
|
56
|
-
* const files = await parseGlob(args.pattern, {
|
|
57
|
-
* cwd: workspaceRoot,
|
|
58
|
-
* ignore: ["node_modules/**"],
|
|
59
|
-
* });
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
declare function parseGlob(pattern: string, options?: ParseGlobOptions): Promise<string[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Parse key=value pairs from CLI input.
|
|
65
|
-
*
|
|
66
|
-
* @param input - Raw input containing key=value pairs
|
|
67
|
-
* @returns Array of parsed key-value pairs
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* // --set key=value --set key2=value2
|
|
72
|
-
* // --set key=value,key2=value2
|
|
73
|
-
* const pairs = parseKeyValue(args.set);
|
|
74
|
-
* // => [{ key: "key", value: "value" }, { key: "key2", value: "value2" }]
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
declare function parseKeyValue(input: string | readonly string[]): Result<KeyValuePair[], InstanceType<typeof ValidationError>>;
|
|
78
|
-
/**
|
|
79
|
-
* Parse range inputs (numeric or date).
|
|
80
|
-
*
|
|
81
|
-
* @param input - Range string (e.g., "1-10" or "2024-01-01..2024-12-31")
|
|
82
|
-
* @param type - Type of range to parse
|
|
83
|
-
* @returns Parsed range
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ```typescript
|
|
87
|
-
* parseRange("1-10", "number");
|
|
88
|
-
* // => Result<{ type: "number", min: 1, max: 10 }, ValidationError>
|
|
89
|
-
*
|
|
90
|
-
* parseRange("2024-01-01..2024-12-31", "date");
|
|
91
|
-
* // => Result<{ type: "date", start: Date, end: Date }, ValidationError>
|
|
92
|
-
* ```
|
|
93
|
-
*/
|
|
94
|
-
declare function parseRange(input: string, type: "number" | "date"): Result<Range, InstanceType<typeof ValidationError>>;
|
|
95
|
-
/**
|
|
96
|
-
* Parse filter expressions from CLI input.
|
|
97
|
-
*
|
|
98
|
-
* @param input - Filter string (e.g., "status:active,priority:high")
|
|
99
|
-
* @returns Array of parsed filter expressions
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* parseFilter("status:active,priority:high");
|
|
104
|
-
* // => Result<[
|
|
105
|
-
* // { field: "status", value: "active" },
|
|
106
|
-
* // { field: "priority", value: "high" }
|
|
107
|
-
* // ], ValidationError>
|
|
108
|
-
* ```
|
|
109
|
-
*/
|
|
110
|
-
declare function parseFilter(input: string): Result<FilterExpression[], InstanceType<typeof ValidationError>>;
|
|
111
|
-
/**
|
|
112
|
-
* Parse sort specification from CLI input.
|
|
113
|
-
*
|
|
114
|
-
* @param input - Sort string (e.g., "modified:desc,title:asc")
|
|
115
|
-
* @returns Array of parsed sort criteria
|
|
116
|
-
*
|
|
117
|
-
* @example
|
|
118
|
-
* ```typescript
|
|
119
|
-
* parseSortSpec("modified:desc,title:asc");
|
|
120
|
-
* // => Result<[
|
|
121
|
-
* // { field: "modified", direction: "desc" },
|
|
122
|
-
* // { field: "title", direction: "asc" }
|
|
123
|
-
* // ], ValidationError>
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
declare function parseSortSpec(input: string): Result<SortCriteria[], InstanceType<typeof ValidationError>>;
|
|
127
|
-
/**
|
|
128
7
|
* Normalize an identifier (trim, lowercase where appropriate).
|
|
129
8
|
*
|
|
130
9
|
* @param input - Raw identifier input
|
package/dist/input.js
CHANGED
|
@@ -1,366 +1,21 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
import {
|
|
3
|
+
expandFileArg,
|
|
4
|
+
parseFilter,
|
|
5
|
+
parseGlob,
|
|
6
|
+
parseKeyValue,
|
|
7
|
+
parseRange,
|
|
8
|
+
parseSortSpec
|
|
9
|
+
} from "./shared/@outfitter/cli-1q5redaj.js";
|
|
10
|
+
import {
|
|
11
|
+
collectIds
|
|
12
|
+
} from "./shared/@outfitter/cli-gqtkhgw4.js";
|
|
13
|
+
import"./shared/@outfitter/cli-sy99pjyj.js";
|
|
14
|
+
import"./shared/@outfitter/cli-6shkwxdc.js";
|
|
15
|
+
|
|
2
16
|
// packages/cli/src/input.ts
|
|
3
|
-
import path from "path";
|
|
4
17
|
import { ValidationError } from "@outfitter/contracts";
|
|
5
18
|
import { Err, Ok } from "better-result";
|
|
6
|
-
function isSecurePath(filePath, allowAbsolute = false) {
|
|
7
|
-
if (filePath.includes("\x00")) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
if (filePath.includes("..")) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const normalized = path.normalize(filePath);
|
|
14
|
-
if (!allowAbsolute && path.isAbsolute(normalized)) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
function isSecureGlobPattern(pattern) {
|
|
20
|
-
if (pattern.startsWith("..")) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (pattern.includes("/../")) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
function isWithinWorkspace(resolvedPath, workspaceRoot) {
|
|
29
|
-
const normalizedPath = path.normalize(resolvedPath);
|
|
30
|
-
const normalizedRoot = path.normalize(workspaceRoot);
|
|
31
|
-
return normalizedPath === normalizedRoot || normalizedPath.startsWith(normalizedRoot + path.sep);
|
|
32
|
-
}
|
|
33
|
-
async function readStdin() {
|
|
34
|
-
const chunks = [];
|
|
35
|
-
for await (const chunk of process.stdin) {
|
|
36
|
-
if (typeof chunk === "string") {
|
|
37
|
-
chunks.push(chunk);
|
|
38
|
-
} else if (Buffer.isBuffer(chunk)) {
|
|
39
|
-
chunks.push(chunk.toString("utf-8"));
|
|
40
|
-
} else if (chunk instanceof Uint8Array) {
|
|
41
|
-
chunks.push(Buffer.from(chunk).toString("utf-8"));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return chunks.join("");
|
|
45
|
-
}
|
|
46
|
-
function splitIds(input) {
|
|
47
|
-
return input.split(",").flatMap((part) => part.trim().split(/\s+/)).map((id) => id.trim()).filter(Boolean);
|
|
48
|
-
}
|
|
49
|
-
async function isDirectory(path2) {
|
|
50
|
-
try {
|
|
51
|
-
const result = await Bun.$`test -d ${path2}`.quiet();
|
|
52
|
-
return result.exitCode === 0;
|
|
53
|
-
} catch {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
async function isFile(path2) {
|
|
58
|
-
try {
|
|
59
|
-
const result = await Bun.$`test -f ${path2}`.quiet();
|
|
60
|
-
return result.exitCode === 0;
|
|
61
|
-
} catch {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
async function collectIds(input, options) {
|
|
66
|
-
const { allowFile = true, allowStdin = true } = options ?? {};
|
|
67
|
-
const ids = [];
|
|
68
|
-
const inputs = Array.isArray(input) ? input : [input];
|
|
69
|
-
for (const item of inputs) {
|
|
70
|
-
if (!item)
|
|
71
|
-
continue;
|
|
72
|
-
if (item.startsWith("@")) {
|
|
73
|
-
const filePath = item.slice(1);
|
|
74
|
-
if (filePath === "-") {
|
|
75
|
-
if (!allowStdin) {
|
|
76
|
-
throw new Error("Reading from stdin is not allowed");
|
|
77
|
-
}
|
|
78
|
-
const stdinContent = await readStdin();
|
|
79
|
-
const stdinIds = stdinContent.split(`
|
|
80
|
-
`).map((line) => line.trim()).filter(Boolean);
|
|
81
|
-
ids.push(...stdinIds);
|
|
82
|
-
} else {
|
|
83
|
-
if (!allowFile) {
|
|
84
|
-
throw new Error("File references are not allowed");
|
|
85
|
-
}
|
|
86
|
-
if (!isSecurePath(filePath, true)) {
|
|
87
|
-
throw new Error(`Security error: path traversal not allowed: ${filePath}`);
|
|
88
|
-
}
|
|
89
|
-
const file = Bun.file(filePath);
|
|
90
|
-
const exists = await file.exists();
|
|
91
|
-
if (!exists) {
|
|
92
|
-
throw new Error(`File not found: ${filePath}`);
|
|
93
|
-
}
|
|
94
|
-
const content = await file.text();
|
|
95
|
-
const fileIds = content.split(`
|
|
96
|
-
`).map((line) => line.trim()).filter(Boolean);
|
|
97
|
-
ids.push(...fileIds);
|
|
98
|
-
}
|
|
99
|
-
} else {
|
|
100
|
-
ids.push(...splitIds(item));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return [...new Set(ids)];
|
|
104
|
-
}
|
|
105
|
-
async function expandFileArg(input, options) {
|
|
106
|
-
const {
|
|
107
|
-
encoding: _encoding = "utf-8",
|
|
108
|
-
maxSize,
|
|
109
|
-
trim = false
|
|
110
|
-
} = options ?? {};
|
|
111
|
-
if (!input.startsWith("@")) {
|
|
112
|
-
return input;
|
|
113
|
-
}
|
|
114
|
-
const filePath = input.slice(1);
|
|
115
|
-
if (filePath === "-") {
|
|
116
|
-
let content2 = await readStdin();
|
|
117
|
-
if (trim) {
|
|
118
|
-
content2 = content2.trim();
|
|
119
|
-
}
|
|
120
|
-
return content2;
|
|
121
|
-
}
|
|
122
|
-
if (!isSecurePath(filePath, true)) {
|
|
123
|
-
throw new Error(`Security error: path traversal not allowed: ${filePath}`);
|
|
124
|
-
}
|
|
125
|
-
const file = Bun.file(filePath);
|
|
126
|
-
const exists = await file.exists();
|
|
127
|
-
if (!exists) {
|
|
128
|
-
throw new Error(`File not found: ${filePath}`);
|
|
129
|
-
}
|
|
130
|
-
if (maxSize !== undefined) {
|
|
131
|
-
const size = file.size;
|
|
132
|
-
if (size > maxSize) {
|
|
133
|
-
throw new Error(`File exceeds maximum size of ${maxSize} bytes`);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
let content = await file.text();
|
|
137
|
-
if (trim) {
|
|
138
|
-
content = content.trim();
|
|
139
|
-
}
|
|
140
|
-
return content;
|
|
141
|
-
}
|
|
142
|
-
async function parseGlob(pattern, options) {
|
|
143
|
-
const {
|
|
144
|
-
cwd = process.cwd(),
|
|
145
|
-
ignore = [],
|
|
146
|
-
onlyFiles = false,
|
|
147
|
-
onlyDirectories = false,
|
|
148
|
-
followSymlinks = false
|
|
149
|
-
} = options ?? {};
|
|
150
|
-
if (!isSecureGlobPattern(pattern)) {
|
|
151
|
-
throw new Error(`Security error: glob pattern may escape workspace: ${pattern}`);
|
|
152
|
-
}
|
|
153
|
-
const resolvedCwd = path.resolve(cwd);
|
|
154
|
-
const glob = new Bun.Glob(pattern);
|
|
155
|
-
const matches = [];
|
|
156
|
-
const scanOptions = {
|
|
157
|
-
cwd,
|
|
158
|
-
followSymlinks,
|
|
159
|
-
onlyFiles: onlyFiles === true
|
|
160
|
-
};
|
|
161
|
-
for await (const match of glob.scan(scanOptions)) {
|
|
162
|
-
const fullPath = path.resolve(cwd, match);
|
|
163
|
-
if (!isWithinWorkspace(fullPath, resolvedCwd)) {
|
|
164
|
-
continue;
|
|
165
|
-
}
|
|
166
|
-
let shouldIgnore = false;
|
|
167
|
-
for (const ignorePattern of ignore) {
|
|
168
|
-
const ignoreGlob = new Bun.Glob(ignorePattern);
|
|
169
|
-
if (ignoreGlob.match(match)) {
|
|
170
|
-
shouldIgnore = true;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
if (shouldIgnore)
|
|
175
|
-
continue;
|
|
176
|
-
if (onlyDirectories) {
|
|
177
|
-
const isDir = await isDirectory(fullPath);
|
|
178
|
-
if (!isDir)
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
if (onlyFiles) {
|
|
182
|
-
const isF = await isFile(fullPath);
|
|
183
|
-
if (!isF)
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
matches.push(match);
|
|
187
|
-
}
|
|
188
|
-
return matches;
|
|
189
|
-
}
|
|
190
|
-
function parseKeyValue(input) {
|
|
191
|
-
const pairs = [];
|
|
192
|
-
const inputs = Array.isArray(input) ? input : [input];
|
|
193
|
-
for (const item of inputs) {
|
|
194
|
-
if (!item)
|
|
195
|
-
continue;
|
|
196
|
-
const parts = item.split(",");
|
|
197
|
-
for (const part of parts) {
|
|
198
|
-
const trimmed = part.trim();
|
|
199
|
-
if (!trimmed)
|
|
200
|
-
continue;
|
|
201
|
-
const eqIndex = trimmed.indexOf("=");
|
|
202
|
-
if (eqIndex === -1) {
|
|
203
|
-
return new Err(new ValidationError({
|
|
204
|
-
message: `Missing '=' in key-value pair: ${trimmed}`
|
|
205
|
-
}));
|
|
206
|
-
}
|
|
207
|
-
const key = trimmed.slice(0, eqIndex).trim();
|
|
208
|
-
const value = trimmed.slice(eqIndex + 1);
|
|
209
|
-
if (!key) {
|
|
210
|
-
return new Err(new ValidationError({ message: "Empty key in key-value pair" }));
|
|
211
|
-
}
|
|
212
|
-
pairs.push({ key, value });
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return new Ok(pairs);
|
|
216
|
-
}
|
|
217
|
-
function parseRange(input, type) {
|
|
218
|
-
const trimmed = input.trim();
|
|
219
|
-
if (type === "date") {
|
|
220
|
-
const parts = trimmed.split("..");
|
|
221
|
-
if (parts.length === 1) {
|
|
222
|
-
const dateStr = parts[0];
|
|
223
|
-
if (dateStr === undefined) {
|
|
224
|
-
return new Err(new ValidationError({ message: "Empty date input" }));
|
|
225
|
-
}
|
|
226
|
-
const date = new Date(dateStr.trim());
|
|
227
|
-
if (Number.isNaN(date.getTime())) {
|
|
228
|
-
return new Err(new ValidationError({ message: `Invalid date format: ${dateStr}` }));
|
|
229
|
-
}
|
|
230
|
-
return new Ok({ type: "date", start: date, end: date });
|
|
231
|
-
}
|
|
232
|
-
if (parts.length === 2) {
|
|
233
|
-
const startStr = parts[0];
|
|
234
|
-
const endStr = parts[1];
|
|
235
|
-
if (startStr === undefined || endStr === undefined) {
|
|
236
|
-
return new Err(new ValidationError({ message: "Invalid date range format" }));
|
|
237
|
-
}
|
|
238
|
-
const start = new Date(startStr.trim());
|
|
239
|
-
const end = new Date(endStr.trim());
|
|
240
|
-
if (Number.isNaN(start.getTime())) {
|
|
241
|
-
return new Err(new ValidationError({ message: `Invalid date format: ${startStr}` }));
|
|
242
|
-
}
|
|
243
|
-
if (Number.isNaN(end.getTime())) {
|
|
244
|
-
return new Err(new ValidationError({ message: `Invalid date format: ${endStr}` }));
|
|
245
|
-
}
|
|
246
|
-
if (start.getTime() > end.getTime()) {
|
|
247
|
-
return new Err(new ValidationError({
|
|
248
|
-
message: "Start date must be before or equal to end date"
|
|
249
|
-
}));
|
|
250
|
-
}
|
|
251
|
-
return new Ok({ type: "date", start, end });
|
|
252
|
-
}
|
|
253
|
-
return new Err(new ValidationError({ message: `Invalid date range format: ${input}` }));
|
|
254
|
-
}
|
|
255
|
-
const singleNum = Number(trimmed);
|
|
256
|
-
if (!(Number.isNaN(singleNum) || trimmed.includes("-", trimmed.startsWith("-") ? 1 : 0))) {
|
|
257
|
-
return new Ok({ type: "number", min: singleNum, max: singleNum });
|
|
258
|
-
}
|
|
259
|
-
let separatorIndex = -1;
|
|
260
|
-
for (let i = 1;i < trimmed.length; i++) {
|
|
261
|
-
const char = trimmed[i];
|
|
262
|
-
const prevChar = trimmed[i - 1];
|
|
263
|
-
if (char === "-" && prevChar !== undefined && /[\d\s]/.test(prevChar)) {
|
|
264
|
-
separatorIndex = i;
|
|
265
|
-
break;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (separatorIndex === -1) {
|
|
269
|
-
return new Err(new ValidationError({ message: `Invalid numeric range format: ${input}` }));
|
|
270
|
-
}
|
|
271
|
-
const minStr = trimmed.slice(0, separatorIndex).trim();
|
|
272
|
-
const maxStr = trimmed.slice(separatorIndex + 1).trim();
|
|
273
|
-
const min = Number(minStr);
|
|
274
|
-
const max = Number(maxStr);
|
|
275
|
-
if (Number.isNaN(min)) {
|
|
276
|
-
return new Err(new ValidationError({ message: `Invalid number: ${minStr}` }));
|
|
277
|
-
}
|
|
278
|
-
if (Number.isNaN(max)) {
|
|
279
|
-
return new Err(new ValidationError({ message: `Invalid number: ${maxStr}` }));
|
|
280
|
-
}
|
|
281
|
-
if (min > max) {
|
|
282
|
-
return new Err(new ValidationError({ message: "Min must be less than or equal to max" }));
|
|
283
|
-
}
|
|
284
|
-
return new Ok({ type: "number", min, max });
|
|
285
|
-
}
|
|
286
|
-
function parseFilter(input) {
|
|
287
|
-
const trimmed = input.trim();
|
|
288
|
-
if (!trimmed) {
|
|
289
|
-
return new Ok([]);
|
|
290
|
-
}
|
|
291
|
-
const filters = [];
|
|
292
|
-
const parts = trimmed.split(",");
|
|
293
|
-
for (const part of parts) {
|
|
294
|
-
let partTrimmed = part.trim();
|
|
295
|
-
if (!partTrimmed)
|
|
296
|
-
continue;
|
|
297
|
-
let isNegated = false;
|
|
298
|
-
if (partTrimmed.startsWith("!")) {
|
|
299
|
-
isNegated = true;
|
|
300
|
-
partTrimmed = partTrimmed.slice(1).trim();
|
|
301
|
-
}
|
|
302
|
-
const colonIndex = partTrimmed.indexOf(":");
|
|
303
|
-
if (colonIndex === -1) {
|
|
304
|
-
return new Err(new ValidationError({
|
|
305
|
-
message: `Missing ':' in filter expression: ${part.trim()}`
|
|
306
|
-
}));
|
|
307
|
-
}
|
|
308
|
-
const field = partTrimmed.slice(0, colonIndex).trim();
|
|
309
|
-
let value = partTrimmed.slice(colonIndex + 1).trim();
|
|
310
|
-
let operator;
|
|
311
|
-
if (isNegated) {
|
|
312
|
-
operator = "ne";
|
|
313
|
-
} else if (value.startsWith(">=")) {
|
|
314
|
-
operator = "gte";
|
|
315
|
-
value = value.slice(2).trim();
|
|
316
|
-
} else if (value.startsWith("<=")) {
|
|
317
|
-
operator = "lte";
|
|
318
|
-
value = value.slice(2).trim();
|
|
319
|
-
} else if (value.startsWith(">")) {
|
|
320
|
-
operator = "gt";
|
|
321
|
-
value = value.slice(1).trim();
|
|
322
|
-
} else if (value.startsWith("<")) {
|
|
323
|
-
operator = "lt";
|
|
324
|
-
value = value.slice(1).trim();
|
|
325
|
-
} else if (value.startsWith("~")) {
|
|
326
|
-
operator = "contains";
|
|
327
|
-
value = value.slice(1).trim();
|
|
328
|
-
}
|
|
329
|
-
const filter = { field, value };
|
|
330
|
-
if (operator) {
|
|
331
|
-
filter.operator = operator;
|
|
332
|
-
}
|
|
333
|
-
filters.push(filter);
|
|
334
|
-
}
|
|
335
|
-
return new Ok(filters);
|
|
336
|
-
}
|
|
337
|
-
function parseSortSpec(input) {
|
|
338
|
-
const trimmed = input.trim();
|
|
339
|
-
if (!trimmed) {
|
|
340
|
-
return new Ok([]);
|
|
341
|
-
}
|
|
342
|
-
const criteria = [];
|
|
343
|
-
const parts = trimmed.split(",");
|
|
344
|
-
for (const part of parts) {
|
|
345
|
-
const partTrimmed = part.trim();
|
|
346
|
-
if (!partTrimmed)
|
|
347
|
-
continue;
|
|
348
|
-
const colonIndex = partTrimmed.indexOf(":");
|
|
349
|
-
if (colonIndex === -1) {
|
|
350
|
-
criteria.push({ field: partTrimmed, direction: "asc" });
|
|
351
|
-
} else {
|
|
352
|
-
const field = partTrimmed.slice(0, colonIndex).trim();
|
|
353
|
-
const direction = partTrimmed.slice(colonIndex + 1).trim().toLowerCase();
|
|
354
|
-
if (direction !== "asc" && direction !== "desc") {
|
|
355
|
-
return new Err(new ValidationError({
|
|
356
|
-
message: `Invalid sort direction: ${direction}. Must be 'asc' or 'desc'.`
|
|
357
|
-
}));
|
|
358
|
-
}
|
|
359
|
-
criteria.push({ field, direction });
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
return new Ok(criteria);
|
|
363
|
-
}
|
|
364
19
|
function normalizeId(input, options) {
|
|
365
20
|
const {
|
|
366
21
|
trim = false,
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { buildDryRunHint, createErrorEnvelope, createSuccessEnvelope, extractCategory, extractMessage, extractRetryAfterSeconds, formatEnvelopeHuman, getExitCode, safeCallHintFn } from "../shared/@outfitter/cli-nkt399zf.js";
|
|
2
|
+
import "../shared/@outfitter/cli-30mt7c5w.js";
|
|
3
|
+
import "../shared/@outfitter/cli-x6qr7bnd.js";
|
|
4
|
+
export { safeCallHintFn, getExitCode, formatEnvelopeHuman, extractRetryAfterSeconds, extractMessage, extractCategory, createSuccessEnvelope, createErrorEnvelope, buildDryRunHint };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
buildDryRunHint,
|
|
4
|
+
createErrorEnvelope,
|
|
5
|
+
createSuccessEnvelope,
|
|
6
|
+
extractCategory,
|
|
7
|
+
extractMessage,
|
|
8
|
+
extractRetryAfterSeconds,
|
|
9
|
+
formatEnvelopeHuman,
|
|
10
|
+
getExitCode,
|
|
11
|
+
safeCallHintFn
|
|
12
|
+
} from "../shared/@outfitter/cli-ry7btmy4.js";
|
|
13
|
+
import"../shared/@outfitter/cli-dg0cz7rw.js";
|
|
14
|
+
export {
|
|
15
|
+
safeCallHintFn,
|
|
16
|
+
getExitCode,
|
|
17
|
+
formatEnvelopeHuman,
|
|
18
|
+
extractRetryAfterSeconds,
|
|
19
|
+
extractMessage,
|
|
20
|
+
extractCategory,
|
|
21
|
+
createSuccessEnvelope,
|
|
22
|
+
createErrorEnvelope,
|
|
23
|
+
buildDryRunHint
|
|
24
|
+
};
|