@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.
- package/LICENSE +21 -0
- package/README.md +236 -0
- package/package.json +70 -0
- package/schemas/agent-tools.schema.json +319 -0
- package/src/az-tool/build.ts +295 -0
- package/src/az-tool/config.ts +33 -0
- package/src/az-tool/errors.ts +26 -0
- package/src/az-tool/extract-option-value.ts +12 -0
- package/src/az-tool/index.ts +181 -0
- package/src/az-tool/security.ts +130 -0
- package/src/az-tool/service.ts +292 -0
- package/src/az-tool/types.ts +67 -0
- package/src/config/index.ts +12 -0
- package/src/config/loader.ts +170 -0
- package/src/config/types.ts +82 -0
- package/src/credential-guard/claude-hook.ts +28 -0
- package/src/credential-guard/index.ts +435 -0
- package/src/db-tool/config-service.ts +38 -0
- package/src/db-tool/errors.ts +40 -0
- package/src/db-tool/index.ts +91 -0
- package/src/db-tool/schema.ts +69 -0
- package/src/db-tool/security.ts +116 -0
- package/src/db-tool/service.ts +605 -0
- package/src/db-tool/types.ts +33 -0
- package/src/gh-tool/config.ts +7 -0
- package/src/gh-tool/errors.ts +47 -0
- package/src/gh-tool/index.ts +140 -0
- package/src/gh-tool/issue.ts +361 -0
- package/src/gh-tool/pr/commands.ts +432 -0
- package/src/gh-tool/pr/core.ts +497 -0
- package/src/gh-tool/pr/helpers.ts +84 -0
- package/src/gh-tool/pr/index.ts +19 -0
- package/src/gh-tool/pr/review.ts +571 -0
- package/src/gh-tool/repo.ts +147 -0
- package/src/gh-tool/service.ts +192 -0
- package/src/gh-tool/types.ts +97 -0
- package/src/gh-tool/workflow.ts +542 -0
- package/src/index.ts +1 -0
- package/src/k8s-tool/errors.ts +21 -0
- package/src/k8s-tool/index.ts +151 -0
- package/src/k8s-tool/service.ts +227 -0
- package/src/k8s-tool/types.ts +9 -0
- package/src/logs-tool/errors.ts +29 -0
- package/src/logs-tool/index.ts +176 -0
- package/src/logs-tool/service.ts +323 -0
- package/src/logs-tool/types.ts +40 -0
- package/src/session-tool/config.ts +55 -0
- package/src/session-tool/errors.ts +38 -0
- package/src/session-tool/index.ts +270 -0
- package/src/session-tool/service.ts +210 -0
- package/src/session-tool/types.ts +28 -0
- package/src/shared/bun.ts +59 -0
- package/src/shared/cli.ts +38 -0
- package/src/shared/error-renderer.ts +42 -0
- package/src/shared/exec.ts +62 -0
- package/src/shared/format.ts +27 -0
- package/src/shared/index.ts +16 -0
- package/src/shared/throttle.ts +35 -0
- package/src/shared/types.ts +25 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { SchemaErrorInfo } from "./types";
|
|
2
|
+
|
|
3
|
+
const MUTATION_PATTERNS = [
|
|
4
|
+
/^\s*UPDATE\s+/i,
|
|
5
|
+
/^\s*INSERT\s+/i,
|
|
6
|
+
/^\s*DELETE\s+/i,
|
|
7
|
+
/^\s*TRUNCATE\s+/i,
|
|
8
|
+
/^\s*DROP\s+/i,
|
|
9
|
+
/^\s*ALTER\s+/i,
|
|
10
|
+
/^\s*CREATE\s+/i,
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
const TABLE_NAME_PATTERN = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Strip SQL comments (block and line) while preserving string literals.
|
|
17
|
+
* This prevents bypass via inline comment masking before DELETE statements.
|
|
18
|
+
*/
|
|
19
|
+
export function stripSqlComments(sql: string): string {
|
|
20
|
+
let result = "";
|
|
21
|
+
let i = 0;
|
|
22
|
+
const len = sql.length;
|
|
23
|
+
|
|
24
|
+
while (i < len) {
|
|
25
|
+
const ch = sql[i];
|
|
26
|
+
const next = i + 1 < len ? sql[i + 1] : "";
|
|
27
|
+
|
|
28
|
+
// Single-quoted string literal — skip through
|
|
29
|
+
if (ch === "'") {
|
|
30
|
+
result += ch;
|
|
31
|
+
i++;
|
|
32
|
+
while (i < len) {
|
|
33
|
+
if (sql[i] === "'" && i + 1 < len && sql[i + 1] === "'") {
|
|
34
|
+
result += "''";
|
|
35
|
+
i += 2;
|
|
36
|
+
} else if (sql[i] === "'") {
|
|
37
|
+
result += "'";
|
|
38
|
+
i++;
|
|
39
|
+
break;
|
|
40
|
+
} else {
|
|
41
|
+
result += sql[i];
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Block comment /* ... */
|
|
49
|
+
if (ch === "/" && next === "*") {
|
|
50
|
+
i += 2;
|
|
51
|
+
while (i + 1 < len && !(sql[i] === "*" && sql[i + 1] === "/")) {
|
|
52
|
+
i++;
|
|
53
|
+
}
|
|
54
|
+
i += 2; // skip closing */
|
|
55
|
+
result += " "; // replace comment with space
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Line comment -- ...
|
|
60
|
+
if (ch === "-" && next === "-") {
|
|
61
|
+
i += 2;
|
|
62
|
+
while (i < len && sql[i] !== "\n") {
|
|
63
|
+
i++;
|
|
64
|
+
}
|
|
65
|
+
result += " ";
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
result += ch;
|
|
70
|
+
i++;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function isMutationQuery(sql: string): boolean {
|
|
77
|
+
const stripped = stripSqlComments(sql);
|
|
78
|
+
return MUTATION_PATTERNS.some((pattern) => pattern.test(stripped));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function isValidTableName(tableName: string): boolean {
|
|
82
|
+
return TABLE_NAME_PATTERN.test(tableName);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function detectSchemaError(stderr: string, sql: string): SchemaErrorInfo {
|
|
86
|
+
const trimmedError = stderr.trim();
|
|
87
|
+
|
|
88
|
+
if (!trimmedError.includes("does not exist")) {
|
|
89
|
+
return {
|
|
90
|
+
type: null,
|
|
91
|
+
missingName: null,
|
|
92
|
+
tableName: null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const relationMatch = trimmedError.match(/relation "([^"]+)" does not exist/);
|
|
97
|
+
if (relationMatch) {
|
|
98
|
+
return {
|
|
99
|
+
type: "table_not_found",
|
|
100
|
+
missingName: relationMatch[1],
|
|
101
|
+
tableName: null,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const columnMatch = trimmedError.match(/column "([^"]+)" does not exist/);
|
|
106
|
+
if (columnMatch) {
|
|
107
|
+
const tableFromSql = sql.match(/FROM\s+["']?(\w+)["']?/i);
|
|
108
|
+
return {
|
|
109
|
+
type: "column_not_found",
|
|
110
|
+
missingName: columnMatch[1],
|
|
111
|
+
tableName: tableFromSql?.[1] ?? null,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { type: null, missingName: null, tableName: null };
|
|
116
|
+
}
|