@blogic-cz/agent-tools 0.1.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +236 -0
  3. package/package.json +70 -0
  4. package/schemas/agent-tools.schema.json +319 -0
  5. package/src/az-tool/build.ts +295 -0
  6. package/src/az-tool/config.ts +33 -0
  7. package/src/az-tool/errors.ts +26 -0
  8. package/src/az-tool/extract-option-value.ts +12 -0
  9. package/src/az-tool/index.ts +181 -0
  10. package/src/az-tool/security.ts +130 -0
  11. package/src/az-tool/service.ts +292 -0
  12. package/src/az-tool/types.ts +67 -0
  13. package/src/config/index.ts +12 -0
  14. package/src/config/loader.ts +170 -0
  15. package/src/config/types.ts +82 -0
  16. package/src/credential-guard/claude-hook.ts +28 -0
  17. package/src/credential-guard/index.ts +435 -0
  18. package/src/db-tool/config-service.ts +38 -0
  19. package/src/db-tool/errors.ts +40 -0
  20. package/src/db-tool/index.ts +91 -0
  21. package/src/db-tool/schema.ts +69 -0
  22. package/src/db-tool/security.ts +116 -0
  23. package/src/db-tool/service.ts +605 -0
  24. package/src/db-tool/types.ts +33 -0
  25. package/src/gh-tool/config.ts +7 -0
  26. package/src/gh-tool/errors.ts +47 -0
  27. package/src/gh-tool/index.ts +140 -0
  28. package/src/gh-tool/issue.ts +361 -0
  29. package/src/gh-tool/pr/commands.ts +432 -0
  30. package/src/gh-tool/pr/core.ts +497 -0
  31. package/src/gh-tool/pr/helpers.ts +84 -0
  32. package/src/gh-tool/pr/index.ts +19 -0
  33. package/src/gh-tool/pr/review.ts +571 -0
  34. package/src/gh-tool/repo.ts +147 -0
  35. package/src/gh-tool/service.ts +192 -0
  36. package/src/gh-tool/types.ts +97 -0
  37. package/src/gh-tool/workflow.ts +542 -0
  38. package/src/index.ts +1 -0
  39. package/src/k8s-tool/errors.ts +21 -0
  40. package/src/k8s-tool/index.ts +151 -0
  41. package/src/k8s-tool/service.ts +227 -0
  42. package/src/k8s-tool/types.ts +9 -0
  43. package/src/logs-tool/errors.ts +29 -0
  44. package/src/logs-tool/index.ts +176 -0
  45. package/src/logs-tool/service.ts +323 -0
  46. package/src/logs-tool/types.ts +40 -0
  47. package/src/session-tool/config.ts +55 -0
  48. package/src/session-tool/errors.ts +38 -0
  49. package/src/session-tool/index.ts +270 -0
  50. package/src/session-tool/service.ts +210 -0
  51. package/src/session-tool/types.ts +28 -0
  52. package/src/shared/bun.ts +59 -0
  53. package/src/shared/cli.ts +38 -0
  54. package/src/shared/error-renderer.ts +42 -0
  55. package/src/shared/exec.ts +62 -0
  56. package/src/shared/format.ts +27 -0
  57. package/src/shared/index.ts +16 -0
  58. package/src/shared/throttle.ts +35 -0
  59. package/src/shared/types.ts +25 -0
@@ -0,0 +1,62 @@
1
+ import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
2
+ import { Effect, Schema, Stream } from "effect";
3
+
4
+ const DEFAULT_TIMEOUT_MS = 30000;
5
+
6
+ export class ExecError extends Schema.TaggedErrorClass<ExecError>()("ExecError", {
7
+ message: Schema.String,
8
+ command: Schema.String,
9
+ exitCode: Schema.Number,
10
+ stderr: Schema.String,
11
+ }) {}
12
+
13
+ export const execEffect = (
14
+ commandStr: string,
15
+ timeoutMs: number = DEFAULT_TIMEOUT_MS,
16
+ ): Effect.Effect<
17
+ { stdout: string; stderr: string; exitCode: number },
18
+ ExecError,
19
+ ChildProcessSpawner.ChildProcessSpawner
20
+ > =>
21
+ Effect.scoped(
22
+ Effect.gen(function* () {
23
+ const executor = yield* ChildProcessSpawner.ChildProcessSpawner;
24
+
25
+ const command = ChildProcess.make("sh", ["-c", commandStr], {
26
+ stdout: "pipe",
27
+ stderr: "pipe",
28
+ });
29
+
30
+ const process = yield* executor.spawn(command);
31
+
32
+ const stdoutChunk = yield* process.stdout.pipe(Stream.decodeText(), Stream.runCollect);
33
+ const stderrChunk = yield* process.stderr.pipe(Stream.decodeText(), Stream.runCollect);
34
+
35
+ const stdout = stdoutChunk.join("");
36
+ const stderr = stderrChunk.join("");
37
+ const exitCode = yield* process.exitCode;
38
+
39
+ if (exitCode !== 0) {
40
+ return yield* new ExecError({
41
+ message: stderr || `Command failed with exit code ${exitCode}`,
42
+ command: commandStr,
43
+ exitCode,
44
+ stderr,
45
+ });
46
+ }
47
+
48
+ return { stdout, stderr, exitCode };
49
+ }),
50
+ ).pipe(
51
+ Effect.timeout(timeoutMs),
52
+ Effect.catch((error: unknown) =>
53
+ Effect.fail(
54
+ new ExecError({
55
+ message: `Command execution failed: ${String(error)}`,
56
+ command: commandStr,
57
+ exitCode: -1,
58
+ stderr: String(error),
59
+ }),
60
+ ),
61
+ ),
62
+ );
@@ -0,0 +1,27 @@
1
+ import { Flag } from "effect/unstable/cli";
2
+ import { encode as encodeToon } from "@toon-format/toon";
3
+ import { Console } from "effect";
4
+
5
+ import type { BaseResult, OutputFormat } from "./types";
6
+
7
+ export const formatOption = Flag.choice("format", ["toon", "json"]).pipe(
8
+ Flag.withDescription("Output format: toon (default, token-efficient) or json"),
9
+ Flag.withDefault("toon"),
10
+ );
11
+
12
+ export function formatOutput<T extends BaseResult>(result: T, format: OutputFormat): string {
13
+ if (format === "toon") {
14
+ return encodeToon(result);
15
+ }
16
+ return JSON.stringify(result, null, 2);
17
+ }
18
+
19
+ export function formatAny<T>(data: T, format: OutputFormat): string {
20
+ if (format === "toon") {
21
+ return encodeToon(data);
22
+ }
23
+ return JSON.stringify(data, null, 2);
24
+ }
25
+
26
+ export const logFormatted = <T>(data: T, format: OutputFormat) =>
27
+ Console.log(formatAny(data, format));
@@ -0,0 +1,16 @@
1
+ export type { BaseResult, CommandOptions, CommandResult, Environment, OutputFormat } from "./types";
2
+
3
+ export { formatAny, formatOption, formatOutput, logFormatted } from "./format";
4
+
5
+ export { expandPath, runCommand, runShellCommand } from "./bun";
6
+
7
+ export { commonArgOptions, parseCommonArgs } from "./cli";
8
+
9
+ export { renderCauseToStderr } from "./error-renderer";
10
+
11
+ import pkg from "../../package.json" with { type: "json" };
12
+ export const VERSION = pkg.version;
13
+
14
+ export { execEffect, type ExecError } from "./exec";
15
+
16
+ export { createThrottle, type ThrottleError } from "./throttle";
@@ -0,0 +1,35 @@
1
+ import { Effect, Ref, Schema } from "effect";
2
+
3
+ const WINDOW_MS = 60000;
4
+
5
+ export class ThrottleError extends Schema.TaggedErrorClass<ThrottleError>()("ThrottleError", {
6
+ message: Schema.String,
7
+ label: Schema.String,
8
+ limit: Schema.Number,
9
+ windowMs: Schema.Number,
10
+ }) {}
11
+
12
+ export const createThrottle = (opts: { maxPerMinute: number; label: string }) => {
13
+ const timestampsRef = Effect.runSync(Ref.make<number[]>([]));
14
+
15
+ const check = (): Effect.Effect<void, ThrottleError> =>
16
+ Effect.gen(function* () {
17
+ const now = Date.now();
18
+ const windowStart = now - WINDOW_MS;
19
+ const timestamps = yield* Ref.get(timestampsRef);
20
+ const recentTimestamps = timestamps.filter((timestamp) => timestamp >= windowStart);
21
+
22
+ if (recentTimestamps.length >= opts.maxPerMinute) {
23
+ return yield* new ThrottleError({
24
+ message: `Rate limit exceeded for ${opts.label}`,
25
+ label: opts.label,
26
+ limit: opts.maxPerMinute,
27
+ windowMs: WINDOW_MS,
28
+ });
29
+ }
30
+
31
+ yield* Ref.set(timestampsRef, [...recentTimestamps, now]);
32
+ });
33
+
34
+ return { check };
35
+ };
@@ -0,0 +1,25 @@
1
+ export type OutputFormat = "json" | "toon";
2
+ export type Environment = "local" | "test" | "prod";
3
+
4
+ export type BaseResult = {
5
+ success: boolean;
6
+ error?: string;
7
+ executionTimeMs: number;
8
+ };
9
+
10
+ export type CommandOptions = {
11
+ cwd?: string;
12
+ env?: Record<string, string>;
13
+ timeout?: number;
14
+ killSignal?: NodeJS.Signals;
15
+ };
16
+
17
+ export type CommandResult = {
18
+ success: boolean;
19
+ stdout: string;
20
+ stderr: string;
21
+ exitCode: number;
22
+ signalCode: NodeJS.Signals | null;
23
+ timedOut: boolean;
24
+ executionTimeMs: number;
25
+ };