@kwirthmagnify/kwirth-common-ai 0.5.26 → 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 CHANGED
@@ -368,6 +368,7 @@ export declare const tools: {
368
368
  startTime: any;
369
369
  reason: any;
370
370
  message: any;
371
+ controlledBy: any;
371
372
  conditions: any;
372
373
  containers: any;
373
374
  initContainers: any;
@@ -385,6 +386,7 @@ export declare const tools: {
385
386
  startTime?: undefined;
386
387
  reason?: undefined;
387
388
  message?: undefined;
389
+ controlledBy?: undefined;
388
390
  conditions?: undefined;
389
391
  containers?: undefined;
390
392
  initContainers?: undefined;
@@ -398,6 +400,22 @@ export declare const tools: {
398
400
  namespace: string;
399
401
  name: string;
400
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
+ }>;
401
419
  };
402
420
  export declare const toolInfoList: IToolInfo[];
403
421
  export interface IAgentRunResult {
package/dist/back.js CHANGED
@@ -786,32 +786,51 @@ exports.tools = {
786
786
  name: zod_1.z.string().describe('Name of the pod')
787
787
  }),
788
788
  execute: async ({ namespace, name }) => {
789
- var _a, _b, _c, _d, _e, _f, _g;
789
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
790
790
  ctx().trace('describe_pod', { namespace, name });
791
791
  try {
792
- const pod = await ctx().clusterInfo.coreApi.readNamespacedPod({ name, namespace });
792
+ const c = ctx().clusterInfo;
793
+ const pod = await c.coreApi.readNamespacedPod({ name, namespace });
793
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).
794
796
  const containerStatus = (cs) => {
795
797
  var _a, _b, _c, _d;
796
798
  return ({
797
- name: cs.name, image: cs.image, ready: cs.ready, restartCount: cs.restartCount,
799
+ name: cs.name, image: cs.image, imageID: cs.imageID, ready: cs.ready, restartCount: cs.restartCount,
798
800
  state: ((_a = cs.state) === null || _a === void 0 ? void 0 : _a.waiting) ? { waiting: { reason: cs.state.waiting.reason, message: cs.state.waiting.message } }
799
801
  : ((_b = cs.state) === null || _b === void 0 ? void 0 : _b.terminated) ? { terminated: { reason: cs.state.terminated.reason, exitCode: cs.state.terminated.exitCode } }
800
802
  : ((_c = cs.state) === null || _c === void 0 ? void 0 : _c.running) ? { running: { startedAt: cs.state.running.startedAt } } : cs.state,
801
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
802
804
  });
803
805
  };
804
- const specContainer = (c) => ({ name: c.name, image: c.image, resources: c.resources, livenessProbe: !!c.livenessProbe, readinessProbe: !!c.readinessProbe, startupProbe: !!c.startupProbe });
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
+ }
805
823
  return {
806
824
  name, namespace, phase: status.phase, node: spec.nodeName, startTime: status.startTime, reason: status.reason, message: status.message,
807
- conditions: ((_c = status.conditions) !== null && _c !== void 0 ? _c : []).map((c) => ({ type: c.type, status: c.status, reason: c.reason })),
808
- containers: ((_d = status.containerStatuses) !== null && _d !== void 0 ? _d : []).map(containerStatus),
809
- initContainers: ((_e = status.initContainerStatuses) !== null && _e !== void 0 ? _e : []).map(containerStatus),
810
- spec: { containers: ((_f = spec.containers) !== null && _f !== void 0 ? _f : []).map(specContainer), restartPolicy: spec.restartPolicy }
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 }
811
830
  };
812
831
  }
813
832
  catch (err) {
814
- return { error: (_g = err.message) !== null && _g !== void 0 ? _g : String(err) };
833
+ return { error: (_l = err.message) !== null && _l !== void 0 ? _l : String(err) };
815
834
  }
816
835
  }
817
836
  }),
@@ -849,6 +868,40 @@ exports.tools = {
849
868
  }
850
869
  }
851
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
+ }),
852
905
  };
853
906
  exports.toolInfoList = [
854
907
  { name: 'list_namespaces', effect: EToolEffect.READ, description: 'Lists all namespaces in the cluster with their status and labels.' },
@@ -882,6 +935,7 @@ exports.toolInfoList = [
882
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.' },
883
936
  { name: 'get_pod_yaml', effect: EToolEffect.READ, description: 'Full Pod manifest (kubectl get pod -o yaml): spec (env, volumes, resources, probes) and status.' },
884
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.' },
885
939
  ];
886
940
  // Resolves the tool names an agent may use: autoTools = full catalog, otherwise its own list
887
941
  // (intersected with the catalog); readOnly filters out WRITE-effect tools. Pure (no LLM) → unit-testable.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.26",
3
+ "version": "0.5.27",
4
4
  "description": "Shared AI/LLM types and utilities for Kwirth AI plugins",
5
5
  "scripts": {
6
6
  "build": "del .\\dist\\* /s /q 2>nul & tsc",