@kwirthmagnify/kwirth-common-ai 0.5.28 → 0.5.29

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
@@ -428,6 +428,71 @@ export declare const tools: {
428
428
  revisionCount?: undefined;
429
429
  revisions?: undefined;
430
430
  }>;
431
+ readonly get_configmap: import("ai").Tool<{
432
+ namespace: string;
433
+ name: string;
434
+ }, {
435
+ name: string;
436
+ namespace: string;
437
+ resourceVersion: any;
438
+ lastModified: string | undefined;
439
+ data: any;
440
+ binaryDataKeys: string[];
441
+ error?: undefined;
442
+ } | {
443
+ error: any;
444
+ name?: undefined;
445
+ namespace?: undefined;
446
+ resourceVersion?: undefined;
447
+ lastModified?: undefined;
448
+ data?: undefined;
449
+ binaryDataKeys?: undefined;
450
+ }>;
451
+ readonly get_secret: import("ai").Tool<{
452
+ namespace: string;
453
+ name: string;
454
+ }, {
455
+ name: string;
456
+ namespace: string;
457
+ type: any;
458
+ resourceVersion: any;
459
+ lastModified: string | undefined;
460
+ keys: string[];
461
+ error?: undefined;
462
+ } | {
463
+ error: any;
464
+ name?: undefined;
465
+ namespace?: undefined;
466
+ type?: undefined;
467
+ resourceVersion?: undefined;
468
+ lastModified?: undefined;
469
+ keys?: undefined;
470
+ }>;
471
+ readonly get_workload_config_refs: import("ai").Tool<{
472
+ namespace: string;
473
+ name: string;
474
+ }, {
475
+ deployment: string;
476
+ namespace: string;
477
+ refs: ({
478
+ resourceVersion: any;
479
+ lastModified: string | undefined;
480
+ kind: string;
481
+ name: string;
482
+ via: string[];
483
+ } | {
484
+ error: any;
485
+ kind: string;
486
+ name: string;
487
+ via: string[];
488
+ })[];
489
+ error?: undefined;
490
+ } | {
491
+ error: any;
492
+ deployment?: undefined;
493
+ namespace?: undefined;
494
+ refs?: undefined;
495
+ }>;
431
496
  readonly get_source_file: import("ai").Tool<{
432
497
  repo: string;
433
498
  ref: string;
package/dist/back.js CHANGED
@@ -261,6 +261,36 @@ const summarizeClusterEvent = (e) => {
261
261
  namespace: (_d = o.metadata) === null || _d === void 0 ? void 0 : _d.namespace
262
262
  };
263
263
  };
264
+ // Best-effort "last modified" of a k8s object: the newest managedFields time (each apply stamps one),
265
+ // falling back to creationTimestamp. k8s keeps no explicit lastModified, so this is the closest signal to
266
+ // "when did this ConfigMap/Secret last change" — used to correlate a config edit with a crash.
267
+ const lastModifiedOf = (meta) => {
268
+ var _a;
269
+ const times = ((_a = meta === null || meta === void 0 ? void 0 : meta.managedFields) !== null && _a !== void 0 ? _a : []).map((f) => f.time).filter(Boolean);
270
+ return times.length ? times.sort()[times.length - 1] : meta === null || meta === void 0 ? void 0 : meta.creationTimestamp;
271
+ };
272
+ // The ConfigMap/Secret references a pod template consumes: envFrom, env.valueFrom, and volumes.
273
+ const configRefsOfPodSpec = (spec) => {
274
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
275
+ const refs = [];
276
+ const add = (kind, name, via) => { if (name)
277
+ refs.push({ kind, name, via }); };
278
+ for (const ct of [...((_a = spec === null || spec === void 0 ? void 0 : spec.containers) !== null && _a !== void 0 ? _a : []), ...((_b = spec === null || spec === void 0 ? void 0 : spec.initContainers) !== null && _b !== void 0 ? _b : [])]) {
279
+ for (const ef of (_c = ct.envFrom) !== null && _c !== void 0 ? _c : []) {
280
+ add('ConfigMap', (_d = ef.configMapRef) === null || _d === void 0 ? void 0 : _d.name, `envFrom(${ct.name})`);
281
+ add('Secret', (_e = ef.secretRef) === null || _e === void 0 ? void 0 : _e.name, `envFrom(${ct.name})`);
282
+ }
283
+ for (const e of (_f = ct.env) !== null && _f !== void 0 ? _f : []) {
284
+ add('ConfigMap', (_h = (_g = e.valueFrom) === null || _g === void 0 ? void 0 : _g.configMapKeyRef) === null || _h === void 0 ? void 0 : _h.name, `env ${e.name}`);
285
+ add('Secret', (_k = (_j = e.valueFrom) === null || _j === void 0 ? void 0 : _j.secretKeyRef) === null || _k === void 0 ? void 0 : _k.name, `env ${e.name}`);
286
+ }
287
+ }
288
+ for (const v of (_l = spec === null || spec === void 0 ? void 0 : spec.volumes) !== null && _l !== void 0 ? _l : []) {
289
+ add('ConfigMap', (_m = v.configMap) === null || _m === void 0 ? void 0 : _m.name, `volume ${v.name}`);
290
+ add('Secret', (_o = v.secret) === null || _o === void 0 ? void 0 : _o.secretName, `volume ${v.name}`);
291
+ }
292
+ return refs;
293
+ };
264
294
  exports.tools = {
265
295
  // ── CLUSTER CONFIG ───────────────────────────────────────────────────────
266
296
  list_namespaces: (0, ai_1.tool)({
@@ -906,7 +936,7 @@ exports.tools = {
906
936
  }
907
937
  }),
908
938
  get_rollout_history: (0, ai_1.tool)({
909
- 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.',
939
+ description: 'Returns the rollout history (revisions) of a Deployment via its ReplicaSets: per revision the image(s), replicas and pod-template summary (env with inline VALUES and their configMap/secret source, resources, command). Use to see WHAT CHANGED recently — a new image tag, a changed inline env value, a resource/command change — that may have broken the pods. Compare the newest revision against the previous one. NOTE: a change to a ConfigMap/Secret VALUE does NOT create a revision — use get_workload_config_refs for that.',
910
940
  inputSchema: zod_1.z.object({
911
941
  namespace: zod_1.z.string().describe('Namespace of the deployment'),
912
942
  name: zod_1.z.string().describe('Name of the Deployment (the owning workload, e.g. describe_pod.controlledBy.name — NOT the pod name)')
@@ -917,7 +947,16 @@ exports.tools = {
917
947
  try {
918
948
  const rsList = await ctx().clusterInfo.appsApi.listNamespacedReplicaSet({ namespace });
919
949
  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); });
920
- 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) }); };
950
+ // env: inline value + where a valueFrom env is sourced (so the LLM can both diff inline values
951
+ // across revisions AND know which vars come from a ConfigMap/Secret to check separately).
952
+ const envSource = (e) => {
953
+ var _a, _b, _c;
954
+ return ((_a = e.valueFrom) === null || _a === void 0 ? void 0 : _a.configMapKeyRef) ? `configMap:${e.valueFrom.configMapKeyRef.name}/${e.valueFrom.configMapKeyRef.key}`
955
+ : ((_b = e.valueFrom) === null || _b === void 0 ? void 0 : _b.secretKeyRef) ? `secret:${e.valueFrom.secretKeyRef.name}/${e.valueFrom.secretKeyRef.key}`
956
+ : ((_c = e.valueFrom) === null || _c === void 0 ? void 0 : _c.fieldRef) ? `field:${e.valueFrom.fieldRef.fieldPath}`
957
+ : undefined;
958
+ };
959
+ 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) => ({ name: e.name, value: e.value, from: envSource(e) })) }); };
921
960
  const revisions = owned.map((rs) => {
922
961
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
923
962
  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 : {};
@@ -939,6 +978,81 @@ exports.tools = {
939
978
  }
940
979
  }
941
980
  }),
981
+ get_configmap: (0, ai_1.tool)({
982
+ description: 'Returns a ConfigMap\'s data (key → value) plus metadata (resourceVersion, lastModified). Use to inspect the ACTUAL config a workload consumes and to check whether it changed recently — a ConfigMap value change (same env var, different value) does NOT create a Deployment revision, so it is invisible to get_rollout_history.',
983
+ inputSchema: zod_1.z.object({
984
+ namespace: zod_1.z.string().describe('Namespace of the ConfigMap'),
985
+ name: zod_1.z.string().describe('Name of the ConfigMap')
986
+ }),
987
+ execute: async ({ namespace, name }) => {
988
+ var _a, _b, _c, _d;
989
+ ctx().trace('get_configmap', { namespace, name });
990
+ try {
991
+ const cm = await ctx().clusterInfo.coreApi.readNamespacedConfigMap({ name, namespace });
992
+ return { name, namespace, resourceVersion: (_a = cm.metadata) === null || _a === void 0 ? void 0 : _a.resourceVersion, lastModified: lastModifiedOf(cm.metadata), data: (_b = cm.data) !== null && _b !== void 0 ? _b : {}, binaryDataKeys: Object.keys((_c = cm.binaryData) !== null && _c !== void 0 ? _c : {}) };
993
+ }
994
+ catch (err) {
995
+ return { error: (_d = err.message) !== null && _d !== void 0 ? _d : String(err) };
996
+ }
997
+ }
998
+ }),
999
+ get_secret: (0, ai_1.tool)({
1000
+ description: 'Returns a Secret\'s KEYS, type and metadata (resourceVersion, lastModified) — VALUES ARE REDACTED (never returned). Use to check whether a Secret a workload consumes changed recently (a value change does NOT create a Deployment revision) and which keys it holds. You cannot read the secret values.',
1001
+ inputSchema: zod_1.z.object({
1002
+ namespace: zod_1.z.string().describe('Namespace of the Secret'),
1003
+ name: zod_1.z.string().describe('Name of the Secret')
1004
+ }),
1005
+ execute: async ({ namespace, name }) => {
1006
+ var _a, _b, _c;
1007
+ ctx().trace('get_secret', { namespace, name });
1008
+ try {
1009
+ const s = await ctx().clusterInfo.coreApi.readNamespacedSecret({ name, namespace });
1010
+ return { name, namespace, type: s.type, resourceVersion: (_a = s.metadata) === null || _a === void 0 ? void 0 : _a.resourceVersion, lastModified: lastModifiedOf(s.metadata), keys: Object.keys((_b = s.data) !== null && _b !== void 0 ? _b : {}) }; // values intentionally omitted
1011
+ }
1012
+ catch (err) {
1013
+ return { error: (_c = err.message) !== null && _c !== void 0 ? _c : String(err) };
1014
+ }
1015
+ }
1016
+ }),
1017
+ get_workload_config_refs: (0, ai_1.tool)({
1018
+ description: 'Given a Deployment, lists the ConfigMaps and Secrets its pods consume (via envFrom, env valueFrom, and volumes), each with its lastModified time and resourceVersion. Use on a crash to find a config source that CHANGED WITHOUT A ROLLOUT: editing a ConfigMap/Secret value keeps the same env spec (no new revision) yet can break the pod — compare each ref\'s lastModified against when the pods started crashing, then read the changed one with get_configmap / get_secret.',
1019
+ inputSchema: zod_1.z.object({
1020
+ namespace: zod_1.z.string().describe('Namespace of the deployment'),
1021
+ name: zod_1.z.string().describe('Name of the Deployment (e.g. describe_pod.controlledBy.name)')
1022
+ }),
1023
+ execute: async ({ namespace, name }) => {
1024
+ var _a, _b, _c, _d;
1025
+ ctx().trace('get_workload_config_refs', { namespace, name });
1026
+ try {
1027
+ const c = ctx().clusterInfo;
1028
+ const dep = await c.appsApi.readNamespacedDeployment({ name, namespace });
1029
+ // dedupe by kind+name, merging the reasons (an object may be referenced several ways)
1030
+ const byKey = new Map();
1031
+ for (const r of configRefsOfPodSpec((_b = (_a = dep.spec) === null || _a === void 0 ? void 0 : _a.template) === null || _b === void 0 ? void 0 : _b.spec)) {
1032
+ const cur = (_c = byKey.get(`${r.kind}/${r.name}`)) !== null && _c !== void 0 ? _c : { kind: r.kind, name: r.name, via: [] };
1033
+ if (!cur.via.includes(r.via))
1034
+ cur.via.push(r.via);
1035
+ byKey.set(`${r.kind}/${r.name}`, cur);
1036
+ }
1037
+ const refs = await Promise.all([...byKey.values()].map(async (r) => {
1038
+ var _a;
1039
+ try {
1040
+ const meta = (r.kind === 'ConfigMap'
1041
+ ? await c.coreApi.readNamespacedConfigMap({ name: r.name, namespace })
1042
+ : await c.coreApi.readNamespacedSecret({ name: r.name, namespace })).metadata;
1043
+ return Object.assign(Object.assign({}, r), { resourceVersion: meta === null || meta === void 0 ? void 0 : meta.resourceVersion, lastModified: lastModifiedOf(meta) });
1044
+ }
1045
+ catch (err) {
1046
+ return Object.assign(Object.assign({}, r), { error: (_a = err.message) !== null && _a !== void 0 ? _a : String(err) });
1047
+ }
1048
+ }));
1049
+ return { deployment: name, namespace, refs };
1050
+ }
1051
+ catch (err) {
1052
+ return { error: (_d = err.message) !== null && _d !== void 0 ? _d : String(err) };
1053
+ }
1054
+ }
1055
+ }),
942
1056
  get_source_file: (0, ai_1.tool)({
943
1057
  description: 'Fetches the contents of a single source file from a Git repository (GitHub or GitLab) at a specific ref. Use to inspect the actual source behind a crash: read the stack-trace file:line from the logs, then fetch that file at the image build revision (describe_pod.source). Call repeatedly to follow the trace across files until you find the bug.',
944
1058
  inputSchema: zod_1.z.object({
@@ -996,7 +1110,10 @@ exports.toolInfoList = [
996
1110
  { 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.' },
997
1111
  { name: 'get_pod_yaml', effect: EToolEffect.READ, description: 'Full Pod manifest (kubectl get pod -o yaml): spec (env, volumes, resources, probes) and status.' },
998
1112
  { name: 'get_deployment_yaml', effect: EToolEffect.READ, description: 'Full Deployment manifest (kubectl get deployment -o yaml): pod template (image, env, resources, probes) and strategy.' },
999
- { 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.' },
1113
+ { name: 'get_rollout_history', effect: EToolEffect.READ, description: 'Rollout revisions of a Deployment (via ReplicaSets): image + template per revision (env with inline values + configMap/secret source), to see what changed (new image/env/resource) that may have broken the pods.' },
1114
+ { name: 'get_configmap', effect: EToolEffect.READ, description: 'A ConfigMap\'s data (key→value) + lastModified. A ConfigMap value change does NOT create a rollout revision, so check it for a crash with no deployment change.' },
1115
+ { name: 'get_secret', effect: EToolEffect.READ, description: 'A Secret\'s keys + type + lastModified (VALUES REDACTED). Check whether a consumed Secret changed recently (no rollout revision is created by a value change).' },
1116
+ { name: 'get_workload_config_refs', effect: EToolEffect.READ, description: 'The ConfigMaps/Secrets a Deployment consumes (envFrom/valueFrom/volumes) with each one\'s lastModified — find a config source that changed WITHOUT a rollout and broke the pods.' },
1000
1117
  { name: 'get_source_file', effect: EToolEffect.READ, description: 'Fetches a file from a Git repo (GitHub/GitLab) at a ref — inspect the source behind a crash by following the stack trace to the offending file:line.' },
1001
1118
  ];
1002
1119
  // Resolves the tool names an agent may use: autoTools = full catalog, otherwise its own list
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kwirthmagnify/kwirth-common-ai",
3
- "version": "0.5.28",
3
+ "version": "0.5.29",
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",