@ebowwa/glm-daemon 0.1.0

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.
Files changed (50) hide show
  1. package/README.md +264 -0
  2. package/dist/agent.d.ts +37 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +97 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/daemon.d.ts +91 -0
  7. package/dist/daemon.d.ts.map +1 -0
  8. package/dist/daemon.js +449 -0
  9. package/dist/daemon.js.map +1 -0
  10. package/dist/hooks.d.ts +34 -0
  11. package/dist/hooks.d.ts.map +1 -0
  12. package/dist/hooks.js +82 -0
  13. package/dist/hooks.js.map +1 -0
  14. package/dist/index.d.ts +21 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +31 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/state.d.ts +31 -0
  19. package/dist/state.d.ts.map +1 -0
  20. package/dist/state.js +67 -0
  21. package/dist/state.js.map +1 -0
  22. package/dist/tools.d.ts +42 -0
  23. package/dist/tools.d.ts.map +1 -0
  24. package/dist/tools.js +110 -0
  25. package/dist/tools.js.map +1 -0
  26. package/dist/types.d.ts +222 -0
  27. package/dist/types.d.ts.map +1 -0
  28. package/dist/types.js +19 -0
  29. package/dist/types.js.map +1 -0
  30. package/dist/worktree.d.ts +42 -0
  31. package/dist/worktree.d.ts.map +1 -0
  32. package/dist/worktree.js +86 -0
  33. package/dist/worktree.js.map +1 -0
  34. package/package.json +70 -0
  35. package/src/agent.js +166 -0
  36. package/src/agent.ts +110 -0
  37. package/src/daemon.js +591 -0
  38. package/src/daemon.ts +529 -0
  39. package/src/hooks.js +145 -0
  40. package/src/hooks.ts +94 -0
  41. package/src/index.js +105 -0
  42. package/src/index.ts +43 -0
  43. package/src/state.js +168 -0
  44. package/src/state.ts +77 -0
  45. package/src/tools.js +192 -0
  46. package/src/tools.ts +134 -0
  47. package/src/types.js +21 -0
  48. package/src/types.ts +249 -0
  49. package/src/worktree.js +195 -0
  50. package/src/worktree.ts +122 -0
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@ebowwa/glm-daemon",
3
+ "version": "0.1.0",
4
+ "description": "Autonomous GLM 4.7 daemon with hooks, tools, and teammates",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./daemon": {
14
+ "types": "./dist/daemon.d.ts",
15
+ "import": "./dist/daemon.js"
16
+ },
17
+ "./agent": {
18
+ "types": "./dist/agent.d.ts",
19
+ "import": "./dist/agent.js"
20
+ },
21
+ "./hooks": {
22
+ "types": "./dist/hooks.d.ts",
23
+ "import": "./dist/hooks.js"
24
+ },
25
+ "./tools": {
26
+ "types": "./dist/tools.d.ts",
27
+ "import": "./dist/tools.js"
28
+ },
29
+ "./state": {
30
+ "types": "./dist/state.d.ts",
31
+ "import": "./dist/state.js"
32
+ },
33
+ "./worktree": {
34
+ "types": "./dist/worktree.d.ts",
35
+ "import": "./dist/worktree.js"
36
+ }
37
+ },
38
+ "scripts": {
39
+ "build": "tsc",
40
+ "build:types": "tsc --emitDeclarationOnly",
41
+ "dev": "bun --watch src/index.ts",
42
+ "test": "bun test",
43
+ "lint": "eslint src --ext .ts",
44
+ "clean": "rm -rf dist"
45
+ },
46
+ "dependencies": {
47
+ "@ebowwa/ai": "^0.1.0",
48
+ "@ebowwa/codespaces-types": "^1.1.0",
49
+ "@ebowwa/teammates": "^0.1.0",
50
+ "zod": "catalog:"
51
+ },
52
+ "devDependencies": {
53
+ "@types/bun": "catalog:dev",
54
+ "@types/node": "catalog:dev",
55
+ "typescript": "catalog:",
56
+ "bun-types": "catalog:dev"
57
+ },
58
+ "files": [
59
+ "dist",
60
+ "src",
61
+ "README.md"
62
+ ],
63
+ "keywords": [
64
+ "glm",
65
+ "daemon",
66
+ "agent",
67
+ "autonomous",
68
+ "ai"
69
+ ]
70
+ }
package/src/agent.js ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ /**
3
+ * GLM Agent - Individual GLM-powered agent
4
+ *
5
+ * Wraps GLM 4.7 API with tool access and hook integration.
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ var __generator = (this && this.__generator) || function (thisArg, body) {
17
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
18
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
19
+ function verb(n) { return function (v) { return step([n, v]); }; }
20
+ function step(op) {
21
+ if (f) throw new TypeError("Generator is already executing.");
22
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
23
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
24
+ if (y = 0, t) op = [op[0] & 2, t.value];
25
+ switch (op[0]) {
26
+ case 0: case 1: t = op; break;
27
+ case 4: _.label++; return { value: op[1], done: false };
28
+ case 5: _.label++; y = op[1]; op = [0]; continue;
29
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
30
+ default:
31
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
32
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
33
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
34
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
35
+ if (t[2]) _.ops.pop();
36
+ _.trys.pop(); continue;
37
+ }
38
+ op = body.call(thisArg, _);
39
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
40
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
41
+ }
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.GLMAgent = void 0;
45
+ var client_1 = require("@codespaces/ai/client");
46
+ var GLMAgent = /** @class */ (function () {
47
+ function GLMAgent(config) {
48
+ this.tools = new Map();
49
+ this.config = config;
50
+ this.client = new client_1.GLMClient();
51
+ }
52
+ /**
53
+ * Execute a prompt and get response
54
+ */
55
+ GLMAgent.prototype.execute = function (prompt, tools) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var messages, response;
58
+ return __generator(this, function (_a) {
59
+ switch (_a.label) {
60
+ case 0:
61
+ messages = [
62
+ {
63
+ role: "system",
64
+ content: this.config.prompt,
65
+ },
66
+ {
67
+ role: "user",
68
+ content: prompt,
69
+ },
70
+ ];
71
+ // Add tool context if provided
72
+ if (tools) {
73
+ messages.push({
74
+ role: "user",
75
+ content: "\nAvailable tools: ".concat(Object.keys(tools).join(", ")),
76
+ });
77
+ }
78
+ return [4 /*yield*/, this.client.chat({
79
+ messages: messages,
80
+ model: this.config.model || "glm-4.7",
81
+ temperature: this.config.temperature || 0.7,
82
+ maxTokens: this.config.maxTokens || 4096,
83
+ })];
84
+ case 1:
85
+ response = _a.sent();
86
+ return [2 /*return*/, response.content || ""];
87
+ }
88
+ });
89
+ });
90
+ };
91
+ /**
92
+ * Execute a tool call
93
+ */
94
+ GLMAgent.prototype.executeTool = function (toolName, args) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var start, tool, result, error_1;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ start = Date.now();
101
+ tool = this.tools.get(toolName);
102
+ if (!tool) {
103
+ return [2 /*return*/, {
104
+ success: false,
105
+ error: "Tool not found: ".concat(toolName),
106
+ duration: Date.now() - start,
107
+ }];
108
+ }
109
+ _a.label = 1;
110
+ case 1:
111
+ _a.trys.push([1, 3, , 4]);
112
+ return [4 /*yield*/, tool(args)];
113
+ case 2:
114
+ result = _a.sent();
115
+ return [2 /*return*/, {
116
+ success: true,
117
+ result: result,
118
+ duration: Date.now() - start,
119
+ }];
120
+ case 3:
121
+ error_1 = _a.sent();
122
+ return [2 /*return*/, {
123
+ success: false,
124
+ error: error_1 instanceof Error ? error_1.message : String(error_1),
125
+ duration: Date.now() - start,
126
+ }];
127
+ case 4: return [2 /*return*/];
128
+ }
129
+ });
130
+ });
131
+ };
132
+ /**
133
+ * Register a tool
134
+ */
135
+ GLMAgent.prototype.registerTool = function (name, handler) {
136
+ this.tools.set(name, handler);
137
+ };
138
+ /**
139
+ * Get available tools
140
+ */
141
+ GLMAgent.prototype.getAvailableTools = function () {
142
+ return Array.from(this.tools.keys());
143
+ };
144
+ Object.defineProperty(GLMAgent.prototype, "agentId", {
145
+ /**
146
+ * Get agent ID
147
+ */
148
+ get: function () {
149
+ return this.config.agentId;
150
+ },
151
+ enumerable: false,
152
+ configurable: true
153
+ });
154
+ Object.defineProperty(GLMAgent.prototype, "name", {
155
+ /**
156
+ * Get agent name
157
+ */
158
+ get: function () {
159
+ return this.config.name;
160
+ },
161
+ enumerable: false,
162
+ configurable: true
163
+ });
164
+ return GLMAgent;
165
+ }());
166
+ exports.GLMAgent = GLMAgent;
package/src/agent.ts ADDED
@@ -0,0 +1,110 @@
1
+ /**
2
+ * GLM Agent - Individual GLM-powered agent
3
+ *
4
+ * Wraps GLM 4.7 API with tool access and hook integration.
5
+ */
6
+
7
+ import type { GLMAgentConfig, GLMToolResult } from "./types.js";
8
+ import { GLMClient, type ChatMessage } from "@ebowwa/ai/client";
9
+
10
+ export class GLMAgent {
11
+ private config: GLMAgentConfig;
12
+ private client: GLMClient;
13
+ private tools: Map<string, (args: unknown) => Promise<unknown>> = new Map();
14
+
15
+ constructor(config: GLMAgentConfig) {
16
+ this.config = config;
17
+ this.client = new GLMClient();
18
+ }
19
+
20
+ /**
21
+ * Execute a prompt and get response
22
+ */
23
+ async execute(prompt: string, tools?: Record<string, unknown>): Promise<string> {
24
+ const messages: ChatMessage[] = [
25
+ {
26
+ role: "system",
27
+ content: this.config.prompt,
28
+ },
29
+ {
30
+ role: "user",
31
+ content: prompt,
32
+ },
33
+ ];
34
+
35
+ // Add tool context if provided
36
+ if (tools) {
37
+ messages.push({
38
+ role: "user",
39
+ content: `\nAvailable tools: ${Object.keys(tools).join(", ")}`,
40
+ });
41
+ }
42
+
43
+ const response = await this.client.chatCompletion(messages, {
44
+ model: this.config.model || "glm-4.7",
45
+ temperature: this.config.temperature || 0.7,
46
+ maxTokens: this.config.maxTokens || 4096,
47
+ });
48
+
49
+ return response.choices[0]?.message?.content || "";
50
+ }
51
+
52
+ /**
53
+ * Execute a tool call
54
+ */
55
+ async executeTool(toolName: string, args: unknown): Promise<GLMToolResult> {
56
+ const start = Date.now();
57
+ const tool = this.tools.get(toolName);
58
+
59
+ if (!tool) {
60
+ return {
61
+ success: false,
62
+ error: `Tool not found: ${toolName}`,
63
+ duration: Date.now() - start,
64
+ };
65
+ }
66
+
67
+ try {
68
+ const result = await tool(args);
69
+ return {
70
+ success: true,
71
+ result,
72
+ duration: Date.now() - start,
73
+ };
74
+ } catch (error) {
75
+ return {
76
+ success: false,
77
+ error: error instanceof Error ? error.message : String(error),
78
+ duration: Date.now() - start,
79
+ };
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Register a tool
85
+ */
86
+ registerTool(name: string, handler: (args: unknown) => Promise<unknown>): void {
87
+ this.tools.set(name, handler);
88
+ }
89
+
90
+ /**
91
+ * Get available tools
92
+ */
93
+ getAvailableTools(): string[] {
94
+ return Array.from(this.tools.keys());
95
+ }
96
+
97
+ /**
98
+ * Get agent ID
99
+ */
100
+ get agentId(): string {
101
+ return this.config.agentId;
102
+ }
103
+
104
+ /**
105
+ * Get agent name
106
+ */
107
+ get name(): string {
108
+ return this.config.name;
109
+ }
110
+ }