@sayknow-cli/utils 0.7.10 → 0.7.12

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 (49) hide show
  1. package/dist/types/broken-pipe.d.ts +4 -3
  2. package/dist/types/canonical-log-dir.d.ts +20 -0
  3. package/dist/types/cli-metadata.d.ts +33 -0
  4. package/dist/types/cli.d.ts +12 -0
  5. package/dist/types/crash-fingerprint.d.ts +82 -0
  6. package/dist/types/crash-journal.d.ts +84 -0
  7. package/dist/types/crash-redaction.d.ts +20 -0
  8. package/dist/types/dirs.d.ts +127 -36
  9. package/dist/types/env-file.d.ts +59 -0
  10. package/dist/types/env.d.ts +19 -1
  11. package/dist/types/error-classification.d.ts +12 -0
  12. package/dist/types/fetch-retry.d.ts +6 -3
  13. package/dist/types/header-value.d.ts +10 -0
  14. package/dist/types/index.d.ts +6 -0
  15. package/dist/types/logger.d.ts +22 -8
  16. package/dist/types/native-process.d.ts +12 -0
  17. package/dist/types/procmgr.d.ts +1 -35
  18. package/dist/types/safe-error.d.ts +20 -0
  19. package/dist/types/sanitize-text.d.ts +10 -0
  20. package/dist/types/shell-config.d.ts +58 -0
  21. package/dist/types/stream.d.ts +2 -1
  22. package/dist/types/which.d.ts +1 -1
  23. package/package.json +2 -2
  24. package/src/broken-pipe.ts +16 -4
  25. package/src/canonical-log-dir.ts +59 -0
  26. package/src/cli-metadata.ts +74 -0
  27. package/src/cli.ts +30 -2
  28. package/src/crash-fingerprint.ts +294 -0
  29. package/src/crash-journal.ts +292 -0
  30. package/src/crash-redaction.ts +558 -0
  31. package/src/dirs.ts +583 -165
  32. package/src/env-file.ts +326 -20
  33. package/src/env.ts +321 -35
  34. package/src/error-classification.ts +31 -0
  35. package/src/fetch-retry.ts +23 -10
  36. package/src/frontmatter.ts +28 -2
  37. package/src/glob.ts +13 -10
  38. package/src/header-value.ts +15 -0
  39. package/src/index.ts +6 -0
  40. package/src/logger.ts +252 -97
  41. package/src/native-process.ts +19 -0
  42. package/src/postmortem.ts +1 -55
  43. package/src/procmgr.ts +16 -212
  44. package/src/ptree.ts +3 -2
  45. package/src/safe-error.ts +40 -0
  46. package/src/sanitize-text.ts +14 -0
  47. package/src/shell-config.ts +329 -0
  48. package/src/stream.ts +32 -1
  49. package/src/which.ts +6 -5
package/src/stream.ts CHANGED
@@ -44,13 +44,44 @@ export async function* readLines(stream: ReadableStream<Uint8Array>, signal?: Ab
44
44
  }
45
45
  }
46
46
 
47
- export async function* readJsonl<T>(stream: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<T> {
47
+ export type JsonlLineObserver = (raw: string) => void;
48
+
49
+ function notifyJsonlLineObserver(observer: JsonlLineObserver | undefined, raw: string): void {
50
+ if (!observer) return;
51
+ try {
52
+ observer(raw);
53
+ } catch {
54
+ // Diagnostic observers must never perturb provider stream consumption.
55
+ }
56
+ }
57
+
58
+ export async function* readJsonl<T>(
59
+ stream: ReadableStream<Uint8Array>,
60
+ signal?: AbortSignal,
61
+ onLine?: JsonlLineObserver,
62
+ ): AsyncGenerator<T> {
48
63
  const buffer = new ConcatSink();
64
+ const rawLineState = onLine
65
+ ? {
66
+ buffer: new ConcatSink(),
67
+ decoder: new TextDecoder(),
68
+ }
69
+ : undefined;
49
70
  const source = createAbortableStream(stream, signal);
50
71
  try {
51
72
  for await (const chunk of source) {
73
+ if (rawLineState) {
74
+ for (const line of rawLineState.buffer.appendAndFlushLines(chunk)) {
75
+ notifyJsonlLineObserver(onLine, rawLineState.decoder.decode(line));
76
+ }
77
+ }
52
78
  yield* buffer.pullJSONL<T>(chunk, 0, chunk.length);
53
79
  }
80
+ if (rawLineState && !rawLineState.buffer.isEmpty) {
81
+ const rawTail = rawLineState.buffer.flush();
82
+ if (rawTail) notifyJsonlLineObserver(onLine, rawLineState.decoder.decode(rawTail));
83
+ rawLineState.buffer.clear();
84
+ }
54
85
  if (!buffer.isEmpty) {
55
86
  const tail = buffer.flush();
56
87
  if (tail) {
package/src/which.ts CHANGED
@@ -183,9 +183,10 @@ export interface WhichOptions extends Bun.WhichOptions {
183
183
 
184
184
  // Darwin-specific "which" shim: consult Xcode/CLT toolchain directories after $PATH.
185
185
  // Uses cached directory listings instead of per-command existsSync or xcrun subprocesses.
186
- function darwinWhich(command: string, _options?: Bun.WhichOptions): string | null {
187
- const regular = Bun.which(command);
186
+ function darwinWhich(command: string, options?: Bun.WhichOptions): string | null {
187
+ const regular = Bun.which(command, options);
188
188
  if (regular) return regular;
189
+ if (options?.PATH !== undefined) return null;
189
190
  if (isXcodeBin(command)) {
190
191
  return getMacosToolPaths().get(command) ?? null;
191
192
  }
@@ -198,10 +199,10 @@ export const whichFresh = os.platform() === "darwin" ? darwinWhich : Bun.which;
198
199
  // Derive stable cache key from command and lookup options
199
200
  function cacheKey(command: string, options?: Bun.WhichOptions): CacheKey {
200
201
  if (!options) return command;
201
- if (!options.cwd && !options.PATH) return command;
202
+ if (options.cwd === undefined && options.PATH === undefined) return command;
202
203
  let h = Bun.hash(command);
203
- if (options.cwd) h = Bun.hash(options.cwd, h);
204
- if (options.PATH) h = Bun.hash(options.PATH, h);
204
+ if (options.cwd !== undefined) h = Bun.hash(`cwd:${options.cwd}`, h);
205
+ if (options.PATH !== undefined) h = Bun.hash(`PATH:${options.PATH}`, h);
205
206
  return h;
206
207
  }
207
208