pretticlaw 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 (158) hide show
  1. package/CONTRIBUTING.md +123 -0
  2. package/README.md +150 -0
  3. package/assets/logo.png +0 -0
  4. package/dist/agent/context.d.ts +22 -0
  5. package/dist/agent/context.js +85 -0
  6. package/dist/agent/loop.d.ts +63 -0
  7. package/dist/agent/loop.js +244 -0
  8. package/dist/agent/memory.d.ts +16 -0
  9. package/dist/agent/memory.js +98 -0
  10. package/dist/agent/skills.d.ts +18 -0
  11. package/dist/agent/skills.js +121 -0
  12. package/dist/agent/subagent.d.ts +30 -0
  13. package/dist/agent/subagent.js +92 -0
  14. package/dist/agent/tools/base.d.ts +10 -0
  15. package/dist/agent/tools/base.js +58 -0
  16. package/dist/agent/tools/cron.d.ts +43 -0
  17. package/dist/agent/tools/cron.js +83 -0
  18. package/dist/agent/tools/filesystem.d.ts +79 -0
  19. package/dist/agent/tools/filesystem.js +125 -0
  20. package/dist/agent/tools/message.d.ts +41 -0
  21. package/dist/agent/tools/message.js +55 -0
  22. package/dist/agent/tools/registry.d.ts +9 -0
  23. package/dist/agent/tools/registry.js +33 -0
  24. package/dist/agent/tools/shell.d.ts +26 -0
  25. package/dist/agent/tools/shell.js +78 -0
  26. package/dist/agent/tools/spawn.d.ts +27 -0
  27. package/dist/agent/tools/spawn.js +35 -0
  28. package/dist/agent/tools/web.d.ts +50 -0
  29. package/dist/agent/tools/web.js +119 -0
  30. package/dist/bus/async-queue.d.ts +7 -0
  31. package/dist/bus/async-queue.js +20 -0
  32. package/dist/bus/events.d.ts +19 -0
  33. package/dist/bus/events.js +3 -0
  34. package/dist/bus/queue.d.ts +12 -0
  35. package/dist/bus/queue.js +23 -0
  36. package/dist/channels/base.d.ts +22 -0
  37. package/dist/channels/base.js +35 -0
  38. package/dist/channels/discord.d.ts +24 -0
  39. package/dist/channels/discord.js +133 -0
  40. package/dist/channels/manager.d.ts +17 -0
  41. package/dist/channels/manager.js +67 -0
  42. package/dist/channels/stub.d.ts +10 -0
  43. package/dist/channels/stub.js +18 -0
  44. package/dist/channels/telegram.d.ts +20 -0
  45. package/dist/channels/telegram.js +93 -0
  46. package/dist/cli/commands.d.ts +2 -0
  47. package/dist/cli/commands.js +552 -0
  48. package/dist/config/loader.d.ts +5 -0
  49. package/dist/config/loader.js +55 -0
  50. package/dist/config/schema.d.ts +246 -0
  51. package/dist/config/schema.js +94 -0
  52. package/dist/cron/service.d.ts +33 -0
  53. package/dist/cron/service.js +195 -0
  54. package/dist/cron/types.d.ts +47 -0
  55. package/dist/cron/types.js +1 -0
  56. package/dist/dashboard/index.html +1567 -0
  57. package/dist/heartbeat/service.d.ts +21 -0
  58. package/dist/heartbeat/service.js +101 -0
  59. package/dist/index.d.ts +2 -0
  60. package/dist/index.js +5 -0
  61. package/dist/providers/base.d.ts +23 -0
  62. package/dist/providers/base.js +21 -0
  63. package/dist/providers/custom-provider.d.ts +16 -0
  64. package/dist/providers/custom-provider.js +49 -0
  65. package/dist/providers/litellm-provider.d.ts +19 -0
  66. package/dist/providers/litellm-provider.js +128 -0
  67. package/dist/providers/registry.d.ts +5 -0
  68. package/dist/providers/registry.js +45 -0
  69. package/dist/session/manager.d.ts +31 -0
  70. package/dist/session/manager.js +116 -0
  71. package/dist/skills/README.md +25 -0
  72. package/dist/skills/clawhub/SKILL.md +53 -0
  73. package/dist/skills/cron/SKILL.md +57 -0
  74. package/dist/skills/github/SKILL.md +48 -0
  75. package/dist/skills/memory/SKILL.md +31 -0
  76. package/dist/skills/skill-creator/SKILL.md +371 -0
  77. package/dist/skills/summarize/SKILL.md +67 -0
  78. package/dist/skills/tmux/SKILL.md +121 -0
  79. package/dist/skills/tmux/scripts/find-sessions.sh +112 -0
  80. package/dist/skills/tmux/scripts/wait-for-text.sh +83 -0
  81. package/dist/skills/weather/SKILL.md +49 -0
  82. package/dist/templates/AGENTS.md +23 -0
  83. package/dist/templates/HEARTBEAT.md +16 -0
  84. package/dist/templates/SOUL.md +21 -0
  85. package/dist/templates/TOOLS.md +15 -0
  86. package/dist/templates/USER.md +49 -0
  87. package/dist/templates/memory/MEMORY.md +23 -0
  88. package/dist/types.d.ts +4 -0
  89. package/dist/types.js +3 -0
  90. package/dist/utils/helpers.d.ts +5 -0
  91. package/dist/utils/helpers.js +53 -0
  92. package/dist/web/server.d.ts +15 -0
  93. package/dist/web/server.js +169 -0
  94. package/package.json +37 -0
  95. package/scripts/copy-assets.mjs +21 -0
  96. package/src/agent/context.ts +90 -0
  97. package/src/agent/loop.ts +291 -0
  98. package/src/agent/memory.ts +104 -0
  99. package/src/agent/skills.ts +121 -0
  100. package/src/agent/subagent.ts +96 -0
  101. package/src/agent/tools/base.ts +59 -0
  102. package/src/agent/tools/cron.ts +79 -0
  103. package/src/agent/tools/filesystem.ts +93 -0
  104. package/src/agent/tools/message.ts +57 -0
  105. package/src/agent/tools/registry.ts +36 -0
  106. package/src/agent/tools/shell.ts +69 -0
  107. package/src/agent/tools/spawn.ts +37 -0
  108. package/src/agent/tools/web.ts +108 -0
  109. package/src/bus/async-queue.ts +20 -0
  110. package/src/bus/events.ts +23 -0
  111. package/src/bus/queue.ts +31 -0
  112. package/src/channels/base.ts +36 -0
  113. package/src/channels/discord.ts +156 -0
  114. package/src/channels/manager.ts +70 -0
  115. package/src/channels/stub.ts +20 -0
  116. package/src/channels/telegram.ts +120 -0
  117. package/src/cli/commands.ts +581 -0
  118. package/src/config/loader.ts +58 -0
  119. package/src/config/schema.ts +144 -0
  120. package/src/cron/service.ts +190 -0
  121. package/src/cron/types.ts +36 -0
  122. package/src/dashboard/index.html +1567 -0
  123. package/src/heartbeat/service.ts +95 -0
  124. package/src/index.ts +6 -0
  125. package/src/providers/base.ts +43 -0
  126. package/src/providers/custom-provider.ts +46 -0
  127. package/src/providers/litellm-provider.ts +131 -0
  128. package/src/providers/registry.ts +48 -0
  129. package/src/session/manager.ts +129 -0
  130. package/src/skills/README.md +25 -0
  131. package/src/skills/clawhub/SKILL.md +53 -0
  132. package/src/skills/cron/SKILL.md +57 -0
  133. package/src/skills/github/SKILL.md +48 -0
  134. package/src/skills/memory/SKILL.md +31 -0
  135. package/src/skills/skill-creator/SKILL.md +371 -0
  136. package/src/skills/summarize/SKILL.md +67 -0
  137. package/src/skills/tmux/SKILL.md +121 -0
  138. package/src/skills/tmux/scripts/find-sessions.sh +112 -0
  139. package/src/skills/tmux/scripts/wait-for-text.sh +83 -0
  140. package/src/skills/weather/SKILL.md +49 -0
  141. package/src/templates/AGENTS.md +23 -0
  142. package/src/templates/HEARTBEAT.md +16 -0
  143. package/src/templates/SOUL.md +21 -0
  144. package/src/templates/TOOLS.md +15 -0
  145. package/src/templates/USER.md +49 -0
  146. package/src/templates/memory/MEMORY.md +23 -0
  147. package/src/types/prompts.d.ts +14 -0
  148. package/src/types/ws.d.ts +15 -0
  149. package/src/types.ts +5 -0
  150. package/src/utils/helpers.ts +55 -0
  151. package/src/web/server.ts +198 -0
  152. package/test/context.test.ts +27 -0
  153. package/test/cron-service.test.ts +31 -0
  154. package/test/message-tool.test.ts +10 -0
  155. package/test/providers.test.ts +43 -0
  156. package/test/tool-validation.test.ts +61 -0
  157. package/tsconfig.json +16 -0
  158. package/vitest.config.ts +8 -0
@@ -0,0 +1,120 @@
1
+ import type { OutboundMessage } from "../bus/events.js";
2
+ import type { MessageBus } from "../bus/queue.js";
3
+ import { BaseChannel } from "./base.js";
4
+
5
+ type TelegramConfig = {
6
+ enabled: boolean;
7
+ token: string;
8
+ allowFrom: string[];
9
+ proxy: string | null;
10
+ replyToMessage: boolean;
11
+ };
12
+
13
+ type TelegramUpdate = {
14
+ update_id: number;
15
+ message?: {
16
+ message_id: number;
17
+ chat: { id: number | string };
18
+ from?: { id: number | string; username?: string; is_bot?: boolean };
19
+ text?: string;
20
+ caption?: string;
21
+ };
22
+ };
23
+
24
+ function splitMessage(content: string, maxLen = 4000): string[] {
25
+ if (content.length <= maxLen) return [content];
26
+ const chunks: string[] = [];
27
+ let rest = content;
28
+ while (rest.length > maxLen) {
29
+ let cut = rest.slice(0, maxLen);
30
+ let idx = Math.max(cut.lastIndexOf("\n"), cut.lastIndexOf(" "));
31
+ if (idx <= 0) idx = maxLen;
32
+ chunks.push(rest.slice(0, idx));
33
+ rest = rest.slice(idx).trimStart();
34
+ }
35
+ if (rest) chunks.push(rest);
36
+ return chunks;
37
+ }
38
+
39
+ export class TelegramChannel extends BaseChannel<TelegramConfig> {
40
+ readonly name = "telegram";
41
+ private offset = 0;
42
+
43
+ constructor(config: TelegramConfig, bus: MessageBus) {
44
+ super(config, bus);
45
+ }
46
+
47
+ private api(path: string): string {
48
+ return `https://api.telegram.org/bot${this.config.token}/${path}`;
49
+ }
50
+
51
+ async start(): Promise<void> {
52
+ if (!this.config.token) {
53
+ console.error("Telegram token not configured");
54
+ return;
55
+ }
56
+
57
+ this.running = true;
58
+ while (this.running) {
59
+ try {
60
+ const url = new URL(this.api("getUpdates"));
61
+ url.searchParams.set("timeout", "25");
62
+ url.searchParams.set("offset", String(this.offset));
63
+ url.searchParams.set("allowed_updates", JSON.stringify(["message"]));
64
+
65
+ const res = await fetch(url);
66
+ if (!res.ok) {
67
+ await new Promise((r) => setTimeout(r, 1500));
68
+ continue;
69
+ }
70
+
71
+ const data = (await res.json()) as { ok: boolean; result: TelegramUpdate[] };
72
+ if (!data.ok) continue;
73
+
74
+ for (const update of data.result) {
75
+ this.offset = update.update_id + 1;
76
+ const msg = update.message;
77
+ if (!msg) continue;
78
+ if (msg.from?.is_bot) continue;
79
+
80
+ const senderBase = String(msg.from?.id ?? "unknown");
81
+ const sender = msg.from?.username ? `${senderBase}|@${msg.from.username}` : senderBase;
82
+ const content = msg.text ?? msg.caption ?? "[Unsupported message]";
83
+
84
+ await this.handleMessage({
85
+ senderId: sender,
86
+ chatId: String(msg.chat.id),
87
+ content,
88
+ metadata: { message_id: msg.message_id },
89
+ });
90
+ }
91
+ } catch {
92
+ await new Promise((r) => setTimeout(r, 1500));
93
+ }
94
+ }
95
+ }
96
+
97
+ async stop(): Promise<void> {
98
+ this.running = false;
99
+ }
100
+
101
+ async send(msg: OutboundMessage): Promise<void> {
102
+ if (!this.config.token) return;
103
+ const chunks = splitMessage(msg.content || "");
104
+ for (const chunk of chunks) {
105
+ const payload: Record<string, unknown> = {
106
+ chat_id: msg.chatId,
107
+ text: chunk,
108
+ };
109
+
110
+ const replyTo = msg.metadata?.message_id;
111
+ if (this.config.replyToMessage && replyTo) payload.reply_parameters = { message_id: replyTo };
112
+
113
+ await fetch(this.api("sendMessage"), {
114
+ method: "POST",
115
+ headers: { "Content-Type": "application/json" },
116
+ body: JSON.stringify(payload),
117
+ }).catch(() => undefined);
118
+ }
119
+ }
120
+ }