@kjanat/dreamcli 2.3.0 → 2.4.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/CHANGELOG.md +27 -1
- package/README.md +94 -34
- package/dist/core/cli/index.mjs +1 -1
- package/dist/core/cli/planner.mjs +1 -1
- package/dist/core/config/package-json.mjs +1 -1
- package/dist/core/execution/index.mjs +1 -1
- package/dist/core/json-schema/meta-descriptions.generated.d.mts +59 -59
- package/dist/core/output/activity.mjs +1 -1
- package/dist/core/output/index.d.mts +6 -1
- package/dist/core/output/index.mjs +2 -2
- package/dist/core/parse/index.mjs +1 -1
- package/dist/core/schema/activity.d.mts +1 -1
- package/dist/core/schema/command.d.mts +8 -0
- package/dist/core/schema/run.d.mts +8 -5
- package/dist/core/schema-dsl/runtime.mjs +1 -1
- package/dist/core/testkit/index.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/runtime/paths.mjs +1 -1
- package/dist/strings.d.mts +27 -0
- package/dist/strings.mjs +1 -0
- package/dist/testkit.mjs +1 -1
- package/dist/version.mjs +1 -1
- package/package.json +33 -24
- package/src/core/cli/index.ts +9 -3
- package/src/core/cli/planner.ts +58 -2
- package/src/core/config/package-json.ts +3 -2
- package/src/core/execution/index.ts +7 -1
- package/src/core/help/index.ts +2 -2
- package/src/core/output/index.ts +29 -0
- package/src/core/parse/index.ts +2 -2
- package/src/core/schema/command.ts +8 -0
- package/src/core/schema/run.ts +8 -5
- package/src/runtime/paths.ts +4 -2
- package/src/strings.ts +34 -0
package/src/core/parse/index.ts
CHANGED
|
@@ -445,7 +445,7 @@ function parseLongFlag(
|
|
|
445
445
|
|
|
446
446
|
// --flag value (next token is the value)
|
|
447
447
|
const nextToken = tokens[startIdx + 1];
|
|
448
|
-
if (
|
|
448
|
+
if (nextToken?.kind !== 'positional') {
|
|
449
449
|
throw new ParseError(`Flag --${token.name} requires a value`, {
|
|
450
450
|
code: 'MISSING_VALUE',
|
|
451
451
|
details: { flag: canonicalName, input: token.name, kind: flagSchema.kind },
|
|
@@ -505,7 +505,7 @@ function parseShortFlags(
|
|
|
505
505
|
|
|
506
506
|
// Last char in the group — consume next token as value
|
|
507
507
|
const nextToken = tokens[nextIdx];
|
|
508
|
-
if (
|
|
508
|
+
if (nextToken?.kind !== 'positional') {
|
|
509
509
|
throw new ParseError(`Flag -${ch} requires a value`, {
|
|
510
510
|
code: 'MISSING_VALUE',
|
|
511
511
|
details: { flag: canonicalName, input: ch, kind: flagSchema.kind },
|
|
@@ -152,6 +152,14 @@ interface Out {
|
|
|
152
152
|
warn(message: string): void;
|
|
153
153
|
/** Error to stderr. */
|
|
154
154
|
error(message: string): void;
|
|
155
|
+
/**
|
|
156
|
+
* Request a process exit code without emitting error-shaped output.
|
|
157
|
+
*
|
|
158
|
+
* Use this for check/status commands that should print normal output but
|
|
159
|
+
* still signal a non-zero status to scripts. This does not stop execution;
|
|
160
|
+
* later calls overwrite earlier calls, and thrown errors still win.
|
|
161
|
+
*/
|
|
162
|
+
setExitCode(code: number): void;
|
|
155
163
|
/**
|
|
156
164
|
* Emit a structured JSON value to stdout.
|
|
157
165
|
*
|
package/src/core/schema/run.ts
CHANGED
|
@@ -155,9 +155,10 @@ export interface RunOptions {
|
|
|
155
155
|
/**
|
|
156
156
|
* Structured result from {@linkcode runCommand}.
|
|
157
157
|
*
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
* Contains the exit code, captured stdout/stderr output, recorded
|
|
159
|
+
* {@linkcode ActivityEvent | activity events}, and an `error` field.
|
|
160
|
+
* `error` is `undefined` when execution completed without throwing, even if
|
|
161
|
+
* the handler requested a non-zero status via {@linkcode Out.setExitCode}.
|
|
161
162
|
*
|
|
162
163
|
* @example
|
|
163
164
|
* ```ts
|
|
@@ -188,8 +189,10 @@ export interface RunResult {
|
|
|
188
189
|
readonly activity: readonly ActivityEvent[];
|
|
189
190
|
|
|
190
191
|
/**
|
|
191
|
-
* The error that caused a
|
|
192
|
-
*
|
|
192
|
+
* The error that caused a failure, or `undefined` when execution completed.
|
|
193
|
+
* A non-zero `exitCode` can still have no error when a handler calls
|
|
194
|
+
* {@linkcode Out.setExitCode}. {@linkcode CLIError} instances are preserved;
|
|
195
|
+
* unknown errors are wrapped.
|
|
193
196
|
*/
|
|
194
197
|
readonly error: CLIError | undefined;
|
|
195
198
|
}
|
package/src/runtime/paths.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
* @module @kjanat/dreamcli/runtime/paths
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import { BACKSLASH, SLASH, stripTrailing } from '#internals/strings.ts';
|
|
12
|
+
|
|
11
13
|
/**
|
|
12
14
|
* Resolve the user's home directory from environment variables.
|
|
13
15
|
*
|
|
@@ -46,10 +48,10 @@ function resolveConfigDirectory(
|
|
|
46
48
|
): string {
|
|
47
49
|
if (isWindows) {
|
|
48
50
|
if (env.APPDATA !== undefined && env.APPDATA !== '') return env.APPDATA;
|
|
49
|
-
const normalizedHome = homedir
|
|
51
|
+
const normalizedHome = stripTrailing(homedir, [SLASH, BACKSLASH]) || homedir;
|
|
50
52
|
return `${normalizedHome}\\AppData\\Roaming`;
|
|
51
53
|
}
|
|
52
|
-
const normalizedHome = homedir
|
|
54
|
+
const normalizedHome = stripTrailing(homedir, [SLASH]);
|
|
53
55
|
if (env.XDG_CONFIG_HOME !== undefined && env.XDG_CONFIG_HOME !== '') {
|
|
54
56
|
return env.XDG_CONFIG_HOME;
|
|
55
57
|
}
|
package/src/strings.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal string utilities shared across runtime and core modules.
|
|
3
|
+
*
|
|
4
|
+
* @module dreamcli/strings
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Character code for `/` (forward slash). */
|
|
8
|
+
const SLASH = 0x2f;
|
|
9
|
+
/** Character code for `\` (backslash). */
|
|
10
|
+
const BACKSLASH = 0x5c;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Remove trailing characters whose code points appear in `codes`.
|
|
14
|
+
*
|
|
15
|
+
* Linear-time replacement for trailing-character regexes such as
|
|
16
|
+
* `/[\\/]+$/`. Those patterns are polynomial-ReDoS prone: the engine
|
|
17
|
+
* greedily consumes the run, fails the end anchor, backtracks one
|
|
18
|
+
* character at a time, and repeats that work from every start position —
|
|
19
|
+
* O(n²) on adversarial input. This scan is O(n) with no backtracking.
|
|
20
|
+
*
|
|
21
|
+
* @param input - Source string.
|
|
22
|
+
* @param codes - Character codes to strip from the end of `input`.
|
|
23
|
+
* @returns `input` with all trailing matching characters removed.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
function stripTrailing(input: string, codes: readonly number[]): string {
|
|
27
|
+
let end = input.length;
|
|
28
|
+
while (end > 0 && codes.includes(input.charCodeAt(end - 1))) {
|
|
29
|
+
end -= 1;
|
|
30
|
+
}
|
|
31
|
+
return end === input.length ? input : input.slice(0, end);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { BACKSLASH, SLASH, stripTrailing };
|