grok-telegram-bot 2.4.0 → 2.6.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 (81) hide show
  1. package/.env.example +38 -2
  2. package/CHANGELOG.md +190 -1
  3. package/README.md +60 -15
  4. package/docs/GROUP.md +260 -0
  5. package/docs/INSTALL.md +3 -0
  6. package/package.json +4 -4
  7. package/src/app/lifetime-flag.ts +20 -0
  8. package/src/app/settings-store.ts +47 -8
  9. package/src/app/types.ts +38 -1
  10. package/src/app/updater.ts +24 -3
  11. package/src/bot/auth.ts +100 -15
  12. package/src/bot/bot.ts +193 -17
  13. package/src/bot/chat-controller.ts +181 -18
  14. package/src/bot/commands.ts +69 -29
  15. package/src/bot/deps.ts +3 -0
  16. package/src/bot/group-memory.ts +339 -0
  17. package/src/bot/handlers/accounts.ts +7 -0
  18. package/src/bot/handlers/control.ts +85 -32
  19. package/src/bot/handlers/document.ts +31 -4
  20. package/src/bot/handlers/forum.ts +217 -0
  21. package/src/bot/handlers/menu.ts +86 -24
  22. package/src/bot/handlers/message.ts +247 -27
  23. package/src/bot/handlers/photo.ts +126 -16
  24. package/src/bot/handlers/running.ts +150 -24
  25. package/src/bot/handlers/session-card.ts +13 -5
  26. package/src/bot/handlers/sessions.ts +68 -18
  27. package/src/bot/handlers/voice.ts +52 -7
  28. package/src/bot/image-return.ts +11 -5
  29. package/src/bot/manager-context.ts +208 -0
  30. package/src/bot/manager-jobs.ts +142 -0
  31. package/src/bot/menu/ephemeral.ts +16 -3
  32. package/src/bot/menu/keyboard.ts +53 -14
  33. package/src/bot/menu/refresh.ts +3 -1
  34. package/src/bot/menu/status-panel.ts +12 -6
  35. package/src/bot/permission-service.ts +19 -0
  36. package/src/bot/prompt-anchor.ts +299 -0
  37. package/src/bot/prompt-content.ts +8 -0
  38. package/src/bot/registry.ts +94 -1
  39. package/src/bot/scope.ts +95 -0
  40. package/src/bot/session-runtime.ts +1280 -183
  41. package/src/bot/suggestions.ts +91 -31
  42. package/src/bot/telegram-actions.ts +1130 -0
  43. package/src/bot/telegram-bots.ts +496 -0
  44. package/src/bot/telegram-io.ts +97 -10
  45. package/src/cli.ts +2 -0
  46. package/src/config.ts +201 -2
  47. package/src/forum/bind-path.ts +146 -0
  48. package/src/forum/manager.ts +652 -0
  49. package/src/forum/project-icon.ts +142 -0
  50. package/src/forum/thread.ts +49 -0
  51. package/src/forum/topic-store.ts +114 -0
  52. package/src/forum/types.ts +29 -0
  53. package/src/grok/client.ts +130 -28
  54. package/src/index.ts +205 -75
  55. package/src/projects/manager.ts +16 -3
  56. package/src/render/chunk.ts +17 -10
  57. package/src/render/hashtags.ts +5 -1
  58. package/src/render/manager-directive.ts +137 -0
  59. package/src/render/session-comment.ts +74 -7
  60. package/src/render/telegram-bridge.ts +464 -0
  61. package/src/render/tool-call.ts +56 -37
  62. package/src/service/platform.ts +44 -7
  63. package/src/service/windows.ts +16 -4
  64. package/src/sessions/history.ts +68 -9
  65. package/src/sessions/process.ts +7 -0
  66. package/src/sessions/types.ts +2 -2
  67. package/src/stream/streamer.ts +62 -15
  68. package/scripts/analyze-jsonl.ts +0 -33
  69. package/scripts/delayed-restart.ps1 +0 -29
  70. package/scripts/probe-exit-response-shape.py +0 -77
  71. package/scripts/probe-plan-exit.py +0 -60
  72. package/scripts/probe-plan-exit2.py +0 -48
  73. package/scripts/probe-plan-fields.py +0 -41
  74. package/scripts/probe-plan-fields2.py +0 -58
  75. package/scripts/probe-plan-response-path.py +0 -48
  76. package/scripts/sample-claude-tooluse.ts +0 -21
  77. package/scripts/sample-kiro-events.ts +0 -31
  78. package/scripts/smoke-exit-plan.ts +0 -274
  79. package/scripts/smoke-exit-shapes.ts +0 -252
  80. package/scripts/smoke-import.mjs +0 -82
  81. package/scripts/smoke-import.ts +0 -73
@@ -4,8 +4,10 @@
4
4
  * Self-recheck (once per real user turn, when enabled):
5
5
  * 1. Hard-skip if no files were modified.
6
6
  * 2. Quiet meta ask: AI refuses (simple / pure build / nothing to re-verify)
7
- * or writes a focused recheck prompt.
8
- * 3. That prompt is queued as the one-shot SELF-RECHECK turn.
7
+ * or writes a complete recheck brief (bugs + production gaps + finish-all +
8
+ * per-bug checklist).
9
+ * 3. That prompt is queued as the one-shot SELF-RECHECK turn (compose always
10
+ * injects finish-all / per-bug rules when the body omitted them).
9
11
  * 4. Then Done + suggestions.
10
12
  *
11
13
  * After Done, the bot quietly asks for 1–3 short next steps as JSON with a
@@ -30,21 +32,36 @@ export const SELF_RECHECK_MARKER = "SELF-RECHECK (automatic quality pass";
30
32
  export const DEFAULT_SELF_RECHECK_PROMPT = [
31
33
  `${SELF_RECHECK_MARKER} — once only).`,
32
34
  "Do a rigorous self-review of the work just completed for the user request below.",
35
+ "You are a bugs/logic finder AND a production-completeness pass for the SAME feature.",
33
36
  "",
34
- "You are both a bugs/logic finder AND a completeness checker for related follow-ups.",
35
- "Look for:",
36
- "1) Bugs, regressions, incomplete steps, wrong assumptions, missing verification, edge cases.",
37
- "2) Logical gaps the user would still need — e.g. if they asked for password reset and you",
38
- " shipped the happy path only, also cover brute-force protection, rate limits, token expiry,",
39
- " email enumeration, CSRF, audit logging, and similar security/ops follow-through that a",
40
- " solid implementation of THAT feature should include (not a random new product idea).",
37
+ "A) Bugs & regressions",
38
+ "1) Incomplete steps, wrong assumptions, missing verification, edge cases, broken paths.",
39
+ "2) Logic mismatches (UI vs backend, state vs render, happy path vs error path).",
40
+ "",
41
+ "B) Production-related functionality (same domain only — not a new product idea)",
42
+ "Continue development toward an ideal production version of WHAT WAS BUILT:",
43
+ "- Game with water → waves/physics/collision where missing; entity that can die → death state; etc.",
44
+ "- Auth form → rate limits, lockout, CSRF, secure tokens, validation, error handling.",
45
+ "- API write → input validation, authz, idempotency/errors, logging where expected.",
46
+ "- UI control → empty/loading/error states, accessibility basics tied to the control.",
47
+ "Only add what a solid implementation of THIS feature should already include.",
48
+ "",
49
+ "C) Finish-all — no honest leftovers",
50
+ "- Do NOT leave half-done work with 'still need…', 'remaining…', 'TODO for user',",
51
+ " incomplete honest footers, or progress stuck low because work is unfinished.",
52
+ "- Finish critical gaps now so Done does not rely on follow-up suggestion buttons",
53
+ " for unfinished must-have work from this request.",
54
+ "- Do NOT ask the user questions. Do NOT call enter_plan_mode unless truly necessary.",
55
+ "",
56
+ "D) Per-bug recheck checklist (REQUIRED at the end of this pass)",
57
+ "1) List every plausible bug/edge case for THESE changes (race, null, authz, wrong path,",
58
+ " regression, missing test, off-by-one, bad default, security hole, etc.).",
59
+ "2) For each item: verify with tools or fix it. Briefly note only real findings.",
60
+ "3) Prefer {progress: 100%} only when this checklist is done and nothing critical remains.",
41
61
  "",
42
62
  "Rules:",
43
- "- Prefer fixing real problems with tools when needed; do not invent unrelated features.",
44
- "- If something is unfinished relative to the user request (or a tightly related follow-up",
45
- " that leaves the feature incomplete/insecure), finish or fix it now.",
63
+ "- Prefer fixing real problems with tools; do not invent unrelated features.",
46
64
  "- If everything checks out, briefly confirm what you verified (no long essay).",
47
- "- Do NOT ask the user questions. Do NOT call enter_plan_mode unless truly necessary.",
48
65
  "- End with an honest {progress: N%} marker for this recheck pass.",
49
66
  "",
50
67
  "USER'S REQUEST:",
@@ -54,6 +71,19 @@ export const DEFAULT_SELF_RECHECK_PROMPT = [
54
71
  "{{DONE}}",
55
72
  ].join("\n");
56
73
 
74
+ /** Shared rules appended when wrapping a short AI-written recheck body. */
75
+ export const SELF_RECHECK_COMPOSE_RULES = [
76
+ "Rules:",
77
+ "- Fix real bugs and logic mismatches with tools when needed; no unrelated features.",
78
+ "- Production-related completeness for the SAME feature (e.g. water→waves, auth→rate limits,",
79
+ " API writes→validation/errors). Close gaps a solid production build of this feature needs.",
80
+ "- Finish-all: do NOT leave 'still need…', 'remaining…', incomplete honest footers, or",
81
+ " half-done work that would force critical follow-up buttons. Finish those gaps now.",
82
+ "- End with a per-bug recheck: list plausible bugs for these changes and verify/fix each.",
83
+ "- Do NOT ask the user questions. Do NOT call enter_plan_mode unless truly necessary.",
84
+ "- End with an honest {progress: N%} marker for this recheck pass (100 only when checklist done).",
85
+ ].join("\n");
86
+
57
87
  export interface Suggestion {
58
88
  /** Plain follow-up the user would type / the bot will submit. */
59
89
  text: string;
@@ -231,9 +261,20 @@ export function buildSelfRecheckDecisionPrompt(
231
261
  "- Non-trivial code/config changed and edge cases, regressions, or incomplete",
232
262
  " follow-through are plausible (auth, multi-file logic, concurrency, data paths).",
233
263
  "- A focused second pass with tools could catch real bugs or finish related gaps.",
264
+ "- The first pass left honest leftovers ('still need…', unfinished production logic,",
265
+ " incomplete feature pieces) that a recheck should finish instead of the user.",
234
266
  "",
235
- "If needed=true, write a focused recheck prompt: imperative instructions for a one-shot",
236
- "second pass that may use tools to fix REAL issues. Do not invent unrelated features.",
267
+ "If needed=true, write prompt = a COMPLETE recheck brief for a one-shot agent pass.",
268
+ "The prompt MUST include ALL of the following sections (imperative, concrete, domain-specific):",
269
+ "1) Bugs/logic: what to re-read, verify, and fix for THIS change set.",
270
+ "2) Production-related functionality: continue to ideal production for the SAME feature",
271
+ " (examples: game water→waves; auth→rate limits/lockout/CSRF; API→validation/errors;",
272
+ " UI→empty/loading/error). Not unrelated product ideas.",
273
+ "3) Finish-all: explicitly order the agent to finish incomplete work and NOT leave",
274
+ " 'still need…', 'remaining…', incomplete honest footers, or half-done bottoms.",
275
+ "4) Per-bug recheck (at the BOTTOM of the prompt): list every plausible bug/edge case",
276
+ " for these changes and instruct the agent to verify or fix EACH one with tools.",
277
+ "Do not invent unrelated features. Keep the prompt actionable (not vague).",
237
278
  "If needed=false, give a short reason.",
238
279
  "",
239
280
  "USER'S REQUEST:",
@@ -248,7 +289,7 @@ export function buildSelfRecheckDecisionPrompt(
248
289
  "Reply with ONLY one JSON object (no markdown fences, no commentary):",
249
290
  '{"needed":false,"reason":"short reason"}',
250
291
  "or",
251
- '{"needed":true,"prompt":"focused recheck / fix instructions for the agent"}',
292
+ '{"needed":true,"prompt":"complete recheck brief with bugs + production gaps + finish-all + per-bug checklist"}',
252
293
  ].join("\n");
253
294
  }
254
295
 
@@ -372,6 +413,26 @@ export function buildSelfRecheckPrompt(
372
413
  return ensureSelfRecheckMarker(out);
373
414
  }
374
415
 
416
+ /**
417
+ * True when the recheck body already encodes finish-all + per-bug expectations
418
+ * (default template or a strong AI brief). Used to avoid double-appending rules.
419
+ */
420
+ export function hasSelfRecheckFinishRules(text: string): boolean {
421
+ const t = text.toLowerCase();
422
+ const finish =
423
+ t.includes("still need") || t.includes("finish-all") || t.includes("finish all");
424
+ const bugs = t.includes("per-bug") || t.includes("plausible bug");
425
+ return finish && bugs;
426
+ }
427
+
428
+ /** Append SHARED compose rules when the body omitted finish-all / per-bug language. */
429
+ export function ensureSelfRecheckComposeRules(text: string): string {
430
+ const body = text.trim();
431
+ if (!body) return SELF_RECHECK_COMPOSE_RULES;
432
+ if (hasSelfRecheckFinishRules(body)) return body;
433
+ return `${body}\n\n${SELF_RECHECK_COMPOSE_RULES}`;
434
+ }
435
+
375
436
  /**
376
437
  * Turn an AI-written recheck body into a full one-shot turn (marker + context).
377
438
  */
@@ -396,23 +457,22 @@ export function composeSelfRecheckTurn(
396
457
  isSelfRecheckPrompt(body) ||
397
458
  (/USER'S REQUEST:/i.test(body) && /WHAT WAS JUST DONE/i.test(body));
398
459
  if (looksComplete) {
399
- return ensureSelfRecheckMarker(body);
460
+ // Still inject finish-all / per-bug rules if a "complete-looking" AI brief
461
+ // only copied headers and omitted production/finish-all/per-bug sections.
462
+ return ensureSelfRecheckMarker(ensureSelfRecheckComposeRules(body));
400
463
  }
401
464
  return ensureSelfRecheckMarker(
402
- [
403
- body,
404
- "",
405
- "Rules:",
406
- "- Prefer fixing real problems with tools when needed; do not invent unrelated features.",
407
- "- Do NOT ask the user questions. Do NOT call enter_plan_mode unless truly necessary.",
408
- "- End with an honest {progress: N%} marker for this recheck pass.",
409
- "",
410
- "USER'S REQUEST:",
411
- user,
412
- "",
413
- "WHAT WAS JUST DONE (summary):",
414
- did,
415
- ].join("\n"),
465
+ ensureSelfRecheckComposeRules(
466
+ [
467
+ body,
468
+ "",
469
+ "USER'S REQUEST:",
470
+ user,
471
+ "",
472
+ "WHAT WAS JUST DONE (summary):",
473
+ did,
474
+ ].join("\n"),
475
+ ),
416
476
  );
417
477
  }
418
478