@bumpyclock/pi-tasque 0.2.0 → 0.2.1

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.
@@ -2,6 +2,7 @@ import type {
2
2
  ExtensionAPI,
3
3
  ExtensionContext,
4
4
  } from "@earendil-works/pi-coding-agent";
5
+ import { isRecord } from "../shared/error-utils.js";
5
6
  import {
6
7
  TODO_PROMPT_GUIDELINES,
7
8
  TODO_PROMPT_SNIPPET,
@@ -232,7 +233,3 @@ function isSuccessfulToolExecutionResult(event: {
232
233
  if (details.ok === false) return false;
233
234
  return details.error === undefined;
234
235
  }
235
-
236
- function isRecord(value: unknown): value is Record<string, unknown> {
237
- return typeof value === "object" && value !== null && !Array.isArray(value);
238
- }
@@ -0,0 +1,29 @@
1
+ export function asRecord(value: unknown): Record<string, unknown> | undefined {
2
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
3
+ return undefined;
4
+ }
5
+ return value as Record<string, unknown>;
6
+ }
7
+
8
+ export function isRecord(value: unknown): value is Record<string, unknown> {
9
+ return typeof value === "object" && value !== null && !Array.isArray(value);
10
+ }
11
+
12
+ export function copyKnownErrorFields(error: Error): Record<string, unknown> {
13
+ const record = error as unknown as Record<string, unknown>;
14
+ const output: Record<string, unknown> = {};
15
+ for (const key of [
16
+ "code",
17
+ "command",
18
+ "details",
19
+ "stderr",
20
+ "stdout",
21
+ "killed",
22
+ "args",
23
+ ] as const) {
24
+ if (record[key] !== undefined) {
25
+ output[key] = record[key];
26
+ }
27
+ }
28
+ return output;
29
+ }
@@ -0,0 +1,25 @@
1
+ export function definedParams<T>(params: Record<string, unknown>): T {
2
+ const output: Record<string, unknown> = {};
3
+ for (const [key, value] of Object.entries(params)) {
4
+ if (value !== undefined) {
5
+ output[key] = value;
6
+ }
7
+ }
8
+ return output as T;
9
+ }
10
+
11
+ export function fieldRequired(field: string): {
12
+ readonly ok: false;
13
+ readonly message: string;
14
+ } {
15
+ return { ok: false, message: `${field} is required` };
16
+ }
17
+
18
+ export function requireStringField(
19
+ value: string | undefined,
20
+ field: string,
21
+ ): { readonly ok: true } | { readonly ok: false; readonly message: string } {
22
+ return typeof value === "string" && value.trim().length > 0
23
+ ? { ok: true }
24
+ : fieldRequired(field);
25
+ }