agent-afk 5.289.1 → 5.290.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.
@@ -0,0 +1,9 @@
1
+ export declare const ACTIVITY_PROMPT_HEAD_MAX = 120;
2
+ export interface PresenceActivity {
3
+ promptHead?: string;
4
+ turns: number;
5
+ lastTurnEndedAt?: string;
6
+ }
7
+ export declare function normalizePromptHead(raw: string): string | undefined;
8
+ export declare function setPresenceActivityPromptHead(sessionId: string, rawText: string): Promise<void>;
9
+ export declare function setPresenceActivityTurnEnd(sessionId: string, totalTurns: number, rawUserText?: string): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import type { RuntimeWorkspace } from './types.js';
2
2
  import type { TraceActor } from '../session/session-identity.js';
3
3
  import { type ProcessLiveness } from '../process-liveness.js';
4
+ import { type StartTimeProbe } from './presence.liveness.js';
4
5
  export declare const PRESENCE_SCHEMA_VERSION = 1;
5
6
  export interface PresenceFileInfo {
6
7
  sessionId: string;
@@ -14,6 +15,8 @@ export interface PresenceFileInfo {
14
15
  };
15
16
  workspace: RuntimeWorkspace;
16
17
  pid: number;
18
+ pidStartedAt?: number;
19
+ pidStartTicks?: number;
17
20
  afk?: boolean;
18
21
  schemaVersion?: number;
19
22
  heartbeatAt?: string;
@@ -22,6 +25,11 @@ export interface PresenceFileInfo {
22
25
  turnState?: 'idle' | 'busy' | 'blocked';
23
26
  turnStateSince?: string;
24
27
  peerInbox?: boolean;
28
+ activity?: {
29
+ promptHead?: string;
30
+ turns: number;
31
+ lastTurnEndedAt?: string;
32
+ };
25
33
  }
26
34
  export type PresenceLiveness = ProcessLiveness;
27
35
  export interface PresenceRecord extends PresenceFileInfo {
@@ -31,7 +39,10 @@ export interface PresenceRecord extends PresenceFileInfo {
31
39
  }
32
40
  export declare function writePresenceFile(info: PresenceFileInfo): Promise<void>;
33
41
  export declare function writePresenceFileSync(info: PresenceFileInfo): void;
34
- export declare function touchPresenceHeartbeat(sessionId: string): Promise<void>;
42
+ export interface TouchHeartbeatOptions {
43
+ stillOwned?: () => boolean;
44
+ }
45
+ export declare function touchPresenceHeartbeat(sessionId: string, options?: TouchHeartbeatOptions): Promise<void>;
35
46
  export declare function patchPresenceFile(sessionId: string, patch: (record: PresenceFileInfo) => void): Promise<void>;
36
47
  export declare function setPresenceAfk(sessionId: string, afk: boolean): Promise<void>;
37
48
  export declare function setPresenceBlocked(sessionId: string, blocked: boolean): Promise<void>;
@@ -41,5 +52,6 @@ export declare function removePresenceFileSync(sessionId: string): void;
41
52
  export declare function readPresenceFiles(): Promise<PresenceRecord[]>;
42
53
  export interface ReadLivePresenceOptions {
43
54
  maxHeartbeatAgeMs?: number;
55
+ startTimeProbe?: StartTimeProbe;
44
56
  }
45
57
  export declare function readLivePresenceFiles(options?: ReadLivePresenceOptions): Promise<PresenceRecord[]>;
@@ -0,0 +1,22 @@
1
+ import type { PresenceRecord } from './presence.js';
2
+ import { type ProcessStartInfo } from '../process-liveness.start-time.js';
3
+ export declare const START_TIME_TOLERANCE_MS = 5000;
4
+ export declare const LEGACY_STALE_HEARTBEAT_MS: number;
5
+ export type PresenceVerdict = 'live' | 'dead' | 'reused' | 'stale-legacy';
6
+ export type StartTimeProbe = (pids: readonly number[]) => Promise<Map<number, ProcessStartInfo | undefined>>;
7
+ type IdentityFields = Pick<PresenceRecord, 'liveness' | 'heartbeatAgeMs' | 'pidStartedAt' | 'pidStartTicks'>;
8
+ export declare function classifyPresenceRecord(record: IdentityFields, probed: ProcessStartInfo | undefined): PresenceVerdict;
9
+ export declare const START_TIME_PROBE_CACHE_TTL_MS = 30000;
10
+ export declare class StartTimeProbeCache {
11
+ private readonly ttlMs;
12
+ private readonly now;
13
+ private readonly entries;
14
+ constructor(ttlMs?: number, now?: () => number);
15
+ static keyFor(record: Pick<PresenceRecord, 'pid' | 'pidStartedAt' | 'pidStartTicks'>): string;
16
+ get(key: string): ProcessStartInfo | undefined;
17
+ set(key: string, info: ProcessStartInfo): void;
18
+ clear(): void;
19
+ }
20
+ export declare function _resetStartTimeProbeCacheForTest(): void;
21
+ export declare function filterVerifiedLive(records: PresenceRecord[], probe?: StartTimeProbe, cache?: StartTimeProbeCache): Promise<PresenceRecord[]>;
22
+ export {};
@@ -0,0 +1,7 @@
1
+ export interface SweepDeadPresenceOptions {
2
+ selfIds?: ReadonlySet<string>;
3
+ kill?: (pid: number, signal: 0) => void;
4
+ remove?: (path: string) => Promise<void>;
5
+ read?: (path: string) => Promise<string>;
6
+ }
7
+ export declare function sweepDeadPresence(opts?: SweepDeadPresenceOptions): Promise<number>;
@@ -0,0 +1,26 @@
1
+ export interface ProcessStartInfo {
2
+ startedAtMs?: number;
3
+ startTicks?: number;
4
+ }
5
+ export type StartTimeExec = (file: string, args: string[]) => Promise<{
6
+ stdout: string;
7
+ }>;
8
+ export interface StartTimeProbeDeps {
9
+ platform?: NodeJS.Platform;
10
+ exec?: StartTimeExec;
11
+ readFile?: (path: string) => Promise<string>;
12
+ now?: () => number;
13
+ }
14
+ export declare const LINUX_CLOCK_TICKS_PER_SEC = 100;
15
+ export declare function parseEtime(value: string): number | undefined;
16
+ export declare function parsePsStartTimes(stdout: string, nowMs: number): Map<number, number>;
17
+ export declare function parseProcStatStartTicks(stat: string): number | undefined;
18
+ export declare function parseProcBootTime(procStat: string): number | undefined;
19
+ export declare function probeProcessStartTimes(pids: readonly number[], deps?: StartTimeProbeDeps): Promise<Map<number, ProcessStartInfo | undefined>>;
20
+ export declare function ownProcessStartedAt(): number;
21
+ export interface OwnStartTicksDeps {
22
+ platform?: NodeJS.Platform;
23
+ readFileSync?: (path: string) => string;
24
+ }
25
+ export declare function readOwnStartTicks(deps?: OwnStartTicksDeps): number | undefined;
26
+ export declare function ownProcessStartTicks(): number | undefined;
@@ -1,3 +1,5 @@
1
+ export declare const PRESENCE_HEARTBEAT_INTERVAL_MS = 60000;
2
+ export declare function _getPresenceHeartbeatTimerForTest(): ReturnType<typeof setInterval> | null;
1
3
  export declare function registerPresenceCleanup(sessionId: string): void;
2
4
  export declare function unregisterPresenceCleanup(sessionId: string): void;
3
5
  export declare function _resetPresenceSignalsForTest(): void;
@@ -3,4 +3,4 @@ export interface InjectionSource {
3
3
  drainInjections(): string;
4
4
  }
5
5
  export declare function prependTurnInjections(runText: string, sources: readonly InjectionSource[]): string;
6
- export declare function markPresenceTurn(sessionId: string | undefined, state: 'idle' | 'busy'): void;
6
+ export declare function markPresenceTurn(sessionId: string | undefined, state: 'idle' | 'busy', rawUserText?: string, totalTurns?: number): void;
@@ -9,4 +9,4 @@ export interface TerminalCapture {
9
9
  doneHasEvidence: boolean | undefined;
10
10
  doneClassification: 'no-code-changes' | 'verified' | 'unverified' | undefined;
11
11
  }
12
- export declare function runOneTurn(runText: string, attachments: readonly ImageAttachment[], ctx: InteractiveCtx, turnState: TurnState, footer: FooterSubsystems, transcript: TranscriptHandle, surface: InputSurface, installSoftStop: (handler: (() => void) | null) => void, maxTurnsNum: number | undefined, autosaveState: [autosaveFailureLogged: boolean]): Promise<TerminalCapture>;
12
+ export declare function runOneTurn(runText: string, attachments: readonly ImageAttachment[], ctx: InteractiveCtx, turnState: TurnState, footer: FooterSubsystems, transcript: TranscriptHandle, surface: InputSurface, installSoftStop: (handler: (() => void) | null) => void, maxTurnsNum: number | undefined, autosaveState: [autosaveFailureLogged: boolean], rawUserText: string): Promise<TerminalCapture>;