feat: Complete zCode CLI X with Telegram bot integration

- Add full Telegram bot functionality with Z.AI API integration
- Implement 4 tools: Bash, FileEdit, WebSearch, Git
- Add 3 agents: Code Reviewer, Architect, DevOps Engineer
- Add 6 skills for common coding tasks
- Add systemd service file for 24/7 operation
- Add nginx configuration for HTTPS webhook
- Add comprehensive documentation
- Implement WebSocket server for real-time updates
- Add logging system with Winston
- Add environment validation

🤖 zCode CLI X - Agentic coder with Z.AI + Telegram integration
This commit is contained in:
admin
2026-05-05 09:01:26 +00:00
Unverified
parent 4a7035dd92
commit 875c7f9b91
24688 changed files with 3224957 additions and 221 deletions

View File

@@ -0,0 +1,50 @@
import type { ContextManager, Context } from '@opentelemetry/api';
export declare abstract class AbstractAsyncHooksContextManager implements ContextManager {
abstract active(): Context;
abstract with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
abstract enable(): this;
abstract disable(): this;
/**
* Binds a the certain context or the active one to the target function and then returns the target
* @param context A context (span) to be bind to target
* @param target a function or event emitter. When target or one of its callbacks is called,
* the provided context will be used as the active context for the duration of the call.
*/
bind<T>(context: Context, target: T): T;
private _bindFunction;
/**
* By default, EventEmitter call their callback with their context, which we do
* not want, instead we will bind a specific context to all callbacks that
* go through it.
* @param context the context we want to bind
* @param ee EventEmitter an instance of EventEmitter to patch
*/
private _bindEventEmitter;
/**
* Patch methods that remove a given listener so that we match the "patched"
* version of that listener (the one that propagate context).
* @param ee EventEmitter instance
* @param original reference to the patched method
*/
private _patchRemoveListener;
/**
* Patch methods that remove all listeners so we remove our
* internal references for a given event.
* @param ee EventEmitter instance
* @param original reference to the patched method
*/
private _patchRemoveAllListeners;
/**
* Patch methods on an event emitter instance that can add listeners so we
* can force them to propagate a given context.
* @param ee EventEmitter instance
* @param original reference to the patched method
* @param [context] context to propagate when calling listeners
*/
private _patchAddListener;
private _createPatchMap;
private _getPatchMap;
private readonly _kOtListeners;
private _wrapped;
}
//# sourceMappingURL=AbstractAsyncHooksContextManager.d.ts.map

View File

@@ -0,0 +1,177 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AbstractAsyncHooksContextManager = void 0;
const events_1 = require("events");
const ADD_LISTENER_METHODS = [
'addListener',
'on',
'once',
'prependListener',
'prependOnceListener',
];
class AbstractAsyncHooksContextManager {
/**
* Binds a the certain context or the active one to the target function and then returns the target
* @param context A context (span) to be bind to target
* @param target a function or event emitter. When target or one of its callbacks is called,
* the provided context will be used as the active context for the duration of the call.
*/
bind(context, target) {
if (target instanceof events_1.EventEmitter) {
return this._bindEventEmitter(context, target);
}
if (typeof target === 'function') {
return this._bindFunction(context, target);
}
return target;
}
_bindFunction(context, target) {
const manager = this;
const contextWrapper = function (...args) {
return manager.with(context, () => target.apply(this, args));
};
Object.defineProperty(contextWrapper, 'length', {
enumerable: false,
configurable: true,
writable: false,
value: target.length,
});
/**
* It isn't possible to tell Typescript that contextWrapper is the same as T
* so we forced to cast as any here.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return contextWrapper;
}
/**
* By default, EventEmitter call their callback with their context, which we do
* not want, instead we will bind a specific context to all callbacks that
* go through it.
* @param context the context we want to bind
* @param ee EventEmitter an instance of EventEmitter to patch
*/
_bindEventEmitter(context, ee) {
const map = this._getPatchMap(ee);
if (map !== undefined)
return ee;
this._createPatchMap(ee);
// patch methods that add a listener to propagate context
ADD_LISTENER_METHODS.forEach(methodName => {
if (ee[methodName] === undefined)
return;
ee[methodName] = this._patchAddListener(ee, ee[methodName], context);
});
// patch methods that remove a listener
if (typeof ee.removeListener === 'function') {
ee.removeListener = this._patchRemoveListener(ee, ee.removeListener);
}
if (typeof ee.off === 'function') {
ee.off = this._patchRemoveListener(ee, ee.off);
}
// patch method that remove all listeners
if (typeof ee.removeAllListeners === 'function') {
ee.removeAllListeners = this._patchRemoveAllListeners(ee, ee.removeAllListeners);
}
return ee;
}
/**
* Patch methods that remove a given listener so that we match the "patched"
* version of that listener (the one that propagate context).
* @param ee EventEmitter instance
* @param original reference to the patched method
*/
_patchRemoveListener(ee, original) {
const contextManager = this;
return function (event, listener) {
const events = contextManager._getPatchMap(ee)?.[event];
if (events === undefined) {
return original.call(this, event, listener);
}
const patchedListener = events.get(listener);
return original.call(this, event, patchedListener || listener);
};
}
/**
* Patch methods that remove all listeners so we remove our
* internal references for a given event.
* @param ee EventEmitter instance
* @param original reference to the patched method
*/
_patchRemoveAllListeners(ee, original) {
const contextManager = this;
return function (event) {
const map = contextManager._getPatchMap(ee);
if (map !== undefined) {
if (arguments.length === 0) {
contextManager._createPatchMap(ee);
}
else if (map[event] !== undefined) {
delete map[event];
}
}
return original.apply(this, arguments);
};
}
/**
* Patch methods on an event emitter instance that can add listeners so we
* can force them to propagate a given context.
* @param ee EventEmitter instance
* @param original reference to the patched method
* @param [context] context to propagate when calling listeners
*/
_patchAddListener(ee, original, context) {
const contextManager = this;
return function (event, listener) {
/**
* This check is required to prevent double-wrapping the listener.
* The implementation for ee.once wraps the listener and calls ee.on.
* Without this check, we would wrap that wrapped listener.
* This causes an issue because ee.removeListener depends on the onceWrapper
* to properly remove the listener. If we wrap their wrapper, we break
* that detection.
*/
if (contextManager._wrapped) {
return original.call(this, event, listener);
}
let map = contextManager._getPatchMap(ee);
if (map === undefined) {
map = contextManager._createPatchMap(ee);
}
let listeners = map[event];
if (listeners === undefined) {
listeners = new WeakMap();
map[event] = listeners;
}
const patchedListener = contextManager.bind(context, listener);
// store a weak reference of the user listener to ours
listeners.set(listener, patchedListener);
/**
* See comment at the start of this function for the explanation of this property.
*/
contextManager._wrapped = true;
try {
return original.call(this, event, patchedListener);
}
finally {
contextManager._wrapped = false;
}
};
}
_createPatchMap(ee) {
const map = Object.create(null);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ee[this._kOtListeners] = map;
return map;
}
_getPatchMap(ee) {
return ee[this._kOtListeners];
}
_kOtListeners = Symbol('OtListeners');
_wrapped = false;
}
exports.AbstractAsyncHooksContextManager = AbstractAsyncHooksContextManager;
//# sourceMappingURL=AbstractAsyncHooksContextManager.js.map

View File

@@ -0,0 +1,46 @@
import type { Context } from '@opentelemetry/api';
import { AbstractAsyncHooksContextManager } from './AbstractAsyncHooksContextManager';
/**
* @deprecated Use AsyncLocalStorageContextManager instead.
*/
export declare class AsyncHooksContextManager extends AbstractAsyncHooksContextManager {
private _asyncHook;
private _contexts;
private _stack;
constructor();
active(): Context;
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
enable(): this;
disable(): this;
/**
* Init hook will be called when userland create a async context, setting the
* context as the current one if it exist.
* @param uid id of the async context
* @param type the resource type
*/
private _init;
/**
* Destroy hook will be called when a given context is no longer used so we can
* remove its attached context.
* @param uid uid of the async context
*/
private _destroy;
/**
* Before hook is called just before executing a async context.
* @param uid uid of the async context
*/
private _before;
/**
* After hook is called just after completing the execution of a async context.
*/
private _after;
/**
* Set the given context as active
*/
private _enterContext;
/**
* Remove the context at the root of the stack
*/
private _exitContext;
}
//# sourceMappingURL=AsyncHooksContextManager.d.ts.map

View File

@@ -0,0 +1,106 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncHooksContextManager = void 0;
const api_1 = require("@opentelemetry/api");
const asyncHooks = require("async_hooks");
const AbstractAsyncHooksContextManager_1 = require("./AbstractAsyncHooksContextManager");
/**
* @deprecated Use AsyncLocalStorageContextManager instead.
*/
class AsyncHooksContextManager extends AbstractAsyncHooksContextManager_1.AbstractAsyncHooksContextManager {
_asyncHook;
_contexts = new Map();
_stack = [];
constructor() {
super();
this._asyncHook = asyncHooks.createHook({
init: this._init.bind(this),
before: this._before.bind(this),
after: this._after.bind(this),
destroy: this._destroy.bind(this),
promiseResolve: this._destroy.bind(this),
});
}
active() {
return this._stack[this._stack.length - 1] ?? api_1.ROOT_CONTEXT;
}
with(context, fn, thisArg, ...args) {
this._enterContext(context);
try {
return fn.call(thisArg, ...args);
}
finally {
this._exitContext();
}
}
enable() {
this._asyncHook.enable();
return this;
}
disable() {
this._asyncHook.disable();
this._contexts.clear();
this._stack = [];
return this;
}
/**
* Init hook will be called when userland create a async context, setting the
* context as the current one if it exist.
* @param uid id of the async context
* @param type the resource type
*/
_init(uid, type) {
// ignore TIMERWRAP as they combine timers with same timeout which can lead to
// false context propagation. TIMERWRAP has been removed in node 11
// every timer has it's own `Timeout` resource anyway which is used to propagate
// context.
if (type === 'TIMERWRAP')
return;
const context = this._stack[this._stack.length - 1];
if (context !== undefined) {
this._contexts.set(uid, context);
}
}
/**
* Destroy hook will be called when a given context is no longer used so we can
* remove its attached context.
* @param uid uid of the async context
*/
_destroy(uid) {
this._contexts.delete(uid);
}
/**
* Before hook is called just before executing a async context.
* @param uid uid of the async context
*/
_before(uid) {
const context = this._contexts.get(uid);
if (context !== undefined) {
this._enterContext(context);
}
}
/**
* After hook is called just after completing the execution of a async context.
*/
_after() {
this._exitContext();
}
/**
* Set the given context as active
*/
_enterContext(context) {
this._stack.push(context);
}
/**
* Remove the context at the root of the stack
*/
_exitContext() {
this._stack.pop();
}
}
exports.AsyncHooksContextManager = AsyncHooksContextManager;
//# sourceMappingURL=AsyncHooksContextManager.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
import type { Context } from '@opentelemetry/api';
import { AbstractAsyncHooksContextManager } from './AbstractAsyncHooksContextManager';
export declare class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextManager {
private _asyncLocalStorage;
constructor();
active(): Context;
with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: Context, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
enable(): this;
disable(): this;
}
//# sourceMappingURL=AsyncLocalStorageContextManager.d.ts.map

View File

@@ -0,0 +1,33 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncLocalStorageContextManager = void 0;
const api_1 = require("@opentelemetry/api");
const async_hooks_1 = require("async_hooks");
const AbstractAsyncHooksContextManager_1 = require("./AbstractAsyncHooksContextManager");
class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextManager_1.AbstractAsyncHooksContextManager {
_asyncLocalStorage;
constructor() {
super();
this._asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
}
active() {
return this._asyncLocalStorage.getStore() ?? api_1.ROOT_CONTEXT;
}
with(context, fn, thisArg, ...args) {
const cb = thisArg == null ? fn : fn.bind(thisArg);
return this._asyncLocalStorage.run(context, cb, ...args);
}
enable() {
return this;
}
disable() {
this._asyncLocalStorage.disable();
return this;
}
}
exports.AsyncLocalStorageContextManager = AsyncLocalStorageContextManager;
//# sourceMappingURL=AsyncLocalStorageContextManager.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"AsyncLocalStorageContextManager.js","sourceRoot":"","sources":["../../src/AsyncLocalStorageContextManager.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,4CAAkD;AAClD,6CAAgD;AAChD,yFAAsF;AAEtF,MAAa,+BAAgC,SAAQ,mEAAgC;IAC3E,kBAAkB,CAA6B;IAEvD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,kBAAkB,GAAG,IAAI,+BAAiB,EAAE,CAAC;IACpD,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,kBAAY,CAAC;IAC5D,CAAC;IAED,IAAI,CACF,OAAgB,EAChB,EAAK,EACL,OAA8B,EAC9B,GAAG,IAAO;QAEV,MAAM,EAAE,GAAG,OAAO,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnD,OAAO,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAW,EAAE,GAAG,IAAI,CAAC,CAAC;IACpE,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA9BD,0EA8BC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { Context } from '@opentelemetry/api';\nimport { ROOT_CONTEXT } from '@opentelemetry/api';\nimport { AsyncLocalStorage } from 'async_hooks';\nimport { AbstractAsyncHooksContextManager } from './AbstractAsyncHooksContextManager';\n\nexport class AsyncLocalStorageContextManager extends AbstractAsyncHooksContextManager {\n private _asyncLocalStorage: AsyncLocalStorage<Context>;\n\n constructor() {\n super();\n this._asyncLocalStorage = new AsyncLocalStorage();\n }\n\n active(): Context {\n return this._asyncLocalStorage.getStore() ?? ROOT_CONTEXT;\n }\n\n with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(\n context: Context,\n fn: F,\n thisArg?: ThisParameterType<F>,\n ...args: A\n ): ReturnType<F> {\n const cb = thisArg == null ? fn : fn.bind(thisArg);\n return this._asyncLocalStorage.run(context, cb as never, ...args);\n }\n\n enable(): this {\n return this;\n }\n\n disable(): this {\n this._asyncLocalStorage.disable();\n return this;\n }\n}\n"]}

View File

@@ -0,0 +1,3 @@
export { AsyncHooksContextManager } from './AsyncHooksContextManager';
export { AsyncLocalStorageContextManager } from './AsyncLocalStorageContextManager';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1,12 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.AsyncLocalStorageContextManager = exports.AsyncHooksContextManager = void 0;
var AsyncHooksContextManager_1 = require("./AsyncHooksContextManager");
Object.defineProperty(exports, "AsyncHooksContextManager", { enumerable: true, get: function () { return AsyncHooksContextManager_1.AsyncHooksContextManager; } });
var AsyncLocalStorageContextManager_1 = require("./AsyncLocalStorageContextManager");
Object.defineProperty(exports, "AsyncLocalStorageContextManager", { enumerable: true, get: function () { return AsyncLocalStorageContextManager_1.AsyncLocalStorageContextManager; } });
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,qFAAoF;AAA3E,kJAAA,+BAA+B,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nexport { AsyncHooksContextManager } from './AsyncHooksContextManager';\nexport { AsyncLocalStorageContextManager } from './AsyncLocalStorageContextManager';\n"]}

View File

@@ -0,0 +1,2 @@
export declare const VERSION = "2.6.1";
//# sourceMappingURL=version.d.ts.map

View File

@@ -0,0 +1,10 @@
"use strict";
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
// this is autogenerated file, see scripts/version-update.js
exports.VERSION = '2.6.1';
//# sourceMappingURL=version.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '2.6.1';\n"]}