@sayknow-cli/utils 0.4.2 → 0.4.4
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/types/abortable.d.ts +27 -0
- package/dist/types/async.d.ts +6 -0
- package/dist/types/broken-pipe.d.ts +27 -0
- package/dist/types/cli.d.ts +126 -0
- package/dist/types/color.d.ts +82 -0
- package/dist/types/dirs.d.ts +165 -0
- package/dist/types/env.d.ts +68 -0
- package/dist/types/fetch-retry.d.ts +80 -0
- package/dist/types/format.d.ts +37 -0
- package/dist/types/frontmatter.d.ts +25 -0
- package/dist/types/fs-error.d.ts +31 -0
- package/dist/types/glob.d.ts +28 -0
- package/dist/types/hook-fetch.d.ts +16 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/json.d.ts +4 -0
- package/dist/types/logger.d.ts +66 -0
- package/dist/types/mermaid-ascii.d.ts +11 -0
- package/dist/types/mime.d.ts +29 -0
- package/dist/types/peek-file.d.ts +9 -0
- package/dist/types/postmortem.d.ts +29 -0
- package/dist/types/procmgr.d.ts +35 -0
- package/dist/types/prompt.d.ts +18 -0
- package/dist/types/ptree.d.ts +108 -0
- package/dist/types/ring.d.ts +93 -0
- package/dist/types/safe-stderr.d.ts +1 -0
- package/dist/types/sanitize-text.d.ts +14 -0
- package/dist/types/snowflake.d.ts +25 -0
- package/dist/types/spawn-env.d.ts +4 -0
- package/dist/types/stream.d.ts +68 -0
- package/dist/types/tab-spacing.d.ts +12 -0
- package/dist/types/temp.d.ts +14 -0
- package/dist/types/type-guards.d.ts +3 -0
- package/dist/types/which.d.ts +39 -0
- package/package.json +7 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare class AbortError extends Error {
|
|
2
|
+
constructor(signal: AbortSignal);
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Creates an abortable stream from a given stream and signal.
|
|
6
|
+
*
|
|
7
|
+
* @param stream - The stream to make abortable
|
|
8
|
+
* @param signal - The signal to abort the stream
|
|
9
|
+
* @returns The abortable stream
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAbortableStream<T>(stream: ReadableStream<T>, signal?: AbortSignal): ReadableStream<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Runs a promise-returning function (`pr`). If the given AbortSignal is aborted before or during
|
|
14
|
+
* execution, the promise is rejected with a standard error.
|
|
15
|
+
*
|
|
16
|
+
* @param signal - Optional AbortSignal to cancel the operation
|
|
17
|
+
* @param pr - Function returning a promise to run
|
|
18
|
+
* @returns Promise resolving as `pr` would, or rejecting on abort
|
|
19
|
+
*/
|
|
20
|
+
export declare function untilAborted<T>(signal: AbortSignal | undefined | null, pr: Promise<T> | (() => Promise<T>)): Promise<T>;
|
|
21
|
+
/**
|
|
22
|
+
* Memoizes a function with no arguments, calling it once and caching the result.
|
|
23
|
+
*
|
|
24
|
+
* @param fn - Function to be called once
|
|
25
|
+
* @returns A function that returns the cached result of `fn`
|
|
26
|
+
*/
|
|
27
|
+
export declare function once<T>(fn: () => T): () => T;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap a promise with a timeout and optional abort signal.
|
|
3
|
+
* Rejects with the given message if the timeout fires first.
|
|
4
|
+
* Cleans up all listeners on settlement.
|
|
5
|
+
*/
|
|
6
|
+
export declare function withTimeout<T>(promise: Promise<T>, ms: number, message: string, signal?: AbortSignal): Promise<T>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* True when an error from a writer that owns its sink reports that the peer
|
|
3
|
+
* closed that sink. This intentionally accepts structural error objects rather
|
|
4
|
+
* than requiring an `Error` instance.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isKnownSinkPeerClosedError(error: unknown): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Backward-compatible local-sink classifier for output writers. Callers must
|
|
9
|
+
* use it only when they own the sink that produced the error.
|
|
10
|
+
*/
|
|
11
|
+
export declare function isBrokenPipeError(error: unknown): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A classifier for process-level stdout `EPIPE` errors. Its direct-write
|
|
14
|
+
* evidence is private to each factory instance, so only the owner that
|
|
15
|
+
* intercepted `process.stdout.write` can mark an error for this classifier.
|
|
16
|
+
*/
|
|
17
|
+
export interface ProcessStdoutEpipeClassifier {
|
|
18
|
+
markDirectProcessStdoutWriteError(error: unknown): void;
|
|
19
|
+
isAttributableProcessStdoutEpipe(error: unknown): boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function createProcessStdoutEpipeClassifier(): ProcessStdoutEpipeClassifier;
|
|
22
|
+
/**
|
|
23
|
+
* Exit code for a producer terminated because its output pipe broke:
|
|
24
|
+
* 128 + SIGPIPE (13), matching what shells report for SIGPIPE-killed tools
|
|
25
|
+
* in `foo | head`-style pipelines.
|
|
26
|
+
*/
|
|
27
|
+
export declare const BROKEN_PIPE_EXIT_CODE = 141;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export interface FlagDescriptor<K extends "string" | "boolean" | "integer" = "string" | "boolean" | "integer"> {
|
|
2
|
+
kind: K;
|
|
3
|
+
description?: string;
|
|
4
|
+
char?: string;
|
|
5
|
+
default?: unknown;
|
|
6
|
+
multiple?: boolean;
|
|
7
|
+
options?: readonly string[];
|
|
8
|
+
required?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ArgDescriptor {
|
|
11
|
+
kind: "string";
|
|
12
|
+
description?: string;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
options?: readonly string[];
|
|
16
|
+
}
|
|
17
|
+
interface FlagInput {
|
|
18
|
+
description?: string;
|
|
19
|
+
char?: string;
|
|
20
|
+
default?: unknown;
|
|
21
|
+
multiple?: boolean;
|
|
22
|
+
options?: readonly string[];
|
|
23
|
+
required?: boolean;
|
|
24
|
+
}
|
|
25
|
+
interface ArgInput {
|
|
26
|
+
description?: string;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
multiple?: boolean;
|
|
29
|
+
options?: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
/** Builders that match the `Flags.*()` / `Args.*()` API from oclif. */
|
|
32
|
+
export declare const Flags: {
|
|
33
|
+
string<T extends FlagInput>(opts?: T): FlagDescriptor<"string"> & T;
|
|
34
|
+
boolean<T extends FlagInput>(opts?: T): FlagDescriptor<"boolean"> & T;
|
|
35
|
+
integer<T extends FlagInput & {
|
|
36
|
+
default?: number;
|
|
37
|
+
}>(opts?: T): FlagDescriptor<"integer"> & T;
|
|
38
|
+
};
|
|
39
|
+
export declare const Args: {
|
|
40
|
+
string<T extends ArgInput>(opts?: T): ArgDescriptor & T;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Thrown when CLI argument/flag parsing or validation fails (unknown flag,
|
|
44
|
+
* bad option value, missing required arg, etc.). `run()` catches this to print
|
|
45
|
+
* the message and render usage instead of crashing as an uncaught exception.
|
|
46
|
+
*/
|
|
47
|
+
export declare class CliParseError extends Error {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
type FlagValue<D extends FlagDescriptor> = D["kind"] extends "boolean" ? D extends {
|
|
51
|
+
default: boolean;
|
|
52
|
+
} ? boolean : boolean | undefined : D["kind"] extends "integer" ? D extends {
|
|
53
|
+
default: number;
|
|
54
|
+
} ? number : number | undefined : D extends {
|
|
55
|
+
multiple: true;
|
|
56
|
+
} ? string[] | undefined : string | undefined;
|
|
57
|
+
type ArgValue<D extends ArgDescriptor> = D extends {
|
|
58
|
+
multiple: true;
|
|
59
|
+
} ? string[] | undefined : string | undefined;
|
|
60
|
+
type FlagValues<T extends Record<string, FlagDescriptor>> = {
|
|
61
|
+
[K in keyof T]: FlagValue<T[K]>;
|
|
62
|
+
};
|
|
63
|
+
type ArgValues<T extends Record<string, ArgDescriptor>> = {
|
|
64
|
+
[K in keyof T]: ArgValue<T[K]>;
|
|
65
|
+
};
|
|
66
|
+
export interface ParseOutput<F extends Record<string, FlagDescriptor> = Record<string, FlagDescriptor>, A extends Record<string, ArgDescriptor> = Record<string, ArgDescriptor>> {
|
|
67
|
+
flags: FlagValues<F>;
|
|
68
|
+
args: ArgValues<A>;
|
|
69
|
+
argv: string[];
|
|
70
|
+
}
|
|
71
|
+
export interface CommandCtor {
|
|
72
|
+
new (argv: string[], config: CliConfig): Command;
|
|
73
|
+
description?: string;
|
|
74
|
+
hidden?: boolean;
|
|
75
|
+
strict?: boolean;
|
|
76
|
+
aliases?: string[];
|
|
77
|
+
examples?: string[];
|
|
78
|
+
flags?: Record<string, FlagDescriptor>;
|
|
79
|
+
args?: Record<string, ArgDescriptor>;
|
|
80
|
+
delegateHelp?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Configuration passed to every command instance and help renderers. */
|
|
83
|
+
export interface CliConfig {
|
|
84
|
+
bin: string;
|
|
85
|
+
version: string;
|
|
86
|
+
/** All registered commands keyed by their canonical name. */
|
|
87
|
+
commands: Map<string, CommandCtor>;
|
|
88
|
+
}
|
|
89
|
+
/** Minimal Command base matching the oclif surface we use. */
|
|
90
|
+
export declare abstract class Command {
|
|
91
|
+
argv: string[];
|
|
92
|
+
config: CliConfig;
|
|
93
|
+
constructor(argv: string[], config: CliConfig);
|
|
94
|
+
abstract run(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Parse argv against the static `flags` and `args` declared on the
|
|
97
|
+
* concrete command class. Returns a typed `{ flags, args, argv }` object.
|
|
98
|
+
*/
|
|
99
|
+
parse<C extends CommandCtor>(_Cmd: C): Promise<ParseOutput<NonNullable<C["flags"]> extends Record<string, FlagDescriptor> ? NonNullable<C["flags"]> : Record<string, FlagDescriptor>, NonNullable<C["args"]> extends Record<string, ArgDescriptor> ? NonNullable<C["args"]> : Record<string, ArgDescriptor>>>;
|
|
100
|
+
}
|
|
101
|
+
/** Render full root help: header, default command details, subcommand list. */
|
|
102
|
+
export declare function renderRootHelp(config: CliConfig): void;
|
|
103
|
+
/** Render help for a single command. */
|
|
104
|
+
export declare function renderCommandHelp(bin: string, id: string, Cmd: CommandCtor): void;
|
|
105
|
+
/** A lazily-loaded command: canonical name, loader, and optional aliases. */
|
|
106
|
+
export interface CommandEntry {
|
|
107
|
+
name: string;
|
|
108
|
+
load: () => Promise<CommandCtor>;
|
|
109
|
+
aliases?: string[];
|
|
110
|
+
}
|
|
111
|
+
export interface RunOptions {
|
|
112
|
+
bin: string;
|
|
113
|
+
version: string;
|
|
114
|
+
argv: string[];
|
|
115
|
+
commands: CommandEntry[];
|
|
116
|
+
/** Custom help renderer. Receives fully-populated config. */
|
|
117
|
+
help?: (config: CliConfig) => Promise<void> | void;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Main entry point — replaces `run()` from @oclif/core.
|
|
121
|
+
*
|
|
122
|
+
* Each command is explicitly registered with a lazy loader.
|
|
123
|
+
* No filesystem scanning, no plugin system, no package.json reading.
|
|
124
|
+
*/
|
|
125
|
+
export declare function run(opts: RunOptions): Promise<void>;
|
|
126
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Color manipulation utilities for hex colors.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { hexToHsv, hsvToHex } from "@sayknow-cli/utils";
|
|
7
|
+
*
|
|
8
|
+
* // Work with HSV directly
|
|
9
|
+
*
|
|
10
|
+
* // Or work with HSV directly
|
|
11
|
+
* const hsv = hexToHsv("#4ade80");
|
|
12
|
+
* hsv.h = (hsv.h + 90) % 360;
|
|
13
|
+
* const newHex = hsvToHex(hsv);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface HSV {
|
|
17
|
+
/** Hue in degrees (0-360) */
|
|
18
|
+
h: number;
|
|
19
|
+
/** Saturation (0-1) */
|
|
20
|
+
s: number;
|
|
21
|
+
/** Value/brightness (0-1) */
|
|
22
|
+
v: number;
|
|
23
|
+
}
|
|
24
|
+
export interface RGB {
|
|
25
|
+
/** Red (0-255) */
|
|
26
|
+
r: number;
|
|
27
|
+
/** Green (0-255) */
|
|
28
|
+
g: number;
|
|
29
|
+
/** Blue (0-255) */
|
|
30
|
+
b: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parse a hex color string to RGB.
|
|
34
|
+
* Supports #RGB, #RRGGBB formats.
|
|
35
|
+
*/
|
|
36
|
+
export declare function hexToRgb(hex: string): RGB;
|
|
37
|
+
/**
|
|
38
|
+
* Convert RGB to hex color string.
|
|
39
|
+
*/
|
|
40
|
+
export declare function rgbToHex(rgb: RGB): string;
|
|
41
|
+
/**
|
|
42
|
+
* Convert RGB to HSV.
|
|
43
|
+
*/
|
|
44
|
+
export declare function rgbToHsv(rgb: RGB): HSV;
|
|
45
|
+
/**
|
|
46
|
+
* Convert HSV to RGB.
|
|
47
|
+
*/
|
|
48
|
+
export declare function hsvToRgb(hsv: HSV): RGB;
|
|
49
|
+
/**
|
|
50
|
+
* Convert hex color to HSV.
|
|
51
|
+
*/
|
|
52
|
+
export declare function hexToHsv(hex: string): HSV;
|
|
53
|
+
/**
|
|
54
|
+
* Convert HSV to hex color.
|
|
55
|
+
*/
|
|
56
|
+
export declare function hsvToHex(hsv: HSV): string;
|
|
57
|
+
/**
|
|
58
|
+
* Shift the hue of a hex color by a given number of degrees.
|
|
59
|
+
*/
|
|
60
|
+
export declare function shiftHue(hex: string, degrees: number): string;
|
|
61
|
+
export interface HSVAdjustment {
|
|
62
|
+
/** Hue shift in degrees (additive) */
|
|
63
|
+
h?: number;
|
|
64
|
+
/** Saturation multiplier */
|
|
65
|
+
s?: number;
|
|
66
|
+
/** Value/brightness multiplier */
|
|
67
|
+
v?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Adjust HSV components of a hex color.
|
|
71
|
+
*
|
|
72
|
+
* @param hex - Hex color string (#RGB or #RRGGBB)
|
|
73
|
+
* @param adj - Adjustments: h is additive degrees, s and v are multipliers
|
|
74
|
+
* @returns New hex color string
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* // Shift hue +60°, reduce saturation to 71%
|
|
79
|
+
* adjustHsv("#00ff88", { h: 60, s: 0.71 }) // "#4a9eff"
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function adjustHsv(hex: string, adj: HSVAdjustment): string;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized path helpers for sayknow-cli config directories.
|
|
3
|
+
*
|
|
4
|
+
* Uses PI_CONFIG_DIR (default ".skc") for the config root and
|
|
5
|
+
* PI_CODING_AGENT_DIR to override the agent directory.
|
|
6
|
+
*
|
|
7
|
+
* On Linux, if XDG_DATA_HOME / XDG_STATE_HOME / XDG_CACHE_HOME environment
|
|
8
|
+
* variables are set, paths are redirected to XDG-compliant locations under
|
|
9
|
+
* $XDG_*_HOME/skc/. This requires running `skc config migrate` first to
|
|
10
|
+
* move data to the new locations. No filesystem existence checks are performed
|
|
11
|
+
* — if the env var is set, skc trusts that the migration has been done.
|
|
12
|
+
*/
|
|
13
|
+
/** App name (e.g. "skc") */
|
|
14
|
+
export declare const APP_NAME: string;
|
|
15
|
+
/** Config directory name (e.g. ".skc") */
|
|
16
|
+
export declare const CONFIG_DIR_NAME: string;
|
|
17
|
+
/** Version (e.g. "1.0.0") */
|
|
18
|
+
export declare const VERSION: string;
|
|
19
|
+
/** Minimum Bun version */
|
|
20
|
+
export declare const MIN_BUN_VERSION: string;
|
|
21
|
+
/**
|
|
22
|
+
* Build the diagnostic shown when the Bun runtime executing `skc` is older
|
|
23
|
+
* than {@link MIN_BUN_VERSION}. This is the most common Windows native-install
|
|
24
|
+
* failure (issue #525): `bun install -g sayknow-cli` probes a recent Bun while
|
|
25
|
+
* the `skc` launcher resolves an older Bun still on PATH. The message names the
|
|
26
|
+
* exact detected runtime path and gives a platform-specific upgrade + PATH fix
|
|
27
|
+
* instead of a bare `bun upgrade`.
|
|
28
|
+
*
|
|
29
|
+
* Pure and platform-parameterized so it can be unit-tested cross-platform.
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatBunRuntimeError(opts: {
|
|
32
|
+
currentVersion: string;
|
|
33
|
+
minVersion: string;
|
|
34
|
+
execPath?: string;
|
|
35
|
+
platform?: NodeJS.Platform;
|
|
36
|
+
}): string;
|
|
37
|
+
export declare function resolveEquivalentPath(inputPath: string): string;
|
|
38
|
+
export declare function normalizePathForComparison(inputPath: string, platform?: NodeJS.Platform): string;
|
|
39
|
+
/** Return whether a relative path crosses above its root or is unexpectedly absolute. */
|
|
40
|
+
export declare function relativePathEscapesRoot(relative: string): boolean;
|
|
41
|
+
export declare function pathIsWithin(root: string, candidate: string): boolean;
|
|
42
|
+
export declare function relativePathWithinRoot(root: string, candidate: string): string | null;
|
|
43
|
+
/** Get the project directory. */
|
|
44
|
+
export declare function getProjectDir(): string;
|
|
45
|
+
/** Set the project directory. */
|
|
46
|
+
export declare function setProjectDir(dir: string): void;
|
|
47
|
+
/** Get the config directory name relative to home (e.g. ".skc" or PI_CONFIG_DIR override). */
|
|
48
|
+
export declare function getConfigDirName(): string;
|
|
49
|
+
/** Get the config agent directory name relative to home (e.g. ".skc/agent" or PI_CONFIG_DIR + "/agent"). */
|
|
50
|
+
export declare function getConfigAgentDirName(): string;
|
|
51
|
+
/** Get the config root directory (~/.skc). */
|
|
52
|
+
export declare function getConfigRootDir(): string;
|
|
53
|
+
/** Set the coding agent directory. Creates a fresh resolver, invalidating all cached paths. */
|
|
54
|
+
export declare function setAgentDir(dir: string): void;
|
|
55
|
+
/** Get the agent config directory (~/.skc/agent). */
|
|
56
|
+
export declare function getAgentDir(): string;
|
|
57
|
+
/** Get the project-local config directory (.skc). */
|
|
58
|
+
export declare function getProjectAgentDir(cwd?: string): string;
|
|
59
|
+
/** Get the reports directory (~/.skc/reports). */
|
|
60
|
+
export declare function getReportsDir(): string;
|
|
61
|
+
/** Get the logs directory (~/.skc/logs). */
|
|
62
|
+
export declare function getLogsDir(): string;
|
|
63
|
+
/** Get the path to a dated log file (~/.skc/logs/skc.YYYY-MM-DD.log). */
|
|
64
|
+
export declare function getLogPath(date?: Date): string;
|
|
65
|
+
/**
|
|
66
|
+
* Get the plugins directory (~/.skc/plugins or its XDG equivalent).
|
|
67
|
+
*
|
|
68
|
+
* No-arg form (production callers) goes through the XDG-aware DirResolver so
|
|
69
|
+
* reads and writes always agree. The optional `home` parameter is for test
|
|
70
|
+
* isolation: when it differs from `os.homedir()` it short-circuits the resolver
|
|
71
|
+
* and returns `<home>/<configDir>/plugins` so tests with a temp HOME get a
|
|
72
|
+
* deterministic path. Passing `os.homedir()` explicitly is identical to the
|
|
73
|
+
* no-arg form — XDG semantics are preserved.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getPluginsDir(home?: string): string;
|
|
76
|
+
/** Where npm installs packages (~/.skc/plugins/node_modules). */
|
|
77
|
+
export declare function getPluginsNodeModules(): string;
|
|
78
|
+
/** Plugin manifest (~/.skc/plugins/package.json). */
|
|
79
|
+
export declare function getPluginsPackageJson(): string;
|
|
80
|
+
/** Plugin lock file (~/.skc/plugins/skc-plugins.lock.json). */
|
|
81
|
+
export declare function getPluginsLockfile(): string;
|
|
82
|
+
/** Get the remote mount directory (~/.skc/remote). */
|
|
83
|
+
export declare function getRemoteDir(): string;
|
|
84
|
+
/** Get the agent-managed worktrees directory (~/.skc/wt). */
|
|
85
|
+
export declare function getWorktreesDir(): string;
|
|
86
|
+
/** Get the SSH control socket directory (~/.skc/ssh-control). */
|
|
87
|
+
export declare function getSshControlDir(): string;
|
|
88
|
+
/** Get the remote host info directory (~/.skc/remote-host). */
|
|
89
|
+
export declare function getRemoteHostDir(): string;
|
|
90
|
+
/** Get the managed Python venv directory (~/.skc/python-env). */
|
|
91
|
+
export declare function getPythonEnvDir(): string;
|
|
92
|
+
/** Get the shared Python gateway state directory (~/.skc/agent/python-gateway; XDG default: $XDG_STATE_HOME/skc/python-gateway). */
|
|
93
|
+
export declare function getPythonGatewayDir(): string;
|
|
94
|
+
/** Get the puppeteer sandbox directory (~/.skc/puppeteer). */
|
|
95
|
+
export declare function getPuppeteerDir(): string;
|
|
96
|
+
/**
|
|
97
|
+
* Stable 7-character hex digest of an absolute filesystem path.
|
|
98
|
+
*
|
|
99
|
+
* Used to pack the project identity into a single short fs-safe segment
|
|
100
|
+
* (e.g. PR-checkout and task-isolation worktree dirs under `~/.skc/wt/`).
|
|
101
|
+
* Bun.hash is non-cryptographic — collision space is ~2^28, which is fine
|
|
102
|
+
* for naming a handful of repos on a single machine. Same input on the
|
|
103
|
+
* same Bun runtime yields the same output.
|
|
104
|
+
*/
|
|
105
|
+
export declare function hashPath(absPath: string): string;
|
|
106
|
+
/** Get the path to a single worktree directory (~/.skc/wt/<segment>). */
|
|
107
|
+
export declare function getWorktreeDir(segment: string): string;
|
|
108
|
+
/** Get the GPU cache path (~/.skc/gpu_cache.json). */
|
|
109
|
+
export declare function getGpuCachePath(): string;
|
|
110
|
+
/**
|
|
111
|
+
* Get the GitHub view cache database path (~/.skc/cache/github-cache.db).
|
|
112
|
+
* Honors the `SKC_GITHUB_CACHE_DB` env var when set so tests can isolate the
|
|
113
|
+
* cache file without touching the rest of the config root.
|
|
114
|
+
*/
|
|
115
|
+
export declare function getGithubCacheDbPath(): string;
|
|
116
|
+
/** Get the natives directory (~/.skc/natives). */
|
|
117
|
+
export declare function getNativesDir(): string;
|
|
118
|
+
/** Get the stats database path (~/.skc/stats.db). */
|
|
119
|
+
export declare function getStatsDbPath(): string;
|
|
120
|
+
/** Get the autoresearch state directory (~/.skc/autoresearch). */
|
|
121
|
+
export declare function getAutoresearchDir(): string;
|
|
122
|
+
/** Get the per-project autoresearch state directory (~/.skc/autoresearch/<encoded-project>). */
|
|
123
|
+
export declare function getAutoresearchProjectDir(encodedProject: string): string;
|
|
124
|
+
/** Get the per-project autoresearch SQLite database path (~/.skc/autoresearch/<encoded-project>.db). */
|
|
125
|
+
export declare function getAutoresearchDbPath(encodedProject: string): string;
|
|
126
|
+
/** Get the per-run artifact directory (~/.skc/autoresearch/<encoded-project>/runs/<runId>). */
|
|
127
|
+
export declare function getAutoresearchRunDir(encodedProject: string, runId: number): string;
|
|
128
|
+
/** Get the path to agent.db (SQLite database for settings and auth storage). */
|
|
129
|
+
export declare function getAgentDbPath(agentDir?: string): string;
|
|
130
|
+
/** Get the path to history.db (SQLite database for session history). */
|
|
131
|
+
export declare function getHistoryDbPath(agentDir?: string): string;
|
|
132
|
+
/** Get the path to models.db (model cache database). */
|
|
133
|
+
export declare function getModelDbPath(agentDir?: string): string;
|
|
134
|
+
/** Get the sessions directory (~/.skc/agent/sessions). */
|
|
135
|
+
export declare function getSessionsDir(agentDir?: string): string;
|
|
136
|
+
/** Get the content-addressed blob store directory (~/.skc/agent/blobs). */
|
|
137
|
+
export declare function getBlobsDir(agentDir?: string): string;
|
|
138
|
+
/** Get the custom themes directory (~/.skc/agent/themes). */
|
|
139
|
+
export declare function getCustomThemesDir(agentDir?: string): string;
|
|
140
|
+
/** Get the tools directory (~/.skc/agent/tools). */
|
|
141
|
+
export declare function getToolsDir(agentDir?: string): string;
|
|
142
|
+
/** Get the slash commands directory (~/.skc/agent/commands). */
|
|
143
|
+
export declare function getCommandsDir(agentDir?: string): string;
|
|
144
|
+
/** Get the prompts directory (~/.skc/agent/prompts). */
|
|
145
|
+
export declare function getPromptsDir(agentDir?: string): string;
|
|
146
|
+
/** Get the user-level Python modules directory (~/.skc/agent/modules). */
|
|
147
|
+
export declare function getAgentModulesDir(agentDir?: string): string;
|
|
148
|
+
/** Get the memories directory (~/.skc/agent/memories). */
|
|
149
|
+
export declare function getMemoriesDir(agentDir?: string): string;
|
|
150
|
+
/** Get the terminal sessions directory (~/.skc/agent/terminal-sessions). */
|
|
151
|
+
export declare function getTerminalSessionsDir(agentDir?: string): string;
|
|
152
|
+
/** Get the crash log path (~/.skc/agent/skc-crash.log). */
|
|
153
|
+
export declare function getCrashLogPath(agentDir?: string): string;
|
|
154
|
+
/** Get the debug log path (~/.skc/agent/skc-debug.log). */
|
|
155
|
+
export declare function getDebugLogPath(agentDir?: string): string;
|
|
156
|
+
/** Get the project-level Python modules directory (.skc/modules). */
|
|
157
|
+
export declare function getProjectModulesDir(cwd?: string): string;
|
|
158
|
+
/** Get the project-level prompts directory (.skc/prompts). */
|
|
159
|
+
export declare function getProjectPromptsDir(cwd?: string): string;
|
|
160
|
+
/** Get the project-level plugin overrides path (.skc/plugin-overrides.json). */
|
|
161
|
+
export declare function getProjectPluginOverridesPath(cwd?: string): string;
|
|
162
|
+
/** Get the primary MCP config file path (first candidate). */
|
|
163
|
+
export declare function getMCPConfigPath(scope: "user" | "project", cwd?: string): string;
|
|
164
|
+
/** Get the SSH config file path. */
|
|
165
|
+
export declare function getSSHConfigPath(scope: "user" | "project", cwd?: string): string;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export { filterProcessEnv, isSafeEnvName, isSafeEnvValue } from "./spawn-env";
|
|
2
|
+
/**
|
|
3
|
+
* Strict shell-identifier shape. Used for dotenv keys we accept into
|
|
4
|
+
* `Bun.env` — those should be referenceable as `$NAME` from POSIX shells,
|
|
5
|
+
* so we reject anything outside `[A-Za-z_][A-Za-z0-9_]*`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isValidEnvName(name: string): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Parses simple POSIX shell environment assignments from files such as
|
|
10
|
+
* ~/.zshrc without executing user shell code. Supports `export KEY=value` and
|
|
11
|
+
* `KEY=value`, including single/double quoted literal values. Dynamic shell
|
|
12
|
+
* expressions are intentionally ignored because evaluating startup files would
|
|
13
|
+
* run arbitrary code during CLI startup.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseShellEnvFile(filePath: string): Record<string, string>;
|
|
16
|
+
/**
|
|
17
|
+
* Parses a .env file synchronously and extracts key-value string pairs.
|
|
18
|
+
* Ignores lines that are empty or start with '#'. Trims whitespace.
|
|
19
|
+
* Allows values to be quoted with single or double quotes.
|
|
20
|
+
* Returns an object of key-value pairs.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseEnvFile(filePath: string): Record<string, string>;
|
|
23
|
+
export declare function $inheritedEnv(name: string): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Intentional re-export of Bun.env.
|
|
26
|
+
*
|
|
27
|
+
* All users should import this env module (import { $env } from "@sayknow-cli/utils")
|
|
28
|
+
* before using environment variables. This ensures that .env files have been loaded and
|
|
29
|
+
* overrides (project, home) have been applied, so $env always reflects the correct values.
|
|
30
|
+
*
|
|
31
|
+
* Provider credential resolution must not use this merged view because it includes the
|
|
32
|
+
* caller's cwd/.env. Use $credentialEnv/$pickCredentialEnv for model authentication.
|
|
33
|
+
*/
|
|
34
|
+
export declare const $env: Record<string, string>;
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the first environment variable value from the given keys.
|
|
37
|
+
* @param keys - The keys to resolve.
|
|
38
|
+
* @returns The first environment variable value, or undefined if no value is found.
|
|
39
|
+
*/
|
|
40
|
+
export declare function $pickenv(...keys: string[]): string | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Resolve credential-bearing environment variables without consulting the caller's project .env.
|
|
43
|
+
*
|
|
44
|
+
* SKC loads cwd/.env into $env for project-aware tools, but model-provider authentication should
|
|
45
|
+
* only use values explicitly inherited from the launching shell or SKC/user-owned config files.
|
|
46
|
+
*/
|
|
47
|
+
export declare function $credentialEnv(name: string): string | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the first credential env value from the given keys, excluding cwd/.env overlays.
|
|
50
|
+
*/
|
|
51
|
+
export declare function $pickCredentialEnv(...keys: string[]): string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Parses a positive decimal integer from `$env[name]`.
|
|
54
|
+
* Empty, invalid, NaN, zero, or negative values return `defaultValue`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function $envpos(name: string, defaultValue: number): number;
|
|
57
|
+
/** True when `BUN_ENV` or `NODE_ENV` is the string `test`. */
|
|
58
|
+
export declare function isBunTestRuntime(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* True when this code is running inside a `bun build --compile` standalone
|
|
61
|
+
* binary. Detects via the embedded virtual-filesystem path markers
|
|
62
|
+
* (`$bunfs`, `~BUN`, or its URL-encoded form `%7EBUN`) in `import.meta.url`,
|
|
63
|
+
* which Bun rewrites for every module bundled into the executable. The
|
|
64
|
+
* `PI_COMPILED` env var (set by the build script's `--define`) is checked
|
|
65
|
+
* first for cheap fast-path detection.
|
|
66
|
+
*/
|
|
67
|
+
export declare function isCompiledBinary(): boolean;
|
|
68
|
+
export declare function $flag(name: string, def?: boolean): boolean;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-suggested retry delay extraction. Merges the patterns historically used
|
|
3
|
+
* by the OpenAI code provider and Google Gemini retry helpers.
|
|
4
|
+
*
|
|
5
|
+
* Header sources (checked in order):
|
|
6
|
+
* - `Retry-After` (numeric seconds, or HTTP date)
|
|
7
|
+
* - `x-ratelimit-reset` (Unix epoch seconds)
|
|
8
|
+
* - `x-ratelimit-reset-after` (seconds)
|
|
9
|
+
*
|
|
10
|
+
* Body patterns:
|
|
11
|
+
* - `Your quota will reset after 18h31m10s` / `10m15s` / `39s`
|
|
12
|
+
* - `Please retry in 250ms` / `Please retry in 12s`
|
|
13
|
+
* - `"retryDelay": "34.074824224s"` (JSON error detail field)
|
|
14
|
+
* - `try again in 250ms` / `try again in 12s` / `try again in 12sec`
|
|
15
|
+
*
|
|
16
|
+
* Returns `undefined` if no signal is found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function extractRetryHint(source: Response | Headers | null | undefined, body?: string): number | undefined;
|
|
19
|
+
export interface FetchWithRetryOptions extends RequestInit {
|
|
20
|
+
/** Total fetch attempts (initial + retries). Default `5`. */
|
|
21
|
+
maxAttempts?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Per-delay cap. Server-provided `Retry-After` hints exceeding this return
|
|
24
|
+
* the current response immediately — caller deals with the `!response.ok`.
|
|
25
|
+
* Default `60_000`.
|
|
26
|
+
*/
|
|
27
|
+
maxDelayMs?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Fallback delay schedule when no server hint is present. Number, array
|
|
30
|
+
* (indexed by attempt, clamped to last), or function. Default exponential
|
|
31
|
+
* `500ms * 2 ** attempt` capped at `maxDelayMs`.
|
|
32
|
+
*/
|
|
33
|
+
defaultDelayMs?: number | readonly number[] | ((attempt: number) => number);
|
|
34
|
+
/**
|
|
35
|
+
* Optional per-attempt overlay merged into the base `RequestInit` each try.
|
|
36
|
+
* Headers from the overlay shallow-merge over the base. Useful for auth
|
|
37
|
+
* token refresh or user-agent rotation.
|
|
38
|
+
*/
|
|
39
|
+
prepareInit?: (attempt: number) => RequestInit | Promise<RequestInit>;
|
|
40
|
+
/**
|
|
41
|
+
* Optional `fetch` implementation override. Defaults to `globalThis.fetch`.
|
|
42
|
+
* Useful for routing requests through a proxy, instrumented transport, or
|
|
43
|
+
* mock during tests.
|
|
44
|
+
*/
|
|
45
|
+
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fetch with bounded retries and sensible defaults. Retries on any
|
|
49
|
+
* `isRetryableStatus` (5xx, 408, 429) and on transient network errors. Server
|
|
50
|
+
* `Retry-After`/quota hints are honoured up to `maxDelayMs`; a hint that exceeds
|
|
51
|
+
* the cap returns the current response so the caller can fail fast. Aborts on
|
|
52
|
+
* `init.signal` propagate as `"Request was aborted"`.
|
|
53
|
+
*
|
|
54
|
+
* The caller is responsible for inspecting `!response.ok` once the call returns.
|
|
55
|
+
*/
|
|
56
|
+
export declare function fetchWithRetry(url: string | URL | ((attempt: number) => string | URL), options?: FetchWithRetryOptions): Promise<Response>;
|
|
57
|
+
/**
|
|
58
|
+
* Inspect an arbitrary error value (or its `cause` chain, up to depth 2) for an
|
|
59
|
+
* HTTP status code. Reads `status`, `statusCode`, and `response.status` fields,
|
|
60
|
+
* coerces string values, and falls back to scanning the error message for
|
|
61
|
+
* common patterns like `Error: 401`, `error (429)`, or `HTTP 503`.
|
|
62
|
+
*/
|
|
63
|
+
export declare function extractHttpStatusFromError(error: unknown): number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* `true` if the given HTTP status code is one we treat as transient: 408
|
|
66
|
+
* (Request Timeout), 429 (Too Many Requests), or any 5xx (server error).
|
|
67
|
+
*/
|
|
68
|
+
export declare function isRetryableStatus(status: number): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* `true` if the message describes an unexpected socket closure — Bun and some
|
|
71
|
+
* proxies surface these for any HTTP/2 stream reset.
|
|
72
|
+
*/
|
|
73
|
+
export declare function isUnexpectedSocketCloseMessage(message: string): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Identify errors that should be retried: aborts/timeouts in the error name or
|
|
76
|
+
* message, retryable HTTP statuses (see `isRetryableStatus`), unexpected socket
|
|
77
|
+
* closes, and the standard transient phrases. 4xx statuses other than 408/429
|
|
78
|
+
* and validation-shaped messages short-circuit to `false`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format a duration in milliseconds to a short human-readable string.
|
|
3
|
+
* Examples: "123ms", "1.5s", "30m15s", "2h30m", "3d2h"
|
|
4
|
+
*/
|
|
5
|
+
export declare function formatDuration(ms: number): string;
|
|
6
|
+
/**
|
|
7
|
+
* Format a number with K/M/B suffix for compact display.
|
|
8
|
+
* Uses 1 decimal for small leading digits when non-zero, rounded otherwise.
|
|
9
|
+
* Examples: "999", "1K", "1.5K", "25K", "1M", "1.5M", "25M", "1.5B"
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatNumber(n: number): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a byte count to a human-readable string.
|
|
14
|
+
* Examples: "512B", "1.5KB", "2.3MB", "1.2GB"
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatBytes(bytes: number): string;
|
|
17
|
+
/**
|
|
18
|
+
* Truncate a string to maxLen characters, appending an ellipsis if truncated.
|
|
19
|
+
* For display-width-aware truncation (terminals), use truncateToWidth from @sayknow-cli/tui.
|
|
20
|
+
*/
|
|
21
|
+
export declare function truncate(str: string, maxLen: number, ellipsis?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Format count with pluralized label (e.g., "3 files", "1 error").
|
|
24
|
+
*/
|
|
25
|
+
export declare function formatCount(label: string, count: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Format age from seconds to human-readable string.
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatAge(ageSeconds: number | null | undefined): string;
|
|
30
|
+
/**
|
|
31
|
+
* Pluralize a label based on the count.
|
|
32
|
+
*/
|
|
33
|
+
export declare function pluralize(label: string, count: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Format a ratio as a percentage.
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatPercent(ratio: number): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class FrontmatterError extends Error {
|
|
2
|
+
readonly source?: unknown | undefined;
|
|
3
|
+
constructor(error: Error, source?: unknown | undefined);
|
|
4
|
+
toString(): string;
|
|
5
|
+
}
|
|
6
|
+
export interface FrontmatterOptions {
|
|
7
|
+
/** Source of the content (alias: source) */
|
|
8
|
+
location?: unknown;
|
|
9
|
+
/** Source of the content (alias for location) */
|
|
10
|
+
source?: unknown;
|
|
11
|
+
/** Fallback frontmatter values */
|
|
12
|
+
fallback?: Record<string, unknown>;
|
|
13
|
+
/** Normalize the content */
|
|
14
|
+
normalize?: boolean;
|
|
15
|
+
/** Level of error handling */
|
|
16
|
+
level?: "off" | "warn" | "fatal";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Parse YAML frontmatter from markdown content
|
|
20
|
+
* Returns { frontmatter, body } where body has frontmatter stripped
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseFrontmatter(content: string, options?: FrontmatterOptions): {
|
|
23
|
+
frontmatter: Record<string, unknown>;
|
|
24
|
+
body: string;
|
|
25
|
+
};
|