@kwirthmagnify/kwirth-common-ai 0.5.25 → 0.5.27
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/dist/back.d.ts +82 -0
- package/dist/back.js +152 -0
- package/package.json +1 -1
package/dist/back.d.ts
CHANGED
|
@@ -334,6 +334,88 @@ export declare const tools: {
|
|
|
334
334
|
count: number;
|
|
335
335
|
events: Record<string, unknown>[];
|
|
336
336
|
}>;
|
|
337
|
+
readonly get_pod_logs: import("ai").Tool<{
|
|
338
|
+
namespace: string;
|
|
339
|
+
name: string;
|
|
340
|
+
container?: string | undefined;
|
|
341
|
+
previous?: boolean | undefined;
|
|
342
|
+
tailLines?: number | undefined;
|
|
343
|
+
}, {
|
|
344
|
+
namespace: string;
|
|
345
|
+
name: string;
|
|
346
|
+
container: string | null;
|
|
347
|
+
previous: boolean;
|
|
348
|
+
truncated: boolean;
|
|
349
|
+
logs: string;
|
|
350
|
+
error?: undefined;
|
|
351
|
+
} | {
|
|
352
|
+
error: any;
|
|
353
|
+
namespace?: undefined;
|
|
354
|
+
name?: undefined;
|
|
355
|
+
container?: undefined;
|
|
356
|
+
previous?: undefined;
|
|
357
|
+
truncated?: undefined;
|
|
358
|
+
logs?: undefined;
|
|
359
|
+
}>;
|
|
360
|
+
readonly describe_pod: import("ai").Tool<{
|
|
361
|
+
namespace: string;
|
|
362
|
+
name: string;
|
|
363
|
+
}, {
|
|
364
|
+
name: string;
|
|
365
|
+
namespace: string;
|
|
366
|
+
phase: any;
|
|
367
|
+
node: any;
|
|
368
|
+
startTime: any;
|
|
369
|
+
reason: any;
|
|
370
|
+
message: any;
|
|
371
|
+
controlledBy: any;
|
|
372
|
+
conditions: any;
|
|
373
|
+
containers: any;
|
|
374
|
+
initContainers: any;
|
|
375
|
+
spec: {
|
|
376
|
+
containers: any;
|
|
377
|
+
restartPolicy: any;
|
|
378
|
+
};
|
|
379
|
+
error?: undefined;
|
|
380
|
+
} | {
|
|
381
|
+
error: any;
|
|
382
|
+
name?: undefined;
|
|
383
|
+
namespace?: undefined;
|
|
384
|
+
phase?: undefined;
|
|
385
|
+
node?: undefined;
|
|
386
|
+
startTime?: undefined;
|
|
387
|
+
reason?: undefined;
|
|
388
|
+
message?: undefined;
|
|
389
|
+
controlledBy?: undefined;
|
|
390
|
+
conditions?: undefined;
|
|
391
|
+
containers?: undefined;
|
|
392
|
+
initContainers?: undefined;
|
|
393
|
+
spec?: undefined;
|
|
394
|
+
}>;
|
|
395
|
+
readonly get_pod_yaml: import("ai").Tool<{
|
|
396
|
+
namespace: string;
|
|
397
|
+
name: string;
|
|
398
|
+
}, any>;
|
|
399
|
+
readonly get_deployment_yaml: import("ai").Tool<{
|
|
400
|
+
namespace: string;
|
|
401
|
+
name: string;
|
|
402
|
+
}, any>;
|
|
403
|
+
readonly get_rollout_history: import("ai").Tool<{
|
|
404
|
+
namespace: string;
|
|
405
|
+
name: string;
|
|
406
|
+
}, {
|
|
407
|
+
deployment: string;
|
|
408
|
+
namespace: string;
|
|
409
|
+
revisionCount: any;
|
|
410
|
+
revisions: any;
|
|
411
|
+
error?: undefined;
|
|
412
|
+
} | {
|
|
413
|
+
error: any;
|
|
414
|
+
deployment?: undefined;
|
|
415
|
+
namespace?: undefined;
|
|
416
|
+
revisionCount?: undefined;
|
|
417
|
+
revisions?: undefined;
|
|
418
|
+
}>;
|
|
337
419
|
};
|
|
338
420
|
export declare const toolInfoList: IToolInfo[];
|
|
339
421
|
export interface IAgentRunResult {
|
package/dist/back.js
CHANGED
|
@@ -755,6 +755,153 @@ exports.tools = {
|
|
|
755
755
|
return { count: evs.length, events: evs.map(summarizeClusterEvent) };
|
|
756
756
|
}
|
|
757
757
|
}),
|
|
758
|
+
// ── POD DIAGNOSIS ────────────────────────────────────────────────────────
|
|
759
|
+
get_pod_logs: (0, ai_1.tool)({
|
|
760
|
+
description: 'Returns recent container logs for a pod (equivalent to kubectl logs). For a crashing pod (CrashLoopBackOff) pass previous:true to read the CRASHED container instance logs — that is where the root cause usually is (the events only say it is restarting, not why).',
|
|
761
|
+
inputSchema: zod_1.z.object({
|
|
762
|
+
namespace: zod_1.z.string().describe('Namespace of the pod'),
|
|
763
|
+
name: zod_1.z.string().describe('Name of the pod'),
|
|
764
|
+
container: zod_1.z.string().optional().describe('Container name (omit to use the pod default / first container)'),
|
|
765
|
+
previous: zod_1.z.boolean().optional().describe('Read the previous (crashed/restarted) container instance logs — key for CrashLoopBackOff'),
|
|
766
|
+
tailLines: zod_1.z.number().optional().describe('How many trailing lines to return (default 200)')
|
|
767
|
+
}),
|
|
768
|
+
execute: async ({ namespace, name, container, previous, tailLines = 200 }) => {
|
|
769
|
+
var _a, _b;
|
|
770
|
+
ctx().trace('get_pod_logs', { namespace, name, container: container !== null && container !== void 0 ? container : '(default)', previous: !!previous, tailLines });
|
|
771
|
+
try {
|
|
772
|
+
const raw = await ctx().clusterInfo.coreApi.readNamespacedPodLog({ name, namespace, container, previous: !!previous, tailLines });
|
|
773
|
+
const text = typeof raw === 'string' ? raw : ((_a = raw === null || raw === void 0 ? void 0 : raw.body) !== null && _a !== void 0 ? _a : JSON.stringify(raw));
|
|
774
|
+
const truncated = text.length > 15000;
|
|
775
|
+
return { namespace, name, container: container !== null && container !== void 0 ? container : null, previous: !!previous, truncated, logs: truncated ? text.slice(-15000) : text };
|
|
776
|
+
}
|
|
777
|
+
catch (err) {
|
|
778
|
+
return { error: (_b = err.message) !== null && _b !== void 0 ? _b : String(err) };
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}),
|
|
782
|
+
describe_pod: (0, ai_1.tool)({
|
|
783
|
+
description: 'Returns a diagnostic summary of a pod (equivalent to kubectl describe pod): phase, conditions, and per-container status — waiting reason (CrashLoopBackOff/ImagePullBackOff…), last termination reason + exitCode (137=OOMKilled, 1=app error, 143=SIGTERM), restart count, image, resources and probes. Best first step to categorize a pod failure.',
|
|
784
|
+
inputSchema: zod_1.z.object({
|
|
785
|
+
namespace: zod_1.z.string().describe('Namespace of the pod'),
|
|
786
|
+
name: zod_1.z.string().describe('Name of the pod')
|
|
787
|
+
}),
|
|
788
|
+
execute: async ({ namespace, name }) => {
|
|
789
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
790
|
+
ctx().trace('describe_pod', { namespace, name });
|
|
791
|
+
try {
|
|
792
|
+
const c = ctx().clusterInfo;
|
|
793
|
+
const pod = await c.coreApi.readNamespacedPod({ name, namespace });
|
|
794
|
+
const spec = (_a = pod.spec) !== null && _a !== void 0 ? _a : {}, status = (_b = pod.status) !== null && _b !== void 0 ? _b : {};
|
|
795
|
+
// image = the tag (spec); imageID = the resolved digest (catches a mutable tag repushed with a broken build).
|
|
796
|
+
const containerStatus = (cs) => {
|
|
797
|
+
var _a, _b, _c, _d;
|
|
798
|
+
return ({
|
|
799
|
+
name: cs.name, image: cs.image, imageID: cs.imageID, ready: cs.ready, restartCount: cs.restartCount,
|
|
800
|
+
state: ((_a = cs.state) === null || _a === void 0 ? void 0 : _a.waiting) ? { waiting: { reason: cs.state.waiting.reason, message: cs.state.waiting.message } }
|
|
801
|
+
: ((_b = cs.state) === null || _b === void 0 ? void 0 : _b.terminated) ? { terminated: { reason: cs.state.terminated.reason, exitCode: cs.state.terminated.exitCode } }
|
|
802
|
+
: ((_c = cs.state) === null || _c === void 0 ? void 0 : _c.running) ? { running: { startedAt: cs.state.running.startedAt } } : cs.state,
|
|
803
|
+
lastTerminated: ((_d = cs.lastState) === null || _d === void 0 ? void 0 : _d.terminated) ? { reason: cs.lastState.terminated.reason, exitCode: cs.lastState.terminated.exitCode, signal: cs.lastState.terminated.signal, finishedAt: cs.lastState.terminated.finishedAt } : undefined
|
|
804
|
+
});
|
|
805
|
+
};
|
|
806
|
+
const specContainer = (ct) => ({ name: ct.name, image: ct.image, resources: ct.resources, livenessProbe: !!ct.livenessProbe, readinessProbe: !!ct.readinessProbe, startupProbe: !!ct.startupProbe });
|
|
807
|
+
// Resolve the owning controller (pod → ReplicaSet → Deployment) so the bot can call get_rollout_history directly.
|
|
808
|
+
let controlledBy = undefined;
|
|
809
|
+
const podOwner = ((_d = (_c = pod.metadata) === null || _c === void 0 ? void 0 : _c.ownerReferences) !== null && _d !== void 0 ? _d : [])[0];
|
|
810
|
+
if ((podOwner === null || podOwner === void 0 ? void 0 : podOwner.kind) === 'ReplicaSet') {
|
|
811
|
+
try {
|
|
812
|
+
const rs = await c.appsApi.readNamespacedReplicaSet({ name: podOwner.name, namespace });
|
|
813
|
+
const rsOwner = ((_f = (_e = rs.metadata) === null || _e === void 0 ? void 0 : _e.ownerReferences) !== null && _f !== void 0 ? _f : [])[0];
|
|
814
|
+
controlledBy = rsOwner ? { kind: rsOwner.kind, name: rsOwner.name } : { kind: 'ReplicaSet', name: podOwner.name };
|
|
815
|
+
}
|
|
816
|
+
catch (_m) {
|
|
817
|
+
controlledBy = { kind: 'ReplicaSet', name: podOwner.name };
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
else if (podOwner) {
|
|
821
|
+
controlledBy = { kind: podOwner.kind, name: podOwner.name }; // StatefulSet/DaemonSet/Job own pods directly
|
|
822
|
+
}
|
|
823
|
+
return {
|
|
824
|
+
name, namespace, phase: status.phase, node: spec.nodeName, startTime: status.startTime, reason: status.reason, message: status.message,
|
|
825
|
+
controlledBy, // e.g. { kind: 'Deployment', name: 'montag-agent' } → feed to get_rollout_history
|
|
826
|
+
conditions: ((_g = status.conditions) !== null && _g !== void 0 ? _g : []).map((c) => ({ type: c.type, status: c.status, reason: c.reason })),
|
|
827
|
+
containers: ((_h = status.containerStatuses) !== null && _h !== void 0 ? _h : []).map(containerStatus),
|
|
828
|
+
initContainers: ((_j = status.initContainerStatuses) !== null && _j !== void 0 ? _j : []).map(containerStatus),
|
|
829
|
+
spec: { containers: ((_k = spec.containers) !== null && _k !== void 0 ? _k : []).map(specContainer), restartPolicy: spec.restartPolicy }
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
catch (err) {
|
|
833
|
+
return { error: (_l = err.message) !== null && _l !== void 0 ? _l : String(err) };
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}),
|
|
837
|
+
get_pod_yaml: (0, ai_1.tool)({
|
|
838
|
+
description: 'Returns the full Kubernetes Pod manifest (equivalent to kubectl get pod -o yaml): complete spec (env, volumes, resources, probes) and status. Use for deeper misconfiguration analysis after describe_pod.',
|
|
839
|
+
inputSchema: zod_1.z.object({
|
|
840
|
+
namespace: zod_1.z.string().describe('Namespace of the pod'),
|
|
841
|
+
name: zod_1.z.string().describe('Name of the pod')
|
|
842
|
+
}),
|
|
843
|
+
execute: async ({ namespace, name }) => {
|
|
844
|
+
var _a;
|
|
845
|
+
ctx().trace('get_pod_yaml', { namespace, name });
|
|
846
|
+
try {
|
|
847
|
+
return await ctx().clusterInfo.coreApi.readNamespacedPod({ name, namespace });
|
|
848
|
+
}
|
|
849
|
+
catch (err) {
|
|
850
|
+
return { error: (_a = err.message) !== null && _a !== void 0 ? _a : String(err) };
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}),
|
|
854
|
+
get_deployment_yaml: (0, ai_1.tool)({
|
|
855
|
+
description: 'Returns the full Kubernetes Deployment manifest (equivalent to kubectl get deployment -o yaml): the pod template (image, env, resources, probes) and strategy. Use to check if a pod problem comes from the owning workload spec.',
|
|
856
|
+
inputSchema: zod_1.z.object({
|
|
857
|
+
namespace: zod_1.z.string().describe('Namespace of the deployment'),
|
|
858
|
+
name: zod_1.z.string().describe('Name of the deployment')
|
|
859
|
+
}),
|
|
860
|
+
execute: async ({ namespace, name }) => {
|
|
861
|
+
var _a;
|
|
862
|
+
ctx().trace('get_deployment_yaml', { namespace, name });
|
|
863
|
+
try {
|
|
864
|
+
return await ctx().clusterInfo.appsApi.readNamespacedDeployment({ name, namespace });
|
|
865
|
+
}
|
|
866
|
+
catch (err) {
|
|
867
|
+
return { error: (_a = err.message) !== null && _a !== void 0 ? _a : String(err) };
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}),
|
|
871
|
+
get_rollout_history: (0, ai_1.tool)({
|
|
872
|
+
description: 'Returns the rollout history (revisions) of a Deployment via its ReplicaSets: per revision the image(s), replicas and pod-template summary (env names, resources, command). Use to see WHAT CHANGED recently — a new image tag, a changed env/resource/command — that may have broken the pods (the "artifact versions" of the workload). Compare the newest revision against the previous one.',
|
|
873
|
+
inputSchema: zod_1.z.object({
|
|
874
|
+
namespace: zod_1.z.string().describe('Namespace of the deployment'),
|
|
875
|
+
name: zod_1.z.string().describe('Name of the Deployment (the owning workload, e.g. describe_pod.controlledBy.name — NOT the pod name)')
|
|
876
|
+
}),
|
|
877
|
+
execute: async ({ namespace, name }) => {
|
|
878
|
+
var _a, _b;
|
|
879
|
+
ctx().trace('get_rollout_history', { namespace, name });
|
|
880
|
+
try {
|
|
881
|
+
const rsList = await ctx().clusterInfo.appsApi.listNamespacedReplicaSet({ namespace });
|
|
882
|
+
const owned = ((_a = rsList.items) !== null && _a !== void 0 ? _a : []).filter((rs) => { var _a, _b; return ((_b = (_a = rs.metadata) === null || _a === void 0 ? void 0 : _a.ownerReferences) !== null && _b !== void 0 ? _b : []).some((o) => o.kind === 'Deployment' && o.name === name); });
|
|
883
|
+
const container = (ct) => { var _a; return ({ name: ct.name, image: ct.image, command: ct.command, args: ct.args, resources: ct.resources, env: ((_a = ct.env) !== null && _a !== void 0 ? _a : []).map((e) => e.name) }); };
|
|
884
|
+
const revisions = owned.map((rs) => {
|
|
885
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
886
|
+
const tmpl = (_c = (_b = (_a = rs.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.spec) !== null && _c !== void 0 ? _c : {};
|
|
887
|
+
return {
|
|
888
|
+
revision: Number((_f = (_e = (_d = rs.metadata) === null || _d === void 0 ? void 0 : _d.annotations) === null || _e === void 0 ? void 0 : _e['deployment.kubernetes.io/revision']) !== null && _f !== void 0 ? _f : 0),
|
|
889
|
+
replicaSet: (_g = rs.metadata) === null || _g === void 0 ? void 0 : _g.name,
|
|
890
|
+
createdAt: (_h = rs.metadata) === null || _h === void 0 ? void 0 : _h.creationTimestamp,
|
|
891
|
+
replicas: (_k = (_j = rs.spec) === null || _j === void 0 ? void 0 : _j.replicas) !== null && _k !== void 0 ? _k : 0,
|
|
892
|
+
readyReplicas: (_m = (_l = rs.status) === null || _l === void 0 ? void 0 : _l.readyReplicas) !== null && _m !== void 0 ? _m : 0,
|
|
893
|
+
containers: ((_o = tmpl.containers) !== null && _o !== void 0 ? _o : []).map(container),
|
|
894
|
+
serviceAccount: tmpl.serviceAccountName,
|
|
895
|
+
securityContext: tmpl.securityContext
|
|
896
|
+
};
|
|
897
|
+
}).sort((a, b) => b.revision - a.revision); // newest first
|
|
898
|
+
return { deployment: name, namespace, revisionCount: revisions.length, revisions };
|
|
899
|
+
}
|
|
900
|
+
catch (err) {
|
|
901
|
+
return { error: (_b = err.message) !== null && _b !== void 0 ? _b : String(err) };
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}),
|
|
758
905
|
};
|
|
759
906
|
exports.toolInfoList = [
|
|
760
907
|
{ name: 'list_namespaces', effect: EToolEffect.READ, description: 'Lists all namespaces in the cluster with their status and labels.' },
|
|
@@ -784,6 +931,11 @@ exports.toolInfoList = [
|
|
|
784
931
|
{ name: 'get_certificate_info', effect: EToolEffect.READ, description: 'Connects to a hostname via HTTPS and returns TLS certificate details: subject, issuer, validity dates, SANs, fingerprint and whether it is currently valid.' },
|
|
785
932
|
{ name: 'get_cluster_events', effect: EToolEffect.READ, description: 'Returns recent buffered Kubernetes events for this cluster (warnings + object lifecycle changes); filter by warnings only or namespace.' },
|
|
786
933
|
{ name: 'get_object_events', effect: EToolEffect.READ, description: 'Returns recent events for a specific Kubernetes object (namespace + name), including related kube Events.' },
|
|
934
|
+
{ name: 'get_pod_logs', effect: EToolEffect.READ, description: 'Returns container logs for a pod (kubectl logs); previous:true reads the crashed instance logs — the root cause of a CrashLoopBackOff.' },
|
|
935
|
+
{ name: 'describe_pod', effect: EToolEffect.READ, description: 'Diagnostic summary of a pod (kubectl describe pod): per-container waiting/terminated reason + exitCode (OOMKilled/CrashLoop…), restart count, probes.' },
|
|
936
|
+
{ name: 'get_pod_yaml', effect: EToolEffect.READ, description: 'Full Pod manifest (kubectl get pod -o yaml): spec (env, volumes, resources, probes) and status.' },
|
|
937
|
+
{ name: 'get_deployment_yaml', effect: EToolEffect.READ, description: 'Full Deployment manifest (kubectl get deployment -o yaml): pod template (image, env, resources, probes) and strategy.' },
|
|
938
|
+
{ name: 'get_rollout_history', effect: EToolEffect.READ, description: 'Rollout revisions of a Deployment (via ReplicaSets): image + template per revision, to see what changed (new image/env/resource) that may have broken the pods.' },
|
|
787
939
|
];
|
|
788
940
|
// Resolves the tool names an agent may use: autoTools = full catalog, otherwise its own list
|
|
789
941
|
// (intersected with the catalog); readOnly filters out WRITE-effect tools. Pure (no LLM) → unit-testable.
|