@kjanat/dreamcli 2.2.1 → 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.
Files changed (38) hide show
  1. package/CHANGELOG.md +42 -1
  2. package/README.md +94 -34
  3. package/dist/core/cli/dispatch.d.mts +30 -2
  4. package/dist/core/cli/dispatch.mjs +1 -1
  5. package/dist/core/cli/index.mjs +1 -1
  6. package/dist/core/cli/planner.mjs +1 -1
  7. package/dist/core/config/package-json.mjs +1 -1
  8. package/dist/core/execution/index.mjs +1 -1
  9. package/dist/core/json-schema/meta-descriptions.generated.d.mts +59 -59
  10. package/dist/core/output/activity.mjs +1 -1
  11. package/dist/core/output/index.d.mts +6 -1
  12. package/dist/core/output/index.mjs +2 -2
  13. package/dist/core/parse/index.d.mts +31 -1
  14. package/dist/core/parse/index.mjs +1 -1
  15. package/dist/core/schema/activity.d.mts +1 -1
  16. package/dist/core/schema/command.d.mts +8 -0
  17. package/dist/core/schema/run.d.mts +8 -5
  18. package/dist/core/schema-dsl/runtime.mjs +1 -1
  19. package/dist/core/testkit/index.mjs +1 -1
  20. package/dist/index.mjs +1 -1
  21. package/dist/runtime/paths.mjs +1 -1
  22. package/dist/strings.d.mts +27 -0
  23. package/dist/strings.mjs +1 -0
  24. package/dist/testkit.mjs +1 -1
  25. package/dist/version.mjs +1 -1
  26. package/package.json +37 -25
  27. package/src/core/cli/dispatch.ts +70 -7
  28. package/src/core/cli/index.ts +13 -4
  29. package/src/core/cli/planner.ts +80 -6
  30. package/src/core/config/package-json.ts +3 -2
  31. package/src/core/execution/index.ts +8 -10
  32. package/src/core/help/index.ts +2 -2
  33. package/src/core/output/index.ts +29 -0
  34. package/src/core/parse/index.ts +23 -3
  35. package/src/core/schema/command.ts +8 -0
  36. package/src/core/schema/run.ts +8 -5
  37. package/src/runtime/paths.ts +4 -2
  38. package/src/strings.ts +34 -0
@@ -155,9 +155,10 @@ export interface RunOptions {
155
155
  /**
156
156
  * Structured result from {@linkcode runCommand}.
157
157
  *
158
- * Contains the exit code, captured stdout/stderr output, recorded
159
- * {@linkcode ActivityEvent | activity events}, and an `error` field
160
- * that is `undefined` on success and a {@linkcode CLIError} on failure.
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 non-zero exit, or `undefined` on success.
192
- * {@linkcode CLIError} instances are preserved; unknown errors are wrapped.
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
  }
@@ -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.replace(/[\\/]+$/, '') || homedir;
51
+ const normalizedHome = stripTrailing(homedir, [SLASH, BACKSLASH]) || homedir;
50
52
  return `${normalizedHome}\\AppData\\Roaming`;
51
53
  }
52
- const normalizedHome = homedir.replace(/\/+$/, '');
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 };