@integrity-labs/agt-cli 0.28.166 → 0.28.168
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.
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
requireHost,
|
|
29
29
|
safeWriteJsonAtomic,
|
|
30
30
|
setConfigHash
|
|
31
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-DYW5QFTU.js";
|
|
32
32
|
import {
|
|
33
33
|
getProjectDir as getProjectDir2,
|
|
34
34
|
getReadyTasks,
|
|
@@ -6878,7 +6878,7 @@ var agentRestartTimezoneInputs = /* @__PURE__ */ new Map();
|
|
|
6878
6878
|
var lastVersionCheckAt = 0;
|
|
6879
6879
|
var VERSION_CHECK_INTERVAL_MS = 5 * 60 * 1e3;
|
|
6880
6880
|
var lastResponsivenessProbeAt = 0;
|
|
6881
|
-
var agtCliVersion = true ? "0.28.
|
|
6881
|
+
var agtCliVersion = true ? "0.28.168" : "dev";
|
|
6882
6882
|
function resolveBrewPath(execFileSync4) {
|
|
6883
6883
|
try {
|
|
6884
6884
|
const out = execFileSync4("which", ["brew"], { timeout: 5e3 }).toString().trim();
|
|
@@ -63,9 +63,9 @@ var require_code = __commonJS({
|
|
|
63
63
|
};
|
|
64
64
|
exports.Name = Name;
|
|
65
65
|
var _Code = class extends _CodeOrName {
|
|
66
|
-
constructor(
|
|
66
|
+
constructor(code2) {
|
|
67
67
|
super();
|
|
68
|
-
this._items = typeof
|
|
68
|
+
this._items = typeof code2 === "string" ? [code2] : code2;
|
|
69
69
|
}
|
|
70
70
|
toString() {
|
|
71
71
|
return this.str;
|
|
@@ -92,13 +92,13 @@ var require_code = __commonJS({
|
|
|
92
92
|
exports._Code = _Code;
|
|
93
93
|
exports.nil = new _Code("");
|
|
94
94
|
function _(strs, ...args) {
|
|
95
|
-
const
|
|
95
|
+
const code2 = [strs[0]];
|
|
96
96
|
let i = 0;
|
|
97
97
|
while (i < args.length) {
|
|
98
|
-
addCodeArg(
|
|
99
|
-
|
|
98
|
+
addCodeArg(code2, args[i]);
|
|
99
|
+
code2.push(strs[++i]);
|
|
100
100
|
}
|
|
101
|
-
return new _Code(
|
|
101
|
+
return new _Code(code2);
|
|
102
102
|
}
|
|
103
103
|
exports._ = _;
|
|
104
104
|
var plus = new _Code("+");
|
|
@@ -114,13 +114,13 @@ var require_code = __commonJS({
|
|
|
114
114
|
return new _Code(expr);
|
|
115
115
|
}
|
|
116
116
|
exports.str = str;
|
|
117
|
-
function addCodeArg(
|
|
117
|
+
function addCodeArg(code2, arg) {
|
|
118
118
|
if (arg instanceof _Code)
|
|
119
|
-
|
|
119
|
+
code2.push(...arg._items);
|
|
120
120
|
else if (arg instanceof Name)
|
|
121
|
-
|
|
121
|
+
code2.push(arg);
|
|
122
122
|
else
|
|
123
|
-
|
|
123
|
+
code2.push(interpolate(arg));
|
|
124
124
|
}
|
|
125
125
|
exports.addCodeArg = addCodeArg;
|
|
126
126
|
function optimize(expr) {
|
|
@@ -304,7 +304,7 @@ var require_scope = __commonJS({
|
|
|
304
304
|
}, usedValues, getCode);
|
|
305
305
|
}
|
|
306
306
|
_reduceValues(values, valueCode, usedValues = {}, getCode) {
|
|
307
|
-
let
|
|
307
|
+
let code2 = code_1.nil;
|
|
308
308
|
for (const prefix in values) {
|
|
309
309
|
const vs = values[prefix];
|
|
310
310
|
if (!vs)
|
|
@@ -317,16 +317,16 @@ var require_scope = __commonJS({
|
|
|
317
317
|
let c = valueCode(name);
|
|
318
318
|
if (c) {
|
|
319
319
|
const def = this.opts.es5 ? exports.varKinds.var : exports.varKinds.const;
|
|
320
|
-
|
|
320
|
+
code2 = (0, code_1._)`${code2}${def} ${name} = ${c};${this.opts._n}`;
|
|
321
321
|
} else if (c = getCode === null || getCode === void 0 ? void 0 : getCode(name)) {
|
|
322
|
-
|
|
322
|
+
code2 = (0, code_1._)`${code2}${c}${this.opts._n}`;
|
|
323
323
|
} else {
|
|
324
324
|
throw new ValueError(name);
|
|
325
325
|
}
|
|
326
326
|
nameSet.set(name, UsedValueState.Completed);
|
|
327
327
|
});
|
|
328
328
|
}
|
|
329
|
-
return
|
|
329
|
+
return code2;
|
|
330
330
|
}
|
|
331
331
|
};
|
|
332
332
|
exports.ValueScope = ValueScope;
|
|
@@ -486,9 +486,9 @@ var require_codegen = __commonJS({
|
|
|
486
486
|
}
|
|
487
487
|
};
|
|
488
488
|
var AnyCode = class extends Node {
|
|
489
|
-
constructor(
|
|
489
|
+
constructor(code2) {
|
|
490
490
|
super();
|
|
491
|
-
this.code =
|
|
491
|
+
this.code = code2;
|
|
492
492
|
}
|
|
493
493
|
render({ _n }) {
|
|
494
494
|
return `${this.code};` + _n;
|
|
@@ -510,7 +510,7 @@ var require_codegen = __commonJS({
|
|
|
510
510
|
this.nodes = nodes;
|
|
511
511
|
}
|
|
512
512
|
render(opts) {
|
|
513
|
-
return this.nodes.reduce((
|
|
513
|
+
return this.nodes.reduce((code2, n) => code2 + n.render(opts), "");
|
|
514
514
|
}
|
|
515
515
|
optimizeNodes() {
|
|
516
516
|
const { nodes } = this;
|
|
@@ -558,10 +558,10 @@ var require_codegen = __commonJS({
|
|
|
558
558
|
this.condition = condition;
|
|
559
559
|
}
|
|
560
560
|
render(opts) {
|
|
561
|
-
let
|
|
561
|
+
let code2 = `if(${this.condition})` + super.render(opts);
|
|
562
562
|
if (this.else)
|
|
563
|
-
|
|
564
|
-
return
|
|
563
|
+
code2 += "else " + this.else.render(opts);
|
|
564
|
+
return code2;
|
|
565
565
|
}
|
|
566
566
|
optimizeNodes() {
|
|
567
567
|
super.optimizeNodes();
|
|
@@ -682,12 +682,12 @@ var require_codegen = __commonJS({
|
|
|
682
682
|
Return.kind = "return";
|
|
683
683
|
var Try = class extends BlockNode {
|
|
684
684
|
render(opts) {
|
|
685
|
-
let
|
|
685
|
+
let code2 = "try" + super.render(opts);
|
|
686
686
|
if (this.catch)
|
|
687
|
-
|
|
687
|
+
code2 += this.catch.render(opts);
|
|
688
688
|
if (this.finally)
|
|
689
|
-
|
|
690
|
-
return
|
|
689
|
+
code2 += this.finally.render(opts);
|
|
690
|
+
return code2;
|
|
691
691
|
}
|
|
692
692
|
optimizeNodes() {
|
|
693
693
|
var _a, _b;
|
|
@@ -804,18 +804,18 @@ var require_codegen = __commonJS({
|
|
|
804
804
|
}
|
|
805
805
|
// returns code for object literal for the passed argument list of key-value pairs
|
|
806
806
|
object(...keyValues) {
|
|
807
|
-
const
|
|
807
|
+
const code2 = ["{"];
|
|
808
808
|
for (const [key2, value] of keyValues) {
|
|
809
|
-
if (
|
|
810
|
-
|
|
811
|
-
|
|
809
|
+
if (code2.length > 1)
|
|
810
|
+
code2.push(",");
|
|
811
|
+
code2.push(key2);
|
|
812
812
|
if (key2 !== value || this.opts.es5) {
|
|
813
|
-
|
|
814
|
-
(0, code_1.addCodeArg)(
|
|
813
|
+
code2.push(":");
|
|
814
|
+
(0, code_1.addCodeArg)(code2, value);
|
|
815
815
|
}
|
|
816
816
|
}
|
|
817
|
-
|
|
818
|
-
return new code_1._Code(
|
|
817
|
+
code2.push("}");
|
|
818
|
+
return new code_1._Code(code2);
|
|
819
819
|
}
|
|
820
820
|
// `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)
|
|
821
821
|
if(condition, thenBody, elseBody) {
|
|
@@ -3112,22 +3112,22 @@ var require_utils = __commonJS({
|
|
|
3112
3112
|
var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
|
|
3113
3113
|
function stringArrayToHexStripped(input) {
|
|
3114
3114
|
let acc = "";
|
|
3115
|
-
let
|
|
3115
|
+
let code2 = 0;
|
|
3116
3116
|
let i = 0;
|
|
3117
3117
|
for (i = 0; i < input.length; i++) {
|
|
3118
|
-
|
|
3119
|
-
if (
|
|
3118
|
+
code2 = input[i].charCodeAt(0);
|
|
3119
|
+
if (code2 === 48) {
|
|
3120
3120
|
continue;
|
|
3121
3121
|
}
|
|
3122
|
-
if (!(
|
|
3122
|
+
if (!(code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 70 || code2 >= 97 && code2 <= 102)) {
|
|
3123
3123
|
return "";
|
|
3124
3124
|
}
|
|
3125
3125
|
acc += input[i];
|
|
3126
3126
|
break;
|
|
3127
3127
|
}
|
|
3128
3128
|
for (i += 1; i < input.length; i++) {
|
|
3129
|
-
|
|
3130
|
-
if (!(
|
|
3129
|
+
code2 = input[i].charCodeAt(0);
|
|
3130
|
+
if (!(code2 >= 48 && code2 <= 57 || code2 >= 65 && code2 <= 70 || code2 >= 97 && code2 <= 102)) {
|
|
3131
3131
|
return "";
|
|
3132
3132
|
}
|
|
3133
3133
|
acc += input[i];
|
|
@@ -6062,8 +6062,8 @@ var require_format = __commonJS({
|
|
|
6062
6062
|
}
|
|
6063
6063
|
}
|
|
6064
6064
|
function getFormat(fmtDef) {
|
|
6065
|
-
const
|
|
6066
|
-
const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code });
|
|
6065
|
+
const code2 = fmtDef instanceof RegExp ? (0, codegen_1.regexpCode)(fmtDef) : opts.code.formats ? (0, codegen_1._)`${opts.code.formats}${(0, codegen_1.getProperty)(schema)}` : void 0;
|
|
6066
|
+
const fmt = gen.scopeValue("formats", { key: schema, ref: fmtDef, code: code2 });
|
|
6067
6067
|
if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
|
|
6068
6068
|
return [fmtDef.type || "string", fmtDef.validate, (0, codegen_1._)`${fmt}.validate`];
|
|
6069
6069
|
}
|
|
@@ -12479,23 +12479,23 @@ var ServerResultSchema = union([
|
|
|
12479
12479
|
CreateTaskResultSchema
|
|
12480
12480
|
]);
|
|
12481
12481
|
var McpError = class _McpError extends Error {
|
|
12482
|
-
constructor(
|
|
12483
|
-
super(`MCP error ${
|
|
12484
|
-
this.code =
|
|
12482
|
+
constructor(code2, message, data) {
|
|
12483
|
+
super(`MCP error ${code2}: ${message}`);
|
|
12484
|
+
this.code = code2;
|
|
12485
12485
|
this.data = data;
|
|
12486
12486
|
this.name = "McpError";
|
|
12487
12487
|
}
|
|
12488
12488
|
/**
|
|
12489
12489
|
* Factory method to create the appropriate error type based on the error code and data
|
|
12490
12490
|
*/
|
|
12491
|
-
static fromError(
|
|
12492
|
-
if (
|
|
12491
|
+
static fromError(code2, message, data) {
|
|
12492
|
+
if (code2 === ErrorCode.UrlElicitationRequired && data) {
|
|
12493
12493
|
const errorData = data;
|
|
12494
12494
|
if (errorData.elicitations) {
|
|
12495
12495
|
return new UrlElicitationRequiredError(errorData.elicitations, message);
|
|
12496
12496
|
}
|
|
12497
12497
|
}
|
|
12498
|
-
return new _McpError(
|
|
12498
|
+
return new _McpError(code2, message, data);
|
|
12499
12499
|
}
|
|
12500
12500
|
};
|
|
12501
12501
|
var UrlElicitationRequiredError = class extends McpError {
|
|
@@ -14250,8 +14250,8 @@ function loadRecentDms(filePath, opts = {}) {
|
|
|
14250
14250
|
try {
|
|
14251
14251
|
raw = readFileSync2(filePath, "utf-8");
|
|
14252
14252
|
} catch (err) {
|
|
14253
|
-
const
|
|
14254
|
-
if (
|
|
14253
|
+
const code2 = err.code;
|
|
14254
|
+
if (code2 !== "ENOENT") {
|
|
14255
14255
|
opts.onError?.(`dm-restart-notice: failed to read recent-DM file: ${err.message}`);
|
|
14256
14256
|
}
|
|
14257
14257
|
return /* @__PURE__ */ new Map();
|
|
@@ -15890,6 +15890,144 @@ function buildAgentConfigReport(opts) {
|
|
|
15890
15890
|
return lines.join("\n");
|
|
15891
15891
|
}
|
|
15892
15892
|
|
|
15893
|
+
// src/agent-status-report.ts
|
|
15894
|
+
var STATUS_REPORT_SCHEMA_VERSION = 1;
|
|
15895
|
+
var FRESHNESS_VALUES = /* @__PURE__ */ new Set(["cached", "live", "unknown"]);
|
|
15896
|
+
var LEVEL_VALUES = /* @__PURE__ */ new Set(["ok", "degraded", "down", "error", "unknown"]);
|
|
15897
|
+
function coerceLevel(value) {
|
|
15898
|
+
return typeof value === "string" && LEVEL_VALUES.has(value) ? value : "unknown";
|
|
15899
|
+
}
|
|
15900
|
+
function coerceFreshness(value) {
|
|
15901
|
+
return typeof value === "string" && FRESHNESS_VALUES.has(value) ? value : "unknown";
|
|
15902
|
+
}
|
|
15903
|
+
function coerceCheckedAt(value) {
|
|
15904
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
15905
|
+
}
|
|
15906
|
+
function parseAgentStatusReport(raw) {
|
|
15907
|
+
if (!raw || typeof raw !== "object") return null;
|
|
15908
|
+
const obj = raw;
|
|
15909
|
+
if (!Array.isArray(obj.channels) || !Array.isArray(obj.integrations)) return null;
|
|
15910
|
+
const channels = obj.channels.filter((c) => !!c && typeof c === "object").map((c) => ({
|
|
15911
|
+
channel_id: typeof c.channel_id === "string" ? c.channel_id : "unknown",
|
|
15912
|
+
level: coerceLevel(c.level),
|
|
15913
|
+
freshness: coerceFreshness(c.freshness),
|
|
15914
|
+
checked_at: coerceCheckedAt(c.checked_at),
|
|
15915
|
+
...typeof c.reason === "string" && c.reason ? { reason: c.reason } : {}
|
|
15916
|
+
}));
|
|
15917
|
+
const integrations = obj.integrations.filter((i) => !!i && typeof i === "object").map((i) => ({
|
|
15918
|
+
id: typeof i.id === "string" ? i.id : "unknown",
|
|
15919
|
+
definition_id: typeof i.definition_id === "string" ? i.definition_id : "unknown",
|
|
15920
|
+
display_name: typeof i.display_name === "string" && i.display_name ? i.display_name : typeof i.definition_id === "string" ? i.definition_id : "unknown",
|
|
15921
|
+
scope: i.scope === "team" || i.scope === "organization" ? i.scope : "agent",
|
|
15922
|
+
level: coerceLevel(i.level),
|
|
15923
|
+
freshness: coerceFreshness(i.freshness),
|
|
15924
|
+
checked_at: coerceCheckedAt(i.checked_at),
|
|
15925
|
+
...typeof i.consecutive_failures === "number" ? { consecutive_failures: i.consecutive_failures } : {},
|
|
15926
|
+
...typeof i.reason === "string" && i.reason ? { reason: i.reason } : {}
|
|
15927
|
+
}));
|
|
15928
|
+
return {
|
|
15929
|
+
schema_version: typeof obj.schema_version === "number" ? obj.schema_version : 0,
|
|
15930
|
+
agent_id: typeof obj.agent_id === "string" ? obj.agent_id : "",
|
|
15931
|
+
generated_at: typeof obj.generated_at === "string" ? obj.generated_at : "",
|
|
15932
|
+
manager_last_seen: coerceCheckedAt(obj.manager_last_seen),
|
|
15933
|
+
channels,
|
|
15934
|
+
integrations
|
|
15935
|
+
};
|
|
15936
|
+
}
|
|
15937
|
+
function mergeOwnChannelLiveStatus(report, channelId, live) {
|
|
15938
|
+
const liveEntry = {
|
|
15939
|
+
channel_id: channelId,
|
|
15940
|
+
level: live.level,
|
|
15941
|
+
freshness: "live",
|
|
15942
|
+
checked_at: live.checked_at,
|
|
15943
|
+
...live.reason ? { reason: live.reason } : {}
|
|
15944
|
+
};
|
|
15945
|
+
const existingIndex = report.channels.findIndex((ch) => ch.channel_id === channelId);
|
|
15946
|
+
const channels = existingIndex === -1 ? [...report.channels, liveEntry] : report.channels.map((ch, i) => i === existingIndex ? liveEntry : ch);
|
|
15947
|
+
return { ...report, channels };
|
|
15948
|
+
}
|
|
15949
|
+
function statusLevelGlyph(level) {
|
|
15950
|
+
switch (level) {
|
|
15951
|
+
case "ok":
|
|
15952
|
+
return "\u{1F7E2}";
|
|
15953
|
+
case "degraded":
|
|
15954
|
+
return "\u{1F7E1}";
|
|
15955
|
+
case "down":
|
|
15956
|
+
case "error":
|
|
15957
|
+
return "\u{1F534}";
|
|
15958
|
+
default:
|
|
15959
|
+
return "\u26AA";
|
|
15960
|
+
}
|
|
15961
|
+
}
|
|
15962
|
+
function formatStatusAge(checkedAt, nowMs) {
|
|
15963
|
+
if (!checkedAt) return "never";
|
|
15964
|
+
const t = Date.parse(checkedAt);
|
|
15965
|
+
if (Number.isNaN(t)) return "unknown";
|
|
15966
|
+
const diffMs = nowMs - t;
|
|
15967
|
+
if (diffMs < 45e3) return "just now";
|
|
15968
|
+
const mins = Math.round(diffMs / 6e4);
|
|
15969
|
+
if (mins < 60) return `${mins}m ago`;
|
|
15970
|
+
const hours = Math.round(diffMs / 36e5);
|
|
15971
|
+
if (hours < 24) return `${hours}h ago`;
|
|
15972
|
+
const days = Math.round(diffMs / 864e5);
|
|
15973
|
+
return `${days}d ago`;
|
|
15974
|
+
}
|
|
15975
|
+
|
|
15976
|
+
// src/telegram-status-render.ts
|
|
15977
|
+
var FRESHNESS_LABEL = {
|
|
15978
|
+
live: "live",
|
|
15979
|
+
cached: "cached",
|
|
15980
|
+
unknown: "unknown"
|
|
15981
|
+
};
|
|
15982
|
+
function freshnessLabel(freshness) {
|
|
15983
|
+
return FRESHNESS_LABEL[freshness] ?? freshness;
|
|
15984
|
+
}
|
|
15985
|
+
function code(value) {
|
|
15986
|
+
return `\`${value.replace(/`/g, "'")}\``;
|
|
15987
|
+
}
|
|
15988
|
+
function renderChannelLine(ch, nowMs) {
|
|
15989
|
+
const glyph = statusLevelGlyph(ch.level);
|
|
15990
|
+
const fresh = freshnessLabel(ch.freshness);
|
|
15991
|
+
const age = formatStatusAge(ch.checked_at, nowMs);
|
|
15992
|
+
const detail = ch.level !== "ok" && ch.reason ? ` (${code(ch.reason)})` : "";
|
|
15993
|
+
return `${glyph} ${code(ch.channel_id)} \xB7 ${ch.level} \xB7 ${fresh} \xB7 ${age}${detail}`;
|
|
15994
|
+
}
|
|
15995
|
+
function renderIntegrationLine(it, nowMs) {
|
|
15996
|
+
const glyph = statusLevelGlyph(it.level);
|
|
15997
|
+
const fresh = freshnessLabel(it.freshness);
|
|
15998
|
+
const age = formatStatusAge(it.checked_at, nowMs);
|
|
15999
|
+
const bits = [];
|
|
16000
|
+
if (it.level !== "ok" && it.reason) bits.push(code(it.reason));
|
|
16001
|
+
if (typeof it.consecutive_failures === "number" && it.consecutive_failures > 0) {
|
|
16002
|
+
bits.push(`${it.consecutive_failures} fail${it.consecutive_failures === 1 ? "" : "s"}`);
|
|
16003
|
+
}
|
|
16004
|
+
const detail = bits.length ? ` (${bits.join(", ")})` : "";
|
|
16005
|
+
return `${glyph} ${code(it.display_name)} \xB7 ${it.level} \xB7 ${fresh} \xB7 ${age}${detail}`;
|
|
16006
|
+
}
|
|
16007
|
+
function renderTelegramStatusSections(report, opts) {
|
|
16008
|
+
const { probing, nowMs } = opts;
|
|
16009
|
+
const lines = [];
|
|
16010
|
+
lines.push(probing ? "*Channels* (probing...)" : "*Channels*");
|
|
16011
|
+
if (report.channels.length === 0) {
|
|
16012
|
+
lines.push("_No channels configured._");
|
|
16013
|
+
} else {
|
|
16014
|
+
for (const ch of report.channels) lines.push(renderChannelLine(ch, nowMs));
|
|
16015
|
+
}
|
|
16016
|
+
lines.push("");
|
|
16017
|
+
lines.push("*Integrations*");
|
|
16018
|
+
if (report.integrations.length === 0) {
|
|
16019
|
+
lines.push("_No integrations configured._");
|
|
16020
|
+
} else {
|
|
16021
|
+
for (const it of report.integrations) lines.push(renderIntegrationLine(it, nowMs));
|
|
16022
|
+
}
|
|
16023
|
+
lines.push("");
|
|
16024
|
+
const seen = report.manager_last_seen ? `Manager last seen ${formatStatusAge(report.manager_last_seen, nowMs)}` : "Manager has never checked in";
|
|
16025
|
+
const tail = probing ? "Integration health is cached; confirming this channel's own status..." : "Integration health is cached from the last probe.";
|
|
16026
|
+
const skew = report.schema_version !== STATUS_REPORT_SCHEMA_VERSION ? ` (report schema v${report.schema_version}; update this agent for full detail)` : "";
|
|
16027
|
+
lines.push(`_${seen}. ${tail}${skew}_`);
|
|
16028
|
+
return lines.join("\n");
|
|
16029
|
+
}
|
|
16030
|
+
|
|
15893
16031
|
// src/pane-tail.ts
|
|
15894
16032
|
import { execFile } from "child_process";
|
|
15895
16033
|
import { promisify } from "util";
|
|
@@ -16406,12 +16544,12 @@ var FRIENDLY_TRANSIENT_MESSAGE = "Sorry, I hit a brief technical hiccup just now
|
|
|
16406
16544
|
function detectTransientApiError(text) {
|
|
16407
16545
|
if (!text) return null;
|
|
16408
16546
|
const head = text.replace(/^\s+/, "").slice(0, 200);
|
|
16409
|
-
const
|
|
16547
|
+
const code2 = head.match(/^api error:\s*(\d{3})\b/i)?.[1] ?? head.match(
|
|
16410
16548
|
/^(\d{3})\s+(?:overloaded|service unavailable|internal server error|too many requests|server error)\b/i
|
|
16411
16549
|
)?.[1];
|
|
16412
|
-
if (
|
|
16413
|
-
const kind = CODE_KIND[
|
|
16414
|
-
if (kind) return { code, kind };
|
|
16550
|
+
if (code2) {
|
|
16551
|
+
const kind = CODE_KIND[code2];
|
|
16552
|
+
if (kind) return { code: code2, kind };
|
|
16415
16553
|
}
|
|
16416
16554
|
const typeToken = head.match(/^[^a-z0-9]*(overloaded_error|rate_limit_error)\b/i)?.[1];
|
|
16417
16555
|
if (typeToken) {
|
|
@@ -16644,8 +16782,8 @@ function defaultIsPidAlive(pid) {
|
|
|
16644
16782
|
process.kill(pid, 0);
|
|
16645
16783
|
return true;
|
|
16646
16784
|
} catch (err) {
|
|
16647
|
-
const
|
|
16648
|
-
if (
|
|
16785
|
+
const code2 = err.code;
|
|
16786
|
+
if (code2 === "ESRCH") return false;
|
|
16649
16787
|
return true;
|
|
16650
16788
|
}
|
|
16651
16789
|
}
|
|
@@ -17359,7 +17497,7 @@ function buildTelegramHelpMessage(codeName) {
|
|
|
17359
17497
|
"",
|
|
17360
17498
|
`_Type these in any chat where the bot is present (intercepted by the agent):_`,
|
|
17361
17499
|
`\u2022 /help \u2014 show this help`,
|
|
17362
|
-
`\u2022 /status
|
|
17500
|
+
`\u2022 /status - full health report: model, session, uptime + per-channel and per-integration status (cached snapshot, then this channel's own live check)`,
|
|
17363
17501
|
`\u2022 /ping-${codeName} - confirm this agent's channel is connected: posts a visible pong (team members and the agent's reports-to person)`,
|
|
17364
17502
|
`\u2022 /watch <google-doc-url> [duration] \u2014 watch a Google Doc for comments that mention me (default 2h, max 7d; auto-pauses when the window ends)`,
|
|
17365
17503
|
`\u2022 /restart \u2014 restart this agent`,
|
|
@@ -17458,13 +17596,82 @@ function buildTelegramStatusReply() {
|
|
|
17458
17596
|
state
|
|
17459
17597
|
});
|
|
17460
17598
|
}
|
|
17599
|
+
var TELEGRAM_OWN_CHANNEL_ID = "telegram";
|
|
17600
|
+
async function fetchTelegramStatusReport() {
|
|
17601
|
+
if (!AGT_HOST || !AGT_API_KEY || !AGT_AGENT_ID) return null;
|
|
17602
|
+
try {
|
|
17603
|
+
const { apiCall: apiCall2 } = await Promise.resolve().then(() => (init_ask_user_runtime(), ask_user_runtime_exports));
|
|
17604
|
+
const cfg = { apiHost: AGT_HOST, apiKey: AGT_API_KEY, agentId: AGT_AGENT_ID };
|
|
17605
|
+
const res = await apiCall2(
|
|
17606
|
+
cfg,
|
|
17607
|
+
"GET",
|
|
17608
|
+
`/host/status?agent_id=${encodeURIComponent(AGT_AGENT_ID)}`
|
|
17609
|
+
);
|
|
17610
|
+
if (!res.ok) {
|
|
17611
|
+
process.stderr.write(
|
|
17612
|
+
`telegram-channel(${AGENT_CODE_NAME}): /status host fetch returned ${res.status}
|
|
17613
|
+
`
|
|
17614
|
+
);
|
|
17615
|
+
return null;
|
|
17616
|
+
}
|
|
17617
|
+
return parseAgentStatusReport(await res.json());
|
|
17618
|
+
} catch (err) {
|
|
17619
|
+
process.stderr.write(
|
|
17620
|
+
`telegram-channel(${AGENT_CODE_NAME}): /status host fetch failed: ${redactAugmentedPaths(err.message)}
|
|
17621
|
+
`
|
|
17622
|
+
);
|
|
17623
|
+
return null;
|
|
17624
|
+
}
|
|
17625
|
+
}
|
|
17626
|
+
async function computeTelegramOwnChannelLiveStatus() {
|
|
17627
|
+
const checked_at = (/* @__PURE__ */ new Date()).toISOString();
|
|
17628
|
+
try {
|
|
17629
|
+
const resp = await telegramApiCall("getMe", {}, 5e3);
|
|
17630
|
+
if (resp.ok) {
|
|
17631
|
+
return { level: "ok", checked_at, reason: "getMe ok" };
|
|
17632
|
+
}
|
|
17633
|
+
return { level: "error", checked_at, reason: `getMe rejected: ${resp.description ?? "unknown"}` };
|
|
17634
|
+
} catch {
|
|
17635
|
+
return { level: "degraded", checked_at, reason: "getMe failed (transient)" };
|
|
17636
|
+
}
|
|
17637
|
+
}
|
|
17461
17638
|
async function handleStatusCommand(opts) {
|
|
17639
|
+
const configBlock = buildTelegramStatusReply();
|
|
17640
|
+
const report = await fetchTelegramStatusReport();
|
|
17641
|
+
if (!report) {
|
|
17642
|
+
await sendTelegramStatusMessage(
|
|
17643
|
+
opts,
|
|
17644
|
+
`${configBlock}
|
|
17645
|
+
|
|
17646
|
+
_Channel + integration health is unavailable right now (host unreachable). Try again shortly._`
|
|
17647
|
+
);
|
|
17648
|
+
return;
|
|
17649
|
+
}
|
|
17650
|
+
const snapshot = `${configBlock}
|
|
17651
|
+
|
|
17652
|
+
${renderTelegramStatusSections(report, {
|
|
17653
|
+
probing: true,
|
|
17654
|
+
nowMs: Date.now()
|
|
17655
|
+
})}`;
|
|
17656
|
+
const messageId = await sendTelegramStatusMessage(opts, snapshot);
|
|
17657
|
+
const live = await computeTelegramOwnChannelLiveStatus();
|
|
17658
|
+
const merged = mergeOwnChannelLiveStatus(report, TELEGRAM_OWN_CHANNEL_ID, live);
|
|
17659
|
+
const finalReport = `${configBlock}
|
|
17660
|
+
|
|
17661
|
+
${renderTelegramStatusSections(merged, {
|
|
17662
|
+
probing: false,
|
|
17663
|
+
nowMs: Date.now()
|
|
17664
|
+
})}`;
|
|
17665
|
+
if (messageId == null) return;
|
|
17666
|
+
await editTelegramStatusMessage(opts.chatId, messageId, finalReport);
|
|
17667
|
+
}
|
|
17668
|
+
async function sendTelegramStatusMessage(opts, text) {
|
|
17462
17669
|
try {
|
|
17463
17670
|
const resp = await telegramApiCall(
|
|
17464
17671
|
"sendMessage",
|
|
17465
17672
|
{
|
|
17466
17673
|
chat_id: opts.chatId,
|
|
17467
|
-
text
|
|
17674
|
+
text,
|
|
17468
17675
|
parse_mode: "Markdown",
|
|
17469
17676
|
reply_to_message_id: Number(opts.messageId)
|
|
17470
17677
|
},
|
|
@@ -17475,10 +17682,33 @@ async function handleStatusCommand(opts) {
|
|
|
17475
17682
|
`telegram-channel(${AGENT_CODE_NAME}): /status reply rejected by Telegram (chat ${redactId(opts.chatId)}): ${resp.description ?? "unknown"}
|
|
17476
17683
|
`
|
|
17477
17684
|
);
|
|
17685
|
+
return null;
|
|
17478
17686
|
}
|
|
17687
|
+
return typeof resp.result?.message_id === "number" ? resp.result.message_id : null;
|
|
17479
17688
|
} catch (err) {
|
|
17480
17689
|
process.stderr.write(
|
|
17481
17690
|
`telegram-channel(${AGENT_CODE_NAME}): /status reply send failed: ${redactAugmentedPaths(err.message)}
|
|
17691
|
+
`
|
|
17692
|
+
);
|
|
17693
|
+
return null;
|
|
17694
|
+
}
|
|
17695
|
+
}
|
|
17696
|
+
async function editTelegramStatusMessage(chatId, messageId, text) {
|
|
17697
|
+
try {
|
|
17698
|
+
const resp = await telegramApiCall(
|
|
17699
|
+
"editMessageText",
|
|
17700
|
+
{ chat_id: chatId, message_id: messageId, text, parse_mode: "Markdown" },
|
|
17701
|
+
1e4
|
|
17702
|
+
);
|
|
17703
|
+
if (!resp.ok && !/not modified/i.test(resp.description ?? "")) {
|
|
17704
|
+
process.stderr.write(
|
|
17705
|
+
`telegram-channel(${AGENT_CODE_NAME}): /status edit rejected by Telegram (chat ${redactId(chatId)}): ${resp.description ?? "unknown"}
|
|
17706
|
+
`
|
|
17707
|
+
);
|
|
17708
|
+
}
|
|
17709
|
+
} catch (err) {
|
|
17710
|
+
process.stderr.write(
|
|
17711
|
+
`telegram-channel(${AGENT_CODE_NAME}): /status edit send failed: ${redactAugmentedPaths(err.message)}
|
|
17482
17712
|
`
|
|
17483
17713
|
);
|
|
17484
17714
|
}
|