@gajae-code/coding-agent 0.8.1 → 0.8.2

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 (112) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/types/cli/completion-cli.d.ts +41 -0
  3. package/dist/types/cli/config-cli.d.ts +1 -0
  4. package/dist/types/cli/notify-cli.d.ts +7 -0
  5. package/dist/types/cli.d.ts +124 -1
  6. package/dist/types/commands/completion.d.ts +29 -0
  7. package/dist/types/commands/config.d.ts +3 -0
  8. package/dist/types/commands/deep-interview.d.ts +3 -0
  9. package/dist/types/config/file-lock.d.ts +7 -6
  10. package/dist/types/config/keybindings.d.ts +2 -2
  11. package/dist/types/config/model-profile-activation.d.ts +6 -0
  12. package/dist/types/config/settings.d.ts +8 -0
  13. package/dist/types/extensibility/extensions/runner.d.ts +2 -1
  14. package/dist/types/extensibility/extensions/types.d.ts +8 -0
  15. package/dist/types/gjc-runtime/deep-interview-ambiguity.d.ts +39 -0
  16. package/dist/types/gjc-runtime/deep-interview-recorder.d.ts +10 -1
  17. package/dist/types/gjc-runtime/deep-interview-runtime.d.ts +1 -1
  18. package/dist/types/gjc-runtime/deep-interview-state.d.ts +12 -0
  19. package/dist/types/gjc-runtime/team-runtime.d.ts +2 -1
  20. package/dist/types/gjc-runtime/ultragoal-runtime.d.ts +1 -0
  21. package/dist/types/main.d.ts +4 -1
  22. package/dist/types/modes/components/model-selector.d.ts +4 -0
  23. package/dist/types/modes/components/queued-message-selector.d.ts +12 -0
  24. package/dist/types/modes/components/settings-selector.d.ts +2 -0
  25. package/dist/types/modes/controllers/input-controller.d.ts +1 -3
  26. package/dist/types/modes/print-mode.d.ts +13 -1
  27. package/dist/types/modes/prompt-action-autocomplete.d.ts +1 -1
  28. package/dist/types/notifications/config.d.ts +8 -1
  29. package/dist/types/notifications/daemon-paths.d.ts +1 -0
  30. package/dist/types/notifications/index.d.ts +6 -3
  31. package/dist/types/notifications/lifecycle-commands.d.ts +11 -3
  32. package/dist/types/notifications/telegram-daemon.d.ts +15 -3
  33. package/dist/types/notifications/telegram-reference.d.ts +0 -5
  34. package/dist/types/runtime-api-key.d.ts +7 -0
  35. package/dist/types/session/agent-session.d.ts +10 -0
  36. package/dist/types/session/agent-storage.d.ts +1 -0
  37. package/dist/types/task/executor.d.ts +2 -0
  38. package/dist/types/tools/computer.d.ts +2 -2
  39. package/dist/types/workflow/workflow-intent-diff.d.ts +8 -2
  40. package/dist/types/workflow/workflow-intent-report-consumer.d.ts +50 -0
  41. package/dist/types/workflow/workflow-intent-report-schema.d.ts +2 -0
  42. package/dist/types/workflow/workflow-intent-report.d.ts +48 -0
  43. package/package.json +7 -7
  44. package/src/cli/completion-cli.ts +234 -0
  45. package/src/cli/config-cli.ts +37 -9
  46. package/src/cli/fast-help.ts +1 -0
  47. package/src/cli/notify-cli.ts +91 -7
  48. package/src/cli.ts +3 -1
  49. package/src/commands/completion.ts +84 -0
  50. package/src/commands/config.ts +2 -0
  51. package/src/commands/deep-interview.ts +2 -1
  52. package/src/config/file-lock.ts +73 -34
  53. package/src/config/keybindings.ts +2 -2
  54. package/src/config/model-profile-activation.ts +65 -0
  55. package/src/config/model-registry.ts +14 -2
  56. package/src/config/settings.ts +22 -0
  57. package/src/coordinator-mcp/server.ts +34 -8
  58. package/src/defaults/gjc/skills/deep-interview/SKILL.md +38 -5
  59. package/src/defaults/gjc/skills/ralplan/SKILL.md +15 -11
  60. package/src/defaults/gjc/skills/team/SKILL.md +1 -1
  61. package/src/extensibility/extensions/runner.ts +2 -0
  62. package/src/extensibility/extensions/types.ts +9 -0
  63. package/src/gjc-runtime/deep-interview-ambiguity.ts +206 -0
  64. package/src/gjc-runtime/deep-interview-recorder.ts +62 -8
  65. package/src/gjc-runtime/deep-interview-runtime.ts +210 -2
  66. package/src/gjc-runtime/deep-interview-state.ts +13 -0
  67. package/src/gjc-runtime/session-state-sidecar.ts +59 -11
  68. package/src/gjc-runtime/state-runtime.ts +12 -2
  69. package/src/gjc-runtime/team-runtime.ts +23 -0
  70. package/src/gjc-runtime/ultragoal-runtime.ts +73 -19
  71. package/src/hooks/native-skill-hook.ts +29 -0
  72. package/src/internal-urls/docs-index.generated.ts +2 -2
  73. package/src/main.ts +52 -41
  74. package/src/modes/components/model-selector.ts +54 -11
  75. package/src/modes/components/queued-message-selector.ts +92 -0
  76. package/src/modes/components/settings-selector.ts +4 -0
  77. package/src/modes/components/welcome.ts +160 -44
  78. package/src/modes/controllers/command-controller.ts +1 -2
  79. package/src/modes/controllers/extension-ui-controller.ts +4 -10
  80. package/src/modes/controllers/input-controller.ts +179 -17
  81. package/src/modes/controllers/selector-controller.ts +122 -27
  82. package/src/modes/interactive-mode.ts +43 -16
  83. package/src/modes/print-mode.ts +43 -4
  84. package/src/modes/prompt-action-autocomplete.ts +21 -20
  85. package/src/modes/utils/hotkeys-markdown.ts +1 -0
  86. package/src/modes/utils/ui-helpers.ts +2 -2
  87. package/src/notifications/config.ts +9 -1
  88. package/src/notifications/daemon-paths.ts +2 -0
  89. package/src/notifications/index.ts +39 -9
  90. package/src/notifications/lifecycle-commands.ts +37 -7
  91. package/src/notifications/lifecycle-orchestrator.ts +19 -6
  92. package/src/notifications/telegram-daemon-control.ts +3 -1
  93. package/src/notifications/telegram-daemon.ts +217 -43
  94. package/src/notifications/telegram-reference.ts +0 -16
  95. package/src/prompts/system/system-prompt.md +3 -0
  96. package/src/prompts/tools/computer.md +2 -2
  97. package/src/runtime-api-key.ts +16 -0
  98. package/src/sdk.ts +20 -6
  99. package/src/session/agent-session.ts +225 -31
  100. package/src/session/agent-storage.ts +4 -0
  101. package/src/session/session-manager.ts +44 -2
  102. package/src/slash-commands/builtin-registry.ts +153 -71
  103. package/src/task/executor.ts +7 -4
  104. package/src/task/index.ts +9 -3
  105. package/src/task/output-manager.ts +16 -6
  106. package/src/task/receipt.ts +26 -7
  107. package/src/tools/computer.ts +246 -43
  108. package/src/tools/telegram-send.ts +6 -0
  109. package/src/workflow/workflow-intent-diff.ts +29 -6
  110. package/src/workflow/workflow-intent-report-consumer.ts +221 -0
  111. package/src/workflow/workflow-intent-report-schema.ts +129 -0
  112. package/src/workflow/workflow-intent-report.ts +135 -0
@@ -98,7 +98,7 @@ export interface ComputerScreenshotDetails {
98
98
  scaleY?: number;
99
99
  originX?: number;
100
100
  originY?: number;
101
- displayEpoch?: string;
101
+ displayEpoch?: number;
102
102
  captureId?: string;
103
103
  pngBytes?: number;
104
104
  path?: string;
@@ -144,7 +144,7 @@ type NativeScreenshot = {
144
144
  scaleY?: number;
145
145
  originX?: number;
146
146
  originY?: number;
147
- displayEpoch?: string;
147
+ displayEpoch?: number;
148
148
  captureId?: string;
149
149
  };
150
150
 
@@ -175,6 +175,7 @@ let controllerFactory: ComputerControllerFactory = createNativeComputerControlle
175
175
  let platformOverrideForTests: NodeJS.Platform | undefined;
176
176
  let archOverrideForTests: NodeJS.Architecture | undefined;
177
177
  const screenshotFallbackDirs = new WeakMap<ToolSession, Promise<string>>();
178
+ const latestScreenshotContexts = new WeakMap<ToolSession, ScreenshotContext>();
178
179
 
179
180
  const COMPUTER_INLINE_SCREENSHOT_MAX_WIDTH = 1568;
180
181
  const COMPUTER_INLINE_SCREENSHOT_MAX_HEIGHT = 1568;
@@ -275,12 +276,24 @@ export class ComputerTool implements AgentTool<typeof computerSchema, ComputerTo
275
276
  const timeoutSeconds = clampTimeout("computer", params.timeout);
276
277
  const timeoutMs = timeoutSeconds > 0 ? timeoutSeconds * 1000 : undefined;
277
278
  const controller = controllerFactory();
278
- // Native ComputerController methods are synchronous and accept no AbortSignal,
279
- // so cancellation is honored before dispatch and wait() is bounded by timeoutMs.
279
+ const deadline = createComputerDeadline(timeoutMs);
280
280
  if (params.action === "batch") {
281
- const batchResult = await dispatchBatchComputerActions(controller, params.actions, timeoutMs, hotkey);
281
+ const batchResult = await dispatchBatchComputerActions(
282
+ controller,
283
+ params.actions,
284
+ timeoutMs,
285
+ hotkey,
286
+ latestScreenshotContexts.get(this.session),
287
+ shouldCapturePostActionScreenshot(params, this.session),
288
+ Boolean(this.session.settings.get("computer.autoScreenshot")),
289
+ signal,
290
+ deadline,
291
+ );
282
292
  details.steps = batchResult.steps;
283
- if (batchResult.screenshot) details.screenshot = batchResult.screenshot;
293
+ if (batchResult.screenshot) {
294
+ details.screenshot = batchResult.screenshot;
295
+ rememberLatestScreenshot(this.session, batchResult.screenshot);
296
+ }
284
297
  details.status = batchResult.failedStep ? "error" : "success";
285
298
  if (batchResult.failedStep) {
286
299
  details.code = batchResult.failedStep.code;
@@ -307,9 +320,21 @@ export class ComputerTool implements AgentTool<typeof computerSchema, ComputerTo
307
320
  .done()
308
321
  : toolResult(details).text(details.message).done();
309
322
  }
310
- const result = await dispatchComputerAction(controller, params, timeoutMs);
323
+ let result = await dispatchComputerAction(
324
+ controller,
325
+ params,
326
+ deadline,
327
+ latestScreenshotContexts.get(this.session),
328
+ signal,
329
+ );
330
+ if (shouldCapturePostActionScreenshot(params, this.session)) {
331
+ result = await captureScreenshot(controller, deadline, signal);
332
+ }
311
333
  const screenshot = normalizeScreenshot(result);
312
- if (screenshot) details.screenshot = screenshot;
334
+ if (screenshot) {
335
+ details.screenshot = screenshot;
336
+ rememberLatestScreenshot(this.session, screenshot);
337
+ }
313
338
  details.status = "success";
314
339
  details.message = describeComputerSuccess(details);
315
340
  if (screenshot) {
@@ -342,6 +367,10 @@ interface CoordinateBounds {
342
367
  originY?: number;
343
368
  }
344
369
 
370
+ interface ScreenshotContext extends CoordinateBounds {
371
+ displayEpoch?: number;
372
+ }
373
+
345
374
  function validatePointerCoordinates(action: string, x: number, y: number, bounds: CoordinateBounds | undefined): void {
346
375
  if (!bounds) return;
347
376
  const minX = bounds.originX ?? 0;
@@ -355,42 +384,189 @@ function validatePointerCoordinates(action: string, x: number, y: number, bounds
355
384
  }
356
385
  }
357
386
 
358
- function dispatchComputerAction(
387
+ function expectedEpochFromContext(context: ScreenshotContext | undefined): number | undefined {
388
+ return typeof context?.displayEpoch === "number" &&
389
+ Number.isFinite(context.displayEpoch) &&
390
+ context.displayEpoch >= 0
391
+ ? context.displayEpoch
392
+ : undefined;
393
+ }
394
+
395
+ function rememberLatestScreenshot(session: ToolSession, screenshot: ComputerScreenshotDetails): void {
396
+ latestScreenshotContexts.set(session, {
397
+ widthPx: screenshot.widthPx,
398
+ heightPx: screenshot.heightPx,
399
+ originX: screenshot.originX,
400
+ originY: screenshot.originY,
401
+ displayEpoch: screenshot.displayEpoch,
402
+ });
403
+ }
404
+
405
+ function captureScreenshot(
359
406
  controller: NativeController,
360
- params: SingleComputerParams,
407
+ deadline: ComputerDeadline | undefined,
408
+ signal?: AbortSignal,
409
+ ): Promise<unknown> {
410
+ return runComputerOperation(
411
+ () => {
412
+ if (!controller.screenshot) missingNativeMethod("screenshot", "screenshot");
413
+ return controller.screenshot();
414
+ },
415
+ deadline,
416
+ signal,
417
+ );
418
+ }
419
+
420
+ function missingNativeMethod(action: string, method: string): never {
421
+ throw new ToolError(`COMPUTER_UNAVAILABLE: Native ComputerController.${method} is unavailable for ${action}.`, {
422
+ code: "COMPUTER_UNAVAILABLE",
423
+ });
424
+ }
425
+
426
+ function shouldCapturePostActionScreenshot(
427
+ params: Pick<ComputerParams, "action" | "include_screenshot">,
428
+ session: Pick<ToolSession, "settings">,
429
+ ): boolean {
430
+ return (
431
+ params.action !== "screenshot" &&
432
+ (params.include_screenshot === true || Boolean(session.settings.get("computer.autoScreenshot")))
433
+ );
434
+ }
435
+
436
+ interface ComputerDeadline {
437
+ expiresAtMs: number;
438
+ }
439
+
440
+ class ComputerTimeoutError extends Error {
441
+ constructor() {
442
+ super("Computer action timed out.");
443
+ this.name = "TimeoutError";
444
+ }
445
+ }
446
+
447
+ function createComputerDeadline(
361
448
  timeoutMs: number | undefined,
362
- bounds?: CoordinateBounds,
363
- ): Promise<unknown> | unknown {
364
- // expectedEpoch is undefined until lossless epoch transport lands (follow-up):
365
- // the native gate skips the stale-display check when the epoch is absent.
366
- switch (params.action) {
367
- case "screenshot":
368
- return controller.screenshot?.();
369
- case "click":
370
- validatePointerCoordinates("click", params.x, params.y, bounds);
371
- return controller.click?.(undefined, params.x, params.y, params.button ?? "left");
372
- case "double_click":
373
- validatePointerCoordinates("double_click", params.x, params.y, bounds);
374
- return controller.doubleClick?.(undefined, params.x, params.y, params.button ?? "left");
375
- case "move":
376
- validatePointerCoordinates("move", params.x, params.y, bounds);
377
- return controller.move?.(undefined, params.x, params.y);
378
- case "drag":
379
- validatePointerCoordinates("drag start", params.x, params.y, bounds);
380
- validatePointerCoordinates("drag end", params.to_x, params.to_y, bounds);
381
- return controller.drag?.(undefined, params.x, params.y, params.to_x, params.to_y, params.button ?? "left");
382
- case "scroll":
383
- validatePointerCoordinates("scroll", params.x, params.y, bounds);
384
- return controller.scroll?.(undefined, params.x, params.y, params.scroll_x, params.scroll_y);
385
- case "type":
386
- return controller.type?.(undefined, params.text);
387
- case "keypress":
388
- return controller.keypress?.(undefined, params.keys);
389
- case "wait":
390
- return controller.wait?.(undefined, capWaitMs(params.ms, timeoutMs));
449
+ parent?: ComputerDeadline,
450
+ ): ComputerDeadline | undefined {
451
+ const localExpiresAt = timeoutMs && timeoutMs > 0 ? performance.now() + timeoutMs : undefined;
452
+ const parentExpiresAt = parent?.expiresAtMs;
453
+ const expiresAtMs =
454
+ localExpiresAt === undefined
455
+ ? parentExpiresAt
456
+ : parentExpiresAt === undefined
457
+ ? localExpiresAt
458
+ : Math.min(localExpiresAt, parentExpiresAt);
459
+ return expiresAtMs === undefined ? undefined : { expiresAtMs };
460
+ }
461
+
462
+ function remainingComputerTimeoutMs(deadline: ComputerDeadline | undefined): number | undefined {
463
+ if (!deadline) return undefined;
464
+ const remaining = Math.ceil(deadline.expiresAtMs - performance.now());
465
+ if (remaining <= 0) throw new ComputerTimeoutError();
466
+ return remaining;
467
+ }
468
+
469
+ function assertComputerDeadline(deadline: ComputerDeadline | undefined): void {
470
+ remainingComputerTimeoutMs(deadline);
471
+ }
472
+
473
+ async function runComputerOperation<T>(
474
+ operation: () => Promise<T> | T,
475
+ deadline: ComputerDeadline | undefined,
476
+ signal?: AbortSignal,
477
+ ): Promise<T> {
478
+ throwIfAborted(signal);
479
+ const timeoutMs = remainingComputerTimeoutMs(deadline);
480
+ let timeout: ReturnType<typeof setTimeout> | undefined;
481
+ let removeAbortListener: (() => void) | undefined;
482
+ const operationPromise = Promise.resolve().then(operation);
483
+ operationPromise.catch(() => undefined);
484
+ const guards: Array<Promise<never>> = [];
485
+ if (timeoutMs !== undefined) {
486
+ guards.push(
487
+ new Promise((_, reject) => {
488
+ timeout = setTimeout(() => reject(new ComputerTimeoutError()), timeoutMs);
489
+ }),
490
+ );
491
+ }
492
+ if (signal) {
493
+ guards.push(
494
+ new Promise((_, reject) => {
495
+ const onAbort = () => reject(new ToolAbortError());
496
+ signal.addEventListener("abort", onAbort, { once: true });
497
+ removeAbortListener = () => signal.removeEventListener("abort", onAbort);
498
+ }),
499
+ );
500
+ }
501
+ try {
502
+ const result = await (guards.length > 0 ? Promise.race([operationPromise, ...guards]) : operationPromise);
503
+ throwIfAborted(signal);
504
+ assertComputerDeadline(deadline);
505
+ return result;
506
+ } finally {
507
+ if (timeout) clearTimeout(timeout);
508
+ removeAbortListener?.();
391
509
  }
392
510
  }
393
511
 
512
+ function dispatchComputerAction(
513
+ controller: NativeController,
514
+ params: SingleComputerParams,
515
+ deadline: ComputerDeadline | undefined,
516
+ context?: ScreenshotContext,
517
+ signal?: AbortSignal,
518
+ ): Promise<unknown> {
519
+ const expectedEpoch = expectedEpochFromContext(context);
520
+ return runComputerOperation(
521
+ () => {
522
+ switch (params.action) {
523
+ case "screenshot":
524
+ if (!controller.screenshot) missingNativeMethod("screenshot", "screenshot");
525
+ return controller.screenshot();
526
+ case "click":
527
+ validatePointerCoordinates("click", params.x, params.y, context);
528
+ if (!controller.click) missingNativeMethod("click", "click");
529
+ return controller.click(expectedEpoch, params.x, params.y, params.button ?? "left");
530
+ case "double_click":
531
+ validatePointerCoordinates("double_click", params.x, params.y, context);
532
+ if (!controller.doubleClick) missingNativeMethod("double_click", "doubleClick");
533
+ return controller.doubleClick(expectedEpoch, params.x, params.y, params.button ?? "left");
534
+ case "move":
535
+ validatePointerCoordinates("move", params.x, params.y, context);
536
+ if (!controller.move) missingNativeMethod("move", "move");
537
+ return controller.move(expectedEpoch, params.x, params.y);
538
+ case "drag":
539
+ validatePointerCoordinates("drag start", params.x, params.y, context);
540
+ validatePointerCoordinates("drag end", params.to_x, params.to_y, context);
541
+ if (!controller.drag) missingNativeMethod("drag", "drag");
542
+ return controller.drag(
543
+ expectedEpoch,
544
+ params.x,
545
+ params.y,
546
+ params.to_x,
547
+ params.to_y,
548
+ params.button ?? "left",
549
+ );
550
+ case "scroll":
551
+ validatePointerCoordinates("scroll", params.x, params.y, context);
552
+ if (!controller.scroll) missingNativeMethod("scroll", "scroll");
553
+ return controller.scroll(expectedEpoch, params.x, params.y, params.scroll_x, params.scroll_y);
554
+ case "type":
555
+ if (!controller.type) missingNativeMethod("type", "type");
556
+ return controller.type(undefined, params.text);
557
+ case "keypress":
558
+ if (!controller.keypress) missingNativeMethod("keypress", "keypress");
559
+ return controller.keypress(undefined, params.keys);
560
+ case "wait":
561
+ if (!controller.wait) missingNativeMethod("wait", "wait");
562
+ return controller.wait(undefined, capWaitMs(params.ms, remainingComputerTimeoutMs(deadline)));
563
+ }
564
+ },
565
+ deadline,
566
+ signal,
567
+ );
568
+ }
569
+
394
570
  interface BatchDispatchResult {
395
571
  steps: ComputerToolDetails[];
396
572
  screenshot?: ComputerScreenshotDetails;
@@ -403,21 +579,34 @@ async function dispatchBatchComputerActions(
403
579
  actions: readonly SingleComputerParams[],
404
580
  timeoutMs: number | undefined,
405
581
  hotkey?: string,
582
+ initialContext?: ScreenshotContext,
583
+ includeBatchScreenshot = false,
584
+ autoScreenshot = false,
585
+ signal?: AbortSignal,
586
+ deadline?: ComputerDeadline,
406
587
  ): Promise<BatchDispatchResult> {
407
588
  const steps: ComputerToolDetails[] = [];
408
589
  let lastScreenshot: ComputerScreenshotDetails | undefined;
409
590
  let lastScreenshotSource: unknown;
410
- let bounds: CoordinateBounds | undefined;
591
+ let context = initialContext;
411
592
  for (const single of actions) {
412
593
  const stepDetails = detailsFromParams(single);
413
594
  try {
414
- const result = await dispatchComputerAction(controller, single, timeoutMs, bounds);
595
+ throwIfAborted(signal);
596
+ assertComputerDeadline(deadline);
597
+ const stepTimeoutMs = stepTimeoutFromParams(single, timeoutMs);
598
+ const stepDeadline = createComputerDeadline(stepTimeoutMs, deadline);
599
+ let result = await dispatchComputerAction(controller, single, stepDeadline, context, signal);
600
+ if (single.action !== "screenshot" && (single.include_screenshot === true || autoScreenshot)) {
601
+ result = await captureScreenshot(controller, stepDeadline, signal);
602
+ }
603
+
415
604
  const screenshot = normalizeScreenshot(result);
416
605
  if (screenshot) {
417
606
  stepDetails.screenshot = screenshot;
418
607
  lastScreenshot = screenshot;
419
608
  lastScreenshotSource = result;
420
- bounds = screenshot;
609
+ context = screenshot;
421
610
  }
422
611
  stepDetails.status = "success";
423
612
  stepDetails.message = describeComputerSuccess(stepDetails);
@@ -437,9 +626,19 @@ async function dispatchBatchComputerActions(
437
626
  }
438
627
  steps.push(stepDetails);
439
628
  }
629
+ if (includeBatchScreenshot) {
630
+ lastScreenshotSource = await captureScreenshot(controller, deadline, signal);
631
+ lastScreenshot = normalizeScreenshot(lastScreenshotSource) ?? lastScreenshot;
632
+ }
440
633
  return { steps, screenshot: lastScreenshot, screenshotSource: lastScreenshotSource };
441
634
  }
442
635
 
636
+ function stepTimeoutFromParams(params: SingleComputerParams, batchTimeoutMs: number | undefined): number | undefined {
637
+ if (params.timeout === undefined) return batchTimeoutMs;
638
+ const timeoutSeconds = clampTimeout("computer", params.timeout);
639
+ return timeoutSeconds > 0 ? timeoutSeconds * 1000 : undefined;
640
+ }
641
+
443
642
  function detailsFromParams(params: ComputerParams): ComputerToolDetails {
444
643
  const details: ComputerToolDetails = { action: params.action, status: "success" };
445
644
  if ("x" in params) details.x = params.x;
@@ -476,12 +675,16 @@ function normalizeScreenshot(value: unknown): ComputerScreenshotDetails | undefi
476
675
  scaleY: shot.scaleY,
477
676
  originX: shot.originX,
478
677
  originY: shot.originY,
479
- displayEpoch: shot.displayEpoch,
678
+ displayEpoch: normalizeDisplayEpoch(shot.displayEpoch),
480
679
  captureId: shot.captureId,
481
680
  pngBytes: getPngByteLength(shot.png),
482
681
  };
483
682
  }
484
683
 
684
+ function normalizeDisplayEpoch(value: unknown): number | undefined {
685
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined;
686
+ }
687
+
485
688
  function fullResolutionImageContentFromNativeResult(value: unknown): ImageContent | undefined {
486
689
  const candidate =
487
690
  value && typeof value === "object" && "screenshot" in value
@@ -6,6 +6,9 @@ import { getTelegramFileSink } from "../notifications/attachment-registry";
6
6
  import { getNotificationConfig, isGloballyConfigured } from "../notifications/config";
7
7
  import type { ToolSession } from "./index";
8
8
 
9
+ const TELEGRAM_SEND_MAX_FILE_BYTES = 50 * 1024 * 1024;
10
+ const TELEGRAM_SEND_MAX_FILE_MIB = TELEGRAM_SEND_MAX_FILE_BYTES / (1024 * 1024);
11
+
9
12
  const telegramSendSchema = z.object({
10
13
  path: z
11
14
  .string()
@@ -75,6 +78,9 @@ export class TelegramSendTool implements AgentTool<typeof telegramSendSchema, Te
75
78
  if (!stat.isFile()) {
76
79
  return { ok: false, error: "not a regular file" };
77
80
  }
81
+ if (stat.size > TELEGRAM_SEND_MAX_FILE_BYTES) {
82
+ return { ok: false, error: `file exceeds Telegram document limit (${TELEGRAM_SEND_MAX_FILE_MIB} MiB)` };
83
+ }
78
84
  return { ok: true, path: real };
79
85
  }
80
86
 
@@ -1,6 +1,15 @@
1
+ import {
2
+ buildWorkflowIntentReport,
3
+ type WorkflowClaimsLedger,
4
+ type WorkflowConsensusReport,
5
+ } from "./workflow-intent-report";
6
+
1
7
  export const WORKFLOW_INTENT_DIFF_CUSTOM_TYPE = "workflow-intent-diff";
8
+ export const WORKFLOW_INTENT_ROUTES = ["direct", "deep-interview", "ralplan", "ultragoal", "team"] as const;
9
+ export const WORKFLOW_ESCALATION_ROUTES = ["deep-interview", "ralplan", "ultragoal", "team"] as const;
2
10
 
3
- export type WorkflowIntentRoute = "direct" | "deep-interview" | "ralplan" | "ultragoal" | "team";
11
+ export type WorkflowIntentRoute = (typeof WORKFLOW_INTENT_ROUTES)[number];
12
+ export type WorkflowEscalationRoute = (typeof WORKFLOW_ESCALATION_ROUTES)[number];
4
13
  export type DirectTrackingMode = "custom-entry-only" | "not-direct";
5
14
  export type RootCausePhaseStatus = "active" | "inactive";
6
15
 
@@ -9,13 +18,15 @@ export interface WorkflowIntentDiff {
9
18
  readonly route: WorkflowIntentRoute;
10
19
  readonly reason: string;
11
20
  readonly directTracking: DirectTrackingMode;
12
- readonly recommendedSkill?: Exclude<WorkflowIntentRoute, "direct">;
21
+ readonly recommendedSkill?: WorkflowEscalationRoute;
13
22
  readonly recommendedInvocation?: string;
14
23
  readonly triggers: readonly string[];
15
24
  readonly rootCausePhase: {
16
25
  readonly status: RootCausePhaseStatus;
17
26
  readonly triggers: readonly string[];
18
27
  };
28
+ readonly claimsLedger: WorkflowClaimsLedger;
29
+ readonly consensusReport: WorkflowConsensusReport;
19
30
  readonly promptPreview: string;
20
31
  }
21
32
 
@@ -182,6 +193,19 @@ export function buildWorkflowIntentDiff(text: string): WorkflowIntentDiff | null
182
193
  const rootCauseTriggers = collectRootCauseTriggers(text);
183
194
  const rootCauseActive = rootCauseTriggers.length > 0;
184
195
  const direct = route.route === "direct";
196
+ const rootCauseStatus: RootCausePhaseStatus = rootCauseActive ? "active" : "inactive";
197
+ const rootCausePhase = {
198
+ status: rootCauseStatus,
199
+ triggers: rootCauseTriggers,
200
+ };
201
+ const report = buildWorkflowIntentReport({
202
+ route: route.route,
203
+ reason: route.reason,
204
+ direct,
205
+ recommendedInvocation: route.recommendedInvocation,
206
+ triggers: route.triggers,
207
+ rootCausePhase,
208
+ });
185
209
 
186
210
  return {
187
211
  version: 1,
@@ -190,10 +214,9 @@ export function buildWorkflowIntentDiff(text: string): WorkflowIntentDiff | null
190
214
  directTracking: direct ? "custom-entry-only" : "not-direct",
191
215
  ...(direct ? {} : { recommendedSkill: route.route, recommendedInvocation: route.recommendedInvocation }),
192
216
  triggers: route.triggers,
193
- rootCausePhase: {
194
- status: rootCauseActive ? "active" : "inactive",
195
- triggers: rootCauseTriggers,
196
- },
217
+ rootCausePhase,
218
+ claimsLedger: report.claimsLedger,
219
+ consensusReport: report.consensusReport,
197
220
  promptPreview,
198
221
  };
199
222
  }
@@ -0,0 +1,221 @@
1
+ import type { SessionEntry } from "../session/session-manager";
2
+ import {
3
+ WORKFLOW_INTENT_DIFF_CUSTOM_TYPE,
4
+ WORKFLOW_INTENT_ROUTES,
5
+ type WorkflowIntentDiff,
6
+ type WorkflowIntentRoute,
7
+ } from "./workflow-intent-diff";
8
+ import type { WorkflowSignalObserver } from "./workflow-intent-report";
9
+ import { parseWorkflowIntentDiffPayload } from "./workflow-intent-report-schema";
10
+
11
+ export type WorkflowConsumerConfidence = "none" | "low" | "medium" | "high";
12
+
13
+ export interface WorkflowRouteCounts {
14
+ readonly direct: number;
15
+ readonly "deep-interview": number;
16
+ readonly ralplan: number;
17
+ readonly ultragoal: number;
18
+ readonly team: number;
19
+ }
20
+
21
+ export interface WorkflowIntentReportEntry {
22
+ readonly entryId: string;
23
+ readonly timestamp: string;
24
+ readonly intent: WorkflowIntentDiff;
25
+ }
26
+
27
+ export interface WorkflowIntentReportTotals {
28
+ readonly total: number;
29
+ readonly byRoute: WorkflowRouteCounts;
30
+ readonly escalationRequired: number;
31
+ readonly rootCauseActive: number;
32
+ }
33
+
34
+ export interface WorkflowIntentReportCollection {
35
+ readonly entries: readonly WorkflowIntentReportEntry[];
36
+ readonly latest: WorkflowIntentReportEntry | undefined;
37
+ readonly totals: WorkflowIntentReportTotals;
38
+ }
39
+
40
+ export interface WorkflowObserverSignalSummary {
41
+ readonly observer: WorkflowSignalObserver;
42
+ readonly conclusion: string;
43
+ readonly count: number;
44
+ }
45
+
46
+ export interface WorkflowConsensusSummary {
47
+ readonly total: number;
48
+ readonly dominantRoute: WorkflowIntentRoute | undefined;
49
+ readonly confidence: WorkflowConsumerConfidence;
50
+ readonly escalationGate: {
51
+ readonly required: boolean;
52
+ readonly count: number;
53
+ readonly latestReason: string | undefined;
54
+ };
55
+ readonly rootCausePhase: {
56
+ readonly active: boolean;
57
+ readonly count: number;
58
+ readonly triggers: readonly string[];
59
+ };
60
+ readonly observerSignals: readonly WorkflowObserverSignalSummary[];
61
+ }
62
+
63
+ function emptyRouteCounts(): WorkflowRouteCounts {
64
+ return {
65
+ direct: 0,
66
+ "deep-interview": 0,
67
+ ralplan: 0,
68
+ ultragoal: 0,
69
+ team: 0,
70
+ };
71
+ }
72
+
73
+ function parseWorkflowIntentDiffEntry(entry: SessionEntry): WorkflowIntentReportEntry | undefined {
74
+ if (entry.type !== "custom" || entry.customType !== WORKFLOW_INTENT_DIFF_CUSTOM_TYPE) return undefined;
75
+ const intent = parseWorkflowIntentDiffPayload(entry.data);
76
+ if (!intent) return undefined;
77
+ return { entryId: entry.id, timestamp: entry.timestamp, intent };
78
+ }
79
+
80
+ function incrementRoute(counts: WorkflowRouteCounts, route: WorkflowIntentRoute): WorkflowRouteCounts {
81
+ switch (route) {
82
+ case "direct":
83
+ return { ...counts, direct: counts.direct + 1 };
84
+ case "deep-interview":
85
+ return { ...counts, "deep-interview": counts["deep-interview"] + 1 };
86
+ case "ralplan":
87
+ return { ...counts, ralplan: counts.ralplan + 1 };
88
+ case "ultragoal":
89
+ return { ...counts, ultragoal: counts.ultragoal + 1 };
90
+ case "team":
91
+ return { ...counts, team: counts.team + 1 };
92
+ }
93
+ }
94
+
95
+ function routeCount(counts: WorkflowRouteCounts, route: WorkflowIntentRoute): number {
96
+ switch (route) {
97
+ case "direct":
98
+ return counts.direct;
99
+ case "deep-interview":
100
+ return counts["deep-interview"];
101
+ case "ralplan":
102
+ return counts.ralplan;
103
+ case "ultragoal":
104
+ return counts.ultragoal;
105
+ case "team":
106
+ return counts.team;
107
+ }
108
+ }
109
+
110
+ export function collectWorkflowIntentReports(entries: readonly SessionEntry[]): WorkflowIntentReportCollection {
111
+ const reports: WorkflowIntentReportEntry[] = [];
112
+ let byRoute = emptyRouteCounts();
113
+ let escalationRequired = 0;
114
+ let rootCauseActive = 0;
115
+
116
+ for (const entry of entries) {
117
+ const report = parseWorkflowIntentDiffEntry(entry);
118
+ if (!report) continue;
119
+ reports.push(report);
120
+ byRoute = incrementRoute(byRoute, report.intent.route);
121
+ if (report.intent.consensusReport.escalationGate.status === "required") escalationRequired += 1;
122
+ if (report.intent.rootCausePhase.status === "active") rootCauseActive += 1;
123
+ }
124
+
125
+ return {
126
+ entries: reports,
127
+ latest: reports[reports.length - 1],
128
+ totals: {
129
+ total: reports.length,
130
+ byRoute,
131
+ escalationRequired,
132
+ rootCauseActive,
133
+ },
134
+ };
135
+ }
136
+
137
+ function dominantRouteFor(counts: WorkflowRouteCounts, total: number): WorkflowIntentRoute | undefined {
138
+ if (total === 0) return undefined;
139
+ let dominant: WorkflowIntentRoute | undefined;
140
+ let dominantCount = 0;
141
+ let tied = false;
142
+
143
+ for (const route of WORKFLOW_INTENT_ROUTES) {
144
+ const count = routeCount(counts, route);
145
+ if (count > dominantCount) {
146
+ dominant = route;
147
+ dominantCount = count;
148
+ tied = false;
149
+ continue;
150
+ }
151
+ if (count === dominantCount && count > 0) tied = true;
152
+ }
153
+
154
+ return tied ? undefined : dominant;
155
+ }
156
+
157
+ function confidenceFor(
158
+ total: number,
159
+ dominantCount: number,
160
+ dominantRoute: WorkflowIntentRoute | undefined,
161
+ ): WorkflowConsumerConfidence {
162
+ if (total === 0) return "none";
163
+ if (!dominantRoute) return "low";
164
+ const ratio = dominantCount / total;
165
+ if (ratio === 1) return "high";
166
+ if (ratio >= 0.5) return "medium";
167
+ return "low";
168
+ }
169
+
170
+ export function summarizeWorkflowConsensus(intents: readonly WorkflowIntentDiff[]): WorkflowConsensusSummary {
171
+ let byRoute = emptyRouteCounts();
172
+ let escalationCount = 0;
173
+ let latestEscalationReason: string | undefined;
174
+ let activeRootCauseCount = 0;
175
+ const rootCauseTriggers: string[] = [];
176
+ const observerSignalCounts = new Map<string, WorkflowObserverSignalSummary>();
177
+
178
+ for (const intent of intents) {
179
+ byRoute = incrementRoute(byRoute, intent.route);
180
+ if (intent.consensusReport.escalationGate.status === "required") {
181
+ escalationCount += 1;
182
+ latestEscalationReason = intent.consensusReport.escalationGate.reason;
183
+ }
184
+ if (intent.rootCausePhase.status === "active") {
185
+ activeRootCauseCount += 1;
186
+ for (const trigger of intent.rootCausePhase.triggers) {
187
+ if (!rootCauseTriggers.includes(trigger)) rootCauseTriggers.push(trigger);
188
+ }
189
+ }
190
+ for (const signal of intent.consensusReport.observerSignals) {
191
+ const key = `${signal.observer}\u0000${signal.conclusion}`;
192
+ const existing = observerSignalCounts.get(key);
193
+ observerSignalCounts.set(key, {
194
+ observer: signal.observer,
195
+ conclusion: signal.conclusion,
196
+ count: existing ? existing.count + 1 : 1,
197
+ });
198
+ }
199
+ }
200
+
201
+ const total = intents.length;
202
+ const dominantRoute = dominantRouteFor(byRoute, total);
203
+ const dominantCount = dominantRoute ? routeCount(byRoute, dominantRoute) : 0;
204
+
205
+ return {
206
+ total,
207
+ dominantRoute,
208
+ confidence: confidenceFor(total, dominantCount, dominantRoute),
209
+ escalationGate: {
210
+ required: escalationCount > 0,
211
+ count: escalationCount,
212
+ latestReason: latestEscalationReason,
213
+ },
214
+ rootCausePhase: {
215
+ active: activeRootCauseCount > 0,
216
+ count: activeRootCauseCount,
217
+ triggers: rootCauseTriggers,
218
+ },
219
+ observerSignals: Array.from(observerSignalCounts.values()),
220
+ };
221
+ }