@blogic-cz/agent-tools 0.1.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.
Files changed (42) hide show
  1. package/README.md +68 -30
  2. package/package.json +7 -4
  3. package/schemas/agent-tools.schema.json +4 -0
  4. package/src/az-tool/build.ts +5 -0
  5. package/src/az-tool/errors.ts +12 -0
  6. package/src/az-tool/index.ts +129 -105
  7. package/src/az-tool/service.ts +13 -4
  8. package/src/config/index.ts +7 -1
  9. package/src/config/loader.ts +8 -0
  10. package/src/config/types.ts +2 -0
  11. package/src/credential-guard/index.ts +2 -1
  12. package/src/db-tool/config-service.ts +2 -2
  13. package/src/db-tool/errors.ts +15 -0
  14. package/src/db-tool/index.ts +47 -8
  15. package/src/db-tool/types.ts +1 -1
  16. package/src/gh-tool/errors.ts +15 -0
  17. package/src/gh-tool/index.ts +5 -1
  18. package/src/gh-tool/issue.ts +1 -1
  19. package/src/gh-tool/pr/commands.ts +58 -3
  20. package/src/gh-tool/pr/core.ts +28 -7
  21. package/src/gh-tool/pr/helpers.ts +1 -1
  22. package/src/gh-tool/pr/index.ts +2 -0
  23. package/src/gh-tool/pr/review.ts +10 -6
  24. package/src/gh-tool/repo.ts +1 -1
  25. package/src/gh-tool/service.ts +5 -0
  26. package/src/gh-tool/workflow.ts +5 -1
  27. package/src/k8s-tool/errors.ts +9 -0
  28. package/src/k8s-tool/index.ts +318 -66
  29. package/src/k8s-tool/service.ts +2 -2
  30. package/src/k8s-tool/types.ts +4 -0
  31. package/src/logs-tool/errors.ts +12 -0
  32. package/src/logs-tool/index.ts +73 -11
  33. package/src/logs-tool/service.ts +4 -4
  34. package/src/logs-tool/types.ts +4 -1
  35. package/src/session-tool/config.ts +1 -1
  36. package/src/session-tool/index.ts +1 -1
  37. package/src/session-tool/service.ts +16 -3
  38. package/src/session-tool/types.ts +1 -1
  39. package/src/shared/bun.ts +1 -1
  40. package/src/shared/error-renderer.ts +21 -11
  41. package/src/shared/index.ts +1 -0
  42. package/src/shared/types.ts +3 -0
@@ -51,8 +51,10 @@ const readJsonFilesInTree = (parentDir: string): Effect.Effect<FileEntry[], Sess
51
51
  const subPath = `${parentDir}/${subDir}`;
52
52
  let files: string[];
53
53
  try {
54
+ // eslint-disable-next-line eslint/no-await-in-loop -- sequential directory walk, each iteration may short-circuit
54
55
  files = await readdir(subPath);
55
56
  } catch {
57
+ /* ignore unreadable files */
56
58
  continue;
57
59
  }
58
60
 
@@ -63,8 +65,11 @@ const readJsonFilesInTree = (parentDir: string): Effect.Effect<FileEntry[], Sess
63
65
  try {
64
66
  const content = await Bun.file(filePath).text();
65
67
  results.push({ filePath, content });
66
- } catch {}
68
+ } catch {
69
+ /* ignore unreadable files */
70
+ }
67
71
  });
72
+ // eslint-disable-next-line eslint/no-await-in-loop -- sequential directory walk, each iteration may short-circuit
68
73
  await Promise.all(reads);
69
74
  }
70
75
 
@@ -90,7 +95,9 @@ const readJsonFilesFlat = (dir: string): Effect.Effect<FileEntry[], SessionError
90
95
  try {
91
96
  const content = await Bun.file(filePath).text();
92
97
  results.push({ filePath, content });
93
- } catch {}
98
+ } catch {
99
+ /* ignore unreadable files */
100
+ }
94
101
  });
95
102
  await Promise.all(reads);
96
103
 
@@ -191,7 +198,13 @@ export class SessionService extends ServiceMap.Service<
191
198
  }
192
199
  }
193
200
 
194
- return summaries.sort((left, right) => right.created - left.created);
201
+ return (
202
+ summaries as MessageSummary[] & {
203
+ toSorted(
204
+ compareFn: (left: MessageSummary, right: MessageSummary) => number,
205
+ ): MessageSummary[];
206
+ }
207
+ ).toSorted((left, right) => right.created - left.created);
195
208
  }),
196
209
 
197
210
  searchSummaries: (summaries: MessageSummary[], query: string): MessageSummary[] => {
@@ -1,4 +1,4 @@
1
- import type { OutputFormat } from "../shared";
1
+ import type { OutputFormat } from "#src/shared";
2
2
 
3
3
  export type { OutputFormat };
4
4
 
package/src/shared/bun.ts CHANGED
@@ -51,7 +51,7 @@ export async function runCommand(
51
51
  };
52
52
  }
53
53
 
54
- export async function runShellCommand(
54
+ export function runShellCommand(
55
55
  command: string,
56
56
  options: CommandOptions = {},
57
57
  ): Promise<CommandResult> {
@@ -11,12 +11,21 @@ const formatError = (error: unknown): string => {
11
11
  ) {
12
12
  const tag = (error as Record<string, unknown>)._tag as string;
13
13
  const message = (error as Record<string, unknown>).message;
14
- if (typeof message === "string") return `${tag}: ${message}`;
15
- const details = Object.entries(error as Record<string, unknown>)
16
- .filter(([key, val]) => typeof val === "string" && key !== "_tag")
17
- .map(([key, val]) => `${key}=${String(val)}`)
18
- .join(", ");
19
- return details ? `${tag}: ${details}` : tag;
14
+ const hint = (error as Record<string, unknown>).hint;
15
+ let result = "";
16
+ if (typeof message === "string") {
17
+ result = `${tag}: ${message}`;
18
+ } else {
19
+ const details = Object.entries(error as Record<string, unknown>)
20
+ .filter(([key, val]) => typeof val === "string" && key !== "_tag" && key !== "hint")
21
+ .map(([key, val]) => `${key}=${String(val)}`)
22
+ .join(", ");
23
+ result = details ? `${tag}: ${details}` : tag;
24
+ }
25
+ if (typeof hint === "string") {
26
+ result += `\n Hint: ${hint}`;
27
+ }
28
+ return result;
20
29
  }
21
30
  if (error instanceof Error) return error.message;
22
31
  return String(error);
@@ -24,14 +33,15 @@ const formatError = (error: unknown): string => {
24
33
 
25
34
  const formatCause = (cause: Cause.Cause<unknown>): string => {
26
35
  const failures = cause.reasons.filter(Cause.isFailReason);
27
- const firstFailure = Array.from(failures)[0];
28
- if (firstFailure !== undefined) return formatError(firstFailure);
36
+ const firstFailure = failures[0];
37
+ if (firstFailure !== undefined) return formatError(firstFailure.error);
29
38
 
30
39
  const defects = cause.reasons.filter(Cause.isDieReason);
31
- const firstDefect = Array.from(defects)[0];
40
+ const firstDefect = defects[0];
32
41
  if (firstDefect !== undefined) {
33
- if (firstDefect instanceof Error) return `Unexpected error: ${firstDefect.message}`;
34
- return `Unexpected error: ${String(firstDefect)}`;
42
+ if (firstDefect.defect instanceof Error)
43
+ return `Unexpected error: ${firstDefect.defect.message}`;
44
+ return `Unexpected error: ${String(firstDefect.defect)}`;
35
45
  }
36
46
 
37
47
  if (Cause.hasInterruptsOnly(cause)) return "Interrupted";
@@ -8,6 +8,7 @@ export { commonArgOptions, parseCommonArgs } from "./cli";
8
8
 
9
9
  export { renderCauseToStderr } from "./error-renderer";
10
10
 
11
+ // eslint-disable-next-line import/no-relative-parent-imports -- package.json lives at project root, outside src/
11
12
  import pkg from "../../package.json" with { type: "json" };
12
13
  export const VERSION = pkg.version;
13
14
 
@@ -5,6 +5,9 @@ export type BaseResult = {
5
5
  success: boolean;
6
6
  error?: string;
7
7
  executionTimeMs: number;
8
+ nextCommand?: string;
9
+ retryable?: boolean;
10
+ hint?: string;
8
11
  };
9
12
 
10
13
  export type CommandOptions = {