pi-harness-runtime 1.1.161 → 1.1.162

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 (109) hide show
  1. package/harness/telegram-auth.ts +150 -0
  2. package/harness/telegram-content-filter.ts +223 -0
  3. package/package.json +1 -1
  4. package/packages/a2a-adapter/package.json +1 -1
  5. package/packages/agent-policy/package.json +1 -1
  6. package/packages/architecture-generator/package.json +1 -1
  7. package/packages/auth/package.json +1 -1
  8. package/packages/autonomous-refactor/package.json +1 -1
  9. package/packages/autonomous-runtime/package.json +1 -1
  10. package/packages/cache-strategy/package.json +1 -1
  11. package/packages/capability-registry/package.json +1 -1
  12. package/packages/checkpoint/package.json +1 -1
  13. package/packages/cli-plugin-sdk/package.json +1 -1
  14. package/packages/clipboard/package.json +1 -1
  15. package/packages/clipboard-plugin/package.json +1 -1
  16. package/packages/code-generation/package.json +1 -1
  17. package/packages/code-review/package.json +1 -1
  18. package/packages/codex-adapter/package.json +1 -1
  19. package/packages/codex-watcher/package.json +1 -1
  20. package/packages/config-capture/package.json +1 -1
  21. package/packages/context-compiler/package.json +1 -1
  22. package/packages/context-discovery/package.json +1 -1
  23. package/packages/context-manager/package.json +1 -1
  24. package/packages/cookie-sanitizer/package.json +1 -1
  25. package/packages/cost-optimizer/package.json +1 -1
  26. package/packages/dependency-analyzer/package.json +1 -1
  27. package/packages/django-plugin/package.json +1 -1
  28. package/packages/doc-generator/package.json +1 -1
  29. package/packages/evaluation-engine/package.json +1 -1
  30. package/packages/evaluation-runner/package.json +1 -1
  31. package/packages/event-bus/package.json +1 -1
  32. package/packages/event-store/package.json +1 -1
  33. package/packages/experience-replay/package.json +1 -1
  34. package/packages/feedback-collector/package.json +1 -1
  35. package/packages/file-copy-helper/package.json +1 -1
  36. package/packages/framework-detector/package.json +1 -1
  37. package/packages/framework-plugin-sdk/package.json +1 -1
  38. package/packages/frappe-plugin/package.json +1 -1
  39. package/packages/generic-web-plugin/package.json +1 -1
  40. package/packages/health-monitor/package.json +1 -1
  41. package/packages/intent-analyzer/package.json +1 -1
  42. package/packages/jev-judge/package.json +1 -1
  43. package/packages/knowledge-graph/package.json +1 -1
  44. package/packages/knowledge-retrieval/package.json +1 -1
  45. package/packages/laravel-plugin/package.json +1 -1
  46. package/packages/learning-engine/package.json +1 -1
  47. package/packages/mcp-adapter/package.json +1 -1
  48. package/packages/memory-engine/package.json +1 -1
  49. package/packages/milestone-manager/package.json +1 -1
  50. package/packages/model-registry/package.json +1 -1
  51. package/packages/nextjs-plugin/package.json +1 -1
  52. package/packages/notification/dist/adapters/telegram-adapter.d.ts.map +1 -1
  53. package/packages/notification/dist/adapters/telegram-adapter.js +17 -12
  54. package/packages/notification/dist/adapters/telegram-adapter.js.map +1 -1
  55. package/packages/notification/dist/mask-secrets.d.ts.map +1 -1
  56. package/packages/notification/dist/mask-secrets.js +9 -0
  57. package/packages/notification/dist/mask-secrets.js.map +1 -1
  58. package/packages/notification/package.json +1 -1
  59. package/packages/notification/src/adapters/telegram-adapter.ts +19 -12
  60. package/packages/notification/src/mask-secrets.ts +11 -1
  61. package/packages/observability/package.json +1 -1
  62. package/packages/okf-indexer/package.json +1 -1
  63. package/packages/paperclip-integration/package.json +1 -1
  64. package/packages/performance-optimizer/package.json +1 -1
  65. package/packages/privilege-broker/package.json +1 -1
  66. package/packages/project-analyzer/package.json +1 -1
  67. package/packages/project-bootstrap/package.json +1 -1
  68. package/packages/projection-engine/package.json +1 -1
  69. package/packages/prompt-compiler/package.json +1 -1
  70. package/packages/prompt-versioning/package.json +1 -1
  71. package/packages/provider-adapter-sdk/package.json +1 -1
  72. package/packages/provider-router/package.json +1 -1
  73. package/packages/provider-selector/package.json +1 -1
  74. package/packages/providers/package.json +1 -1
  75. package/packages/qdrant-skills/package.json +1 -1
  76. package/packages/quota-manager/package.json +1 -1
  77. package/packages/rate-limiter/package.json +1 -1
  78. package/packages/react-vite-plugin/package.json +1 -1
  79. package/packages/release-manager/package.json +1 -1
  80. package/packages/requirement-compiler/package.json +1 -1
  81. package/packages/runtime/package.json +1 -1
  82. package/packages/scheduler/package.json +1 -1
  83. package/packages/scheduler-adapter/package.json +1 -1
  84. package/packages/session/package.json +1 -1
  85. package/packages/session-api/package.json +1 -1
  86. package/packages/session-export/package.json +1 -1
  87. package/packages/shared-context/package.json +1 -1
  88. package/packages/skill-mcp-client/package.json +1 -1
  89. package/packages/skill-registry/package.json +1 -1
  90. package/packages/skills/package.json +1 -1
  91. package/packages/sprint-planner/package.json +1 -1
  92. package/packages/subscription-engine/package.json +1 -1
  93. package/packages/task-compiler/package.json +1 -1
  94. package/packages/tencentdb-memory/package.json +1 -1
  95. package/packages/tencentdb-sync/package.json +1 -1
  96. package/packages/test-data-generator/package.json +1 -1
  97. package/packages/test-generator/package.json +1 -1
  98. package/packages/todo-bd-sync/package.json +1 -1
  99. package/packages/token-estimation/package.json +1 -1
  100. package/packages/token-optimizer/package.json +1 -1
  101. package/packages/trajectory/package.json +1 -1
  102. package/packages/tui/package.json +1 -1
  103. package/packages/types/package.json +1 -1
  104. package/packages/workflow-events/package.json +1 -1
  105. package/packages/workspace-scanner/package.json +1 -1
  106. package/packages/worktree/package.json +1 -1
  107. package/packages/write-review/package.json +1 -1
  108. package/scripts/telegram-webhook-server.ts +85 -6
  109. package/scripts/tsconfig.json +9 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/session",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Session management system for pi-harness-runtime",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/session-api",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/session-export",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/shared-context",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "pi-harness-runtime — shared-context",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/skill-mcp-client",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "MCP client for Skills SaaS backend",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/skill-registry",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Skill Registry for pi-harness-runtime — dynamic skill discovery and invocation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/skills",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "File-based skill system with pi.dev compatibility and Hermes self-improvement",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/sprint-planner",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "description": "Sprint planning engine for pi-harness",
6
6
  "main": "dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/subscription-engine",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/task-compiler",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Task Compiler for pi-harness-runtime — produces deterministic task DAG from CompiledRequirement",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moocoding/tencentdb-memory",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "TencentDB Agent Memory client - sync skills to centralized knowledge base",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/tencentdb-sync",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Sync SKILL.md skills to TencentDB-Agent-Memory server (RFC-0105/0106)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/test-data-generator",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Test data generation for pi-harness-runtime",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/test-generator",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Auto-Test Generator — generate unit and E2E tests from source code (RFC-0013)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moocoding/todo-bd-sync",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Two-way sync between rpiv-todo overlay and bd issue tracker",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/token-estimation",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "pi-harness-runtime — token-estimation",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/token-optimizer",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Token Budget Optimizer — maximize prompt value within token limits (RFC-0011)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/trajectory",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Trajectory capture for the write-review loop — persists cycle records for learning",
5
5
  "type": "module",
6
6
  "main": "./dist/src/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/tui",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "pi-harness-runtime — tui",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/types",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Shared TypeScript types for pi-harness-runtime packages",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/workflow-events",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi/workspace-scanner",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "exports": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-harness/worktree",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "pi-harness-runtime — worktree",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moocoding/write-review",
3
- "version": "1.1.161",
3
+ "version": "1.1.162",
4
4
  "description": "Two-agent write-review loop with blackboard coordination",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -17,7 +17,8 @@ import { createServer } from "node:http";
17
17
 
18
18
  // --- Configuration ---
19
19
  const BOT_TOKEN = process.env.TELEGRAM_BOT_TOKEN;
20
- const WEBHOOK_SECRET = process.env.TELEGRAM_WEBHOOK_SECRET || "default-secret-change-me";
20
+ // SECURITY: Require webhook secret - fail closed if not set
21
+ const WEBHOOK_SECRET = process.env.TELEGRAM_WEBHOOK_SECRET;
21
22
  const WEBHOOK_URL = process.env.TELEGRAM_WEBHOOK_URL;
22
23
  const CALLBACK_QUEUE_FILE = process.env.CALLBACK_QUEUE_FILE || join(process.env.HOME || "/tmp", ".pi-harness-runtime", "callback-queue.jsonl");
23
24
  const PORT = parseInt(process.env.PORT || "3000", 10);
@@ -26,10 +27,70 @@ const PORT = parseInt(process.env.PORT || "3000", 10);
26
27
  if (!BOT_TOKEN) {
27
28
  console.error("[TelegramWebhook] ERROR: TELEGRAM_BOT_TOKEN not set");
28
29
  console.error("[TelegramWebhook] Usage:");
29
- console.error("[TelegramWebhook] TELEGRAM_BOT_TOKEN=xxx bun run scripts/telegram-webhook-server.ts");
30
+ console.error("[TelegramWebhook] TELEGRAM_BOT_TOKEN=xxx TELEGRAM_WEBHOOK_SECRET=xxx bun run scripts/telegram-webhook-server.ts");
30
31
  process.exit(1);
31
32
  }
32
33
 
34
+ // SECURITY: Require webhook secret - fail closed in production
35
+ if (!WEBHOOK_SECRET) {
36
+ console.error("[TelegramWebhook] ERROR: TELEGRAM_WEBHOOK_SECRET not set");
37
+ console.error("[TelegramWebhook] SECURITY: Webhook secret is required for production");
38
+ console.error("[TelegramWebhook] Usage:");
39
+ console.error("[TelegramWebhook] TELEGRAM_WEBHOOK_SECRET=<high-entropy-secret> bun run scripts/telegram-webhook-server.ts");
40
+ process.exit(1);
41
+ }
42
+
43
+ // --- Authorization helpers ---
44
+ function getAllowedUserIds(): Set<number> {
45
+ const ids = new Set<number>();
46
+
47
+ // Priority 1: Environment variable
48
+ const envUsers = process.env.TELEGRAM_ALLOWED_USERS;
49
+ if (envUsers) {
50
+ for (const part of envUsers.split(",")) {
51
+ const num = parseInt(part.trim(), 10);
52
+ if (!isNaN(num) && num > 0) ids.add(num);
53
+ }
54
+ }
55
+
56
+ // Priority 2: Key file (telegram-allowed-users.txt)
57
+ const allowedFile = join(process.env.HOME || "/tmp", ".pi-harness-runtime", "keys", "telegram-allowed-users.txt");
58
+ if (existsSync(allowedFile)) {
59
+ const content = readFileSync(allowedFile, "utf8").trim();
60
+ for (const part of content.split(",")) {
61
+ const num = parseInt(part.trim(), 10);
62
+ if (!isNaN(num) && num > 0) ids.add(num);
63
+ }
64
+ }
65
+
66
+ // Priority 3: Legacy chat ID file
67
+ const legacyFile = join(process.env.HOME || "/tmp", ".pi-harness-runtime", "keys", "telegram-chat-id.txt");
68
+ if (existsSync(legacyFile) && ids.size === 0) {
69
+ const content = readFileSync(legacyFile, "utf8").trim();
70
+ const num = parseInt(content, 10);
71
+ if (!isNaN(num) && num > 0) ids.add(num);
72
+ }
73
+
74
+ return ids;
75
+ }
76
+
77
+ function isAuthorizedUser(userId: number): boolean {
78
+ const allowed = getAllowedUserIds();
79
+ // SECURITY: Fail closed - deny if no allowlist configured
80
+ if (allowed.size === 0) {
81
+ console.warn("[TelegramWebhook] SECURITY: No TELEGRAM_ALLOWED_USERS configured - denying access");
82
+ return false;
83
+ }
84
+ return allowed.has(userId);
85
+ }
86
+
87
+ // SECURITY: Sanitize URLs from error messages
88
+ function sanitizeError(error: unknown): string {
89
+ const msg = String(error);
90
+ // Remove any bot token URLs
91
+ return msg.replace(/https?:\/\/[^/]*\/bot[^/]+\/[^\s]*/gi, "[REDACTED_URL]");
92
+ }
93
+
33
94
  // --- Types ---
34
95
  interface CallbackQuery {
35
96
  id: string;
@@ -275,7 +336,24 @@ function handleRequest(req: import("node:http").IncomingMessage, res: import("no
275
336
  const cq = update.callback_query;
276
337
  const parsed = parseCallbackData(cq.data);
277
338
 
278
- console.log(`[TelegramWebhook] Callback: ${cq.data} from ${cq.from.username || cq.from.first_name}`);
339
+ // SECURITY: Validate sender is authorized user
340
+ if (!isAuthorizedUser(cq.from.id)) {
341
+ console.warn(`[TelegramWebhook] Unauthorized user: ${cq.from.id} (${cq.from.username || cq.from.first_name})`);
342
+ // Answer callback query to remove loading state
343
+ await fetch(`https://api.telegram.org/bot${BOT_TOKEN}/answerCallbackQuery`, {
344
+ method: "POST",
345
+ headers: { "Content-Type": "application/json" },
346
+ body: JSON.stringify({
347
+ callback_query_id: cq.id,
348
+ text: "Unauthorized. Please contact the bot owner.",
349
+ }),
350
+ });
351
+ res.writeHead(200, { "Content-Type": "application/json" });
352
+ res.end(JSON.stringify({ ok: true }));
353
+ return;
354
+ }
355
+
356
+ console.log(`[TelegramWebhook] Callback: ${cq.data} from user_id=${cq.from.id}`);
279
357
 
280
358
  // Queue for pi-harness to process
281
359
  const queued: QueuedCallback = {
@@ -318,7 +396,7 @@ function handleRequest(req: import("node:http").IncomingMessage, res: import("no
318
396
  res.writeHead(200, { "Content-Type": "application/json" });
319
397
  res.end(JSON.stringify({ ok: true }));
320
398
  } catch (err) {
321
- console.error("[TelegramWebhook] Error:", err);
399
+ console.error("[TelegramWebhook] Error:", sanitizeError(err));
322
400
  res.writeHead(500, { "Content-Type": "application/json" });
323
401
  res.end(JSON.stringify({ error: "Internal error" }));
324
402
  }
@@ -330,7 +408,8 @@ async function setupWebhook(): Promise<void> {
330
408
  if (!WEBHOOK_URL) {
331
409
  console.log("[TelegramWebhook] TELEGRAM_WEBHOOK_URL not set — skipping webhook setup");
332
410
  console.log("[TelegramWebhook] To set webhook manually:");
333
- console.log(`[TelegramWebhook] curl -X POST https://api.telegram.org/bot${BOT_TOKEN}/setWebhook -d '{"url":"YOUR_WEBHOOK_URL","secret_token":"${WEBHOOK_SECRET}"}'`);
411
+ console.log("[TelegramWebhook] Configure webhook URL via environment or secret provider");
412
+ console.log("[TelegramWebhook] Then run: curl -X POST https://api.telegram.org/botYOUR_BOT_TOKEN/setWebhook -d json_with_secrets_removed");
334
413
  return;
335
414
  }
336
415
 
@@ -347,7 +426,7 @@ async function setupWebhook(): Promise<void> {
347
426
  if (result.ok) {
348
427
  console.log(`[TelegramWebhook] Webhook set to: ${WEBHOOK_URL}`);
349
428
  } else {
350
- console.error(`[TelegramWebhook] Webhook setup failed: ${result.description}`);
429
+ console.error(`[TelegramWebhook] Webhook setup failed: ${sanitizeError(result.description)}`);
351
430
  }
352
431
  }
353
432
 
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "types": ["node"]
7
+ },
8
+ "include": ["./**/*.ts"]
9
+ }