agent-afk 5.319.1 → 5.319.3

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.
@@ -1,4 +1,5 @@
1
1
  import { type HandoffRecord } from './handoff-store.js';
2
+ export declare const RESUME_QUEUE_SUBDIR = "handoff-resume";
2
3
  export declare const DEFAULT_HANDOFF_TTL_MS: number;
3
4
  export declare const EXPIRY_SWEEP_INTERVAL_MS = 60000;
4
5
  export interface ExpireHandoffOpts {
@@ -10,5 +11,9 @@ export interface ExpireHandoffOpts {
10
11
  export declare function isHandoffStale(record: Pick<HandoffRecord, 'createdAt'>, now: number, ttlMs?: number): boolean;
11
12
  export declare function expireHandoff(taskId: string, opts?: ExpireHandoffOpts): Promise<boolean>;
12
13
  export declare function expireStaleHandoffs(opts?: ExpireHandoffOpts): Promise<number>;
13
- export declare function sweepExpiredHandoffs(queueDir: string, now?: number): void;
14
+ export declare function sweepExpiredHandoffs(queueDir: string, now?: number, handoffsDir?: string): void;
14
15
  export declare function resetExpirySweepThrottleForTests(): void;
16
+ export declare function expiryNoticeRoute(route: unknown): {
17
+ target: number;
18
+ messageThreadId?: number;
19
+ } | undefined;
@@ -0,0 +1,18 @@
1
+ import type { Telegraf } from 'telegraf';
2
+ import { RESUME_QUEUE_SUBDIR } from './handoff-expiry.js';
3
+ export declare const HANDOFF_MAINTENANCE_INTERVAL_MS = 30000;
4
+ export { RESUME_QUEUE_SUBDIR };
5
+ export declare function resumeQueueDir(queueDir: string): string;
6
+ export interface HandoffMaintenanceOpts {
7
+ queueDir: string;
8
+ handoffsDir?: string;
9
+ bot?: Telegraf;
10
+ drainResumeQueue: (resumeDir: string) => Promise<void>;
11
+ intervalMs?: number;
12
+ }
13
+ export interface HandoffMaintenanceHandle {
14
+ stop(): void;
15
+ }
16
+ export declare function runStartupRecovery(opts: HandoffMaintenanceOpts, resumeDir: string): Promise<void>;
17
+ export declare function consumeAndResume(opts: HandoffMaintenanceOpts, resumeDir: string): Promise<void>;
18
+ export declare function startHandoffMaintenance(opts: HandoffMaintenanceOpts): HandoffMaintenanceHandle;
@@ -0,0 +1,10 @@
1
+ import type { ScheduledTask } from './triggers.js';
2
+ export interface HandoffResumeContext {
3
+ originalTaskId?: string;
4
+ cwd?: string;
5
+ notifyOn?: 'failure' | 'always' | 'never';
6
+ notifyChat?: number | string;
7
+ }
8
+ export declare function pickResumeFields(src: unknown): HandoffResumeContext;
9
+ export declare function resumeContextFromTask(task: ScheduledTask): HandoffResumeContext;
10
+ export declare function overlapKeyOf(task: Pick<ScheduledTask, 'taskId' | 'overlapKey'>): string;
@@ -22,6 +22,10 @@ export interface HandoffRecord {
22
22
  responderIdentity?: string;
23
23
  originalCommand: string;
24
24
  telegramMessageId?: number;
25
+ originalTaskId?: string;
26
+ cwd?: string;
27
+ notifyOn?: 'failure' | 'always' | 'never';
28
+ notifyChat?: number | string;
25
29
  }
26
30
  export declare function writeHandoff(record: HandoffRecord, handoffsDir?: string): Promise<void>;
27
31
  export declare function readHandoff(taskId: string, handoffsDir?: string): Promise<HandoffRecord | null>;
@@ -1,3 +1,4 @@
1
+ import { type HandoffResumeContext } from './handoff-resume-context.js';
1
2
  import type { ElicitationHandler } from '../elicitation-router.js';
2
3
  import type { Telegraf } from 'telegraf';
3
4
  export interface DaemonElicitationOpts {
@@ -8,6 +9,7 @@ export interface DaemonElicitationOpts {
8
9
  bot?: Telegraf;
9
10
  chatId?: number;
10
11
  threadId?: number;
12
+ resumeContext?: HandoffResumeContext;
11
13
  }
12
14
  export declare function makeDaemonElicitationHandler(opts: DaemonElicitationOpts): ElicitationHandler;
13
15
  export interface RecoveryResult {
@@ -1,4 +1,5 @@
1
1
  import { recoverExpiredLeases } from './lease-store.js';
2
+ import { type HandoffResumeContext } from './handoff-resume-context.js';
2
3
  export { recoverExpiredLeases };
3
4
  export interface QueuedTask {
4
5
  id: string;
@@ -11,8 +12,11 @@ export interface QueuedTask {
11
12
  backoffStrategy?: 'fixed' | 'exponential';
12
13
  backoffBaseMs?: number;
13
14
  eligibleAfter?: number;
15
+ originalTaskId?: string;
16
+ cwd?: string;
17
+ notifyChat?: number | string;
14
18
  }
15
- export interface EnqueueOptions {
19
+ export interface EnqueueOptions extends HandoffResumeContext {
16
20
  notifyOn?: 'failure' | 'always' | 'never';
17
21
  }
18
22
  export declare function enqueue(command: string, opts?: EnqueueOptions, queueDir?: string): QueuedTask;
@@ -59,6 +59,7 @@ export declare class CronScheduler {
59
59
  private readonly now;
60
60
  private readonly idleDetector;
61
61
  private pullPollTimer;
62
+ private handoffMaintenance;
62
63
  private isDequeuing;
63
64
  private readonly queueDir;
64
65
  private readonly inFlightTasks;
@@ -80,6 +81,7 @@ export declare class CronScheduler {
80
81
  fireOnStart(): Promise<TelemetryRecord[]>;
81
82
  stop(): Promise<void>;
82
83
  startPullLoop(): void;
84
+ startHandoffMaintenance(intervalMs?: number): void;
83
85
  private pullTick;
84
86
  private runOnce;
85
87
  private spawnSession;
@@ -1,3 +1,4 @@
1
+ import { type HandoffResumeContext } from './handoff-resume-context.js';
1
2
  import type { ElicitationHandler } from '../elicitation-router.js';
2
3
  import type { Telegraf } from 'telegraf';
3
4
  export type { ElicitationHandler };
@@ -11,5 +12,6 @@ export interface CronElicitationHandlerOpts {
11
12
  bot?: Telegraf;
12
13
  chatId?: number;
13
14
  threadId?: number;
15
+ resumeContext?: HandoffResumeContext;
14
16
  }
15
17
  export declare function makeCronElicitationHandler(opts: CronElicitationHandlerOpts): ElicitationHandler;
@@ -15,3 +15,10 @@ export declare class OverlapAlertLatch {
15
15
  _reset(): void;
16
16
  }
17
17
  export declare function formatOverlapAlertMessage(taskId: string, command: string, cron: string | undefined): string;
18
+ export declare function snapshotInFlightTasks(inFlight: ReadonlyMap<string, number>, commandOf: (taskId: string) => string | undefined, now: number): Array<{
19
+ taskId: string;
20
+ displayId: string;
21
+ commandHead: string;
22
+ elapsedMs: number;
23
+ }>;
24
+ export declare function makeCwdErrorRecord(task: ScheduledTask, trigger: TelemetryTrigger, nowMs: number, cwdError: string): TelemetryRecord;
@@ -2,12 +2,14 @@ import type { ScheduledTask } from './triggers.js';
2
2
  import type { TelemetryRecord, TaskCompletionDetails } from './scheduler.js';
3
3
  export interface PullTickContext {
4
4
  queueDir: string;
5
+ handoffsDir?: string;
5
6
  isIdle: () => boolean;
6
7
  getIsDequeuing: () => boolean;
7
8
  setIsDequeuing: (v: boolean) => void;
8
9
  runOnce: (task: ScheduledTask, trigger: 'pull') => Promise<TelemetryRecord>;
10
+ isOverlapBusy?: (overlapKey: string) => boolean;
9
11
  }
10
- export declare function sweepAnsweredHandoffs(queueDir: string): void;
12
+ export declare function sweepAnsweredHandoffs(queueDir: string, handoffsDir?: string): void;
11
13
  export declare function executePullTick(ctx: PullTickContext): Promise<void>;
12
14
  export interface FireOnTaskCompleteOptions {
13
15
  onTaskComplete?: (record: TelemetryRecord, details?: TaskCompletionDetails) => void | Promise<void>;
@@ -14,5 +14,6 @@ export interface ScheduledTask {
14
14
  cwd?: string;
15
15
  maxAttempts?: number;
16
16
  retryDelayMs?: number;
17
+ overlapKey?: string;
17
18
  }
18
19
  export declare function validateScheduledTask(task: ScheduledTask): void;
@@ -16,6 +16,7 @@ export interface DaemonOptions {
16
16
  onTaskTurnComplete?: SchedulerOptions['onTaskTurnComplete'];
17
17
  pullPollIntervalMs?: number;
18
18
  queueDir?: string;
19
+ handoffMaintenance?: boolean;
19
20
  writePortFile?: boolean;
20
21
  bot?: Telegraf;
21
22
  primaryChatId?: number;