@fenixforce/kernel 0.1.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.
- package/dist/agent/execution-result.d.ts +27 -0
- package/dist/agent-loop.d.ts +55 -0
- package/dist/api/dashboard.d.ts +260 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/api/middleware.d.ts +46 -0
- package/dist/api/openai-compat.d.ts +163 -0
- package/dist/api/server.d.ts +44 -0
- package/dist/api/streaming.d.ts +15 -0
- package/dist/api/webhook-triggers.d.ts +139 -0
- package/dist/billing/cost-meter.d.ts +123 -0
- package/dist/billing/index.d.ts +2 -0
- package/dist/boot.d.ts +109 -0
- package/dist/channels/discord.d.ts +99 -0
- package/dist/channels/email.d.ts +88 -0
- package/dist/channels/http-api.d.ts +155 -0
- package/dist/channels/index.d.ts +20 -0
- package/dist/channels/mcp-channel.d.ts +75 -0
- package/dist/channels/mobile-hil.d.ts +88 -0
- package/dist/channels/openai-compat.d.ts +42 -0
- package/dist/channels/registry.d.ts +80 -0
- package/dist/channels/signal.d.ts +75 -0
- package/dist/channels/slack.d.ts +115 -0
- package/dist/channels/teams.d.ts +106 -0
- package/dist/channels/telegram.d.ts +164 -0
- package/dist/channels/types.d.ts +71 -0
- package/dist/channels/whatsapp.d.ts +83 -0
- package/dist/checkpoint.d.ts +77 -0
- package/dist/config/canary.d.ts +74 -0
- package/dist/config/constitution.d.ts +57 -0
- package/dist/config/defaults.d.ts +17 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/loader.d.ts +11 -0
- package/dist/config/provider-config.d.ts +29 -0
- package/dist/config/schema.d.ts +118 -0
- package/dist/config/steering-rules.d.ts +28 -0
- package/dist/content/chunker.d.ts +42 -0
- package/dist/content/entity-extractor.d.ts +58 -0
- package/dist/content/index.d.ts +8 -0
- package/dist/content/ocr.d.ts +79 -0
- package/dist/content/pipeline.d.ts +153 -0
- package/dist/context-overflow.d.ts +19 -0
- package/dist/editions/mobile.d.ts +12 -0
- package/dist/editions/pro.d.ts +12 -0
- package/dist/editions/voices.d.ts +14 -0
- package/dist/events/block-manager.d.ts +37 -0
- package/dist/events/bus.d.ts +39 -0
- package/dist/events/index.d.ts +8 -0
- package/dist/events/session-manager.d.ts +59 -0
- package/dist/events/stream-adapter.d.ts +24 -0
- package/dist/events/types.d.ts +465 -0
- package/dist/events/websocket.d.ts +34 -0
- package/dist/extensions/defaults/05-session-repair.d.ts +6 -0
- package/dist/extensions/defaults/10-logging.d.ts +6 -0
- package/dist/extensions/defaults/15-loop-guard.d.ts +6 -0
- package/dist/extensions/defaults/20-cost-tracking.d.ts +7 -0
- package/dist/extensions/defaults/25-ssrf-protection.d.ts +6 -0
- package/dist/extensions/defaults/30-rate-limiting.d.ts +6 -0
- package/dist/extensions/defaults/35-shell-bleed.d.ts +6 -0
- package/dist/extensions/defaults/40-observation-capture.d.ts +7 -0
- package/dist/extensions/defaults/45-context-survival.d.ts +6 -0
- package/dist/extensions/defaults/50-context-budget.d.ts +6 -0
- package/dist/extensions/defaults/55-steering-rules.d.ts +7 -0
- package/dist/extensions/defaults/60-quality-gates.d.ts +7 -0
- package/dist/extensions/defaults/65-job-dispatch.d.ts +24 -0
- package/dist/extensions/defaults/70-skill-loader.d.ts +18 -0
- package/dist/extensions/hooks.d.ts +74 -0
- package/dist/extensions/index.d.ts +21 -0
- package/dist/extensions/intervention.d.ts +59 -0
- package/dist/extensions/manager.d.ts +63 -0
- package/dist/extensions/runner.d.ts +63 -0
- package/dist/hooks/hook-manager.d.ts +39 -0
- package/dist/hooks/hook-types.d.ts +60 -0
- package/dist/identity/assembler.d.ts +45 -0
- package/dist/identity/ccc-adapter.d.ts +33 -0
- package/dist/identity/index.d.ts +6 -0
- package/dist/identity/persona-parser.d.ts +24 -0
- package/dist/identity/soul-parser.d.ts +23 -0
- package/dist/identity/user-populator.d.ts +20 -0
- package/dist/index.d.ts +227 -0
- package/dist/index.js +579 -0
- package/dist/interrupt.d.ts +84 -0
- package/dist/job-queue.d.ts +69 -0
- package/dist/jobs/index.d.ts +12 -0
- package/dist/jobs/memory-queue.d.ts +23 -0
- package/dist/jobs/planned-tasks.d.ts +121 -0
- package/dist/jobs/queue.d.ts +79 -0
- package/dist/jobs/router.d.ts +23 -0
- package/dist/jobs/synthesize-memories.d.ts +26 -0
- package/dist/jobs/types.d.ts +47 -0
- package/dist/jobs/worker-pool.d.ts +25 -0
- package/dist/jobs/worker.d.ts +40 -0
- package/dist/loop/autonomous-controller.d.ts +91 -0
- package/dist/loop/backpressure.d.ts +64 -0
- package/dist/loop/fresh-context.d.ts +48 -0
- package/dist/loop/prd-importer.d.ts +134 -0
- package/dist/loop/stop-controller.d.ts +31 -0
- package/dist/loop-guard.d.ts +32 -0
- package/dist/mcp/tool-executor.d.ts +57 -0
- package/dist/memory/brain-artifacts.d.ts +25 -0
- package/dist/memory/dual-search.d.ts +67 -0
- package/dist/memory/episodic.d.ts +45 -0
- package/dist/memory/index.d.ts +27 -0
- package/dist/memory/knowledge-graph.d.ts +89 -0
- package/dist/memory/markdown-store.d.ts +64 -0
- package/dist/memory/metadata-filter.d.ts +29 -0
- package/dist/memory/mid-conversation-saves.d.ts +17 -0
- package/dist/memory/note-parser.d.ts +34 -0
- package/dist/memory/observation-store.d.ts +36 -0
- package/dist/memory/observation-thresholds.d.ts +26 -0
- package/dist/memory/progressive-search.d.ts +25 -0
- package/dist/memory/synthesis.d.ts +36 -0
- package/dist/memory/tree-index.d.ts +104 -0
- package/dist/memory/write-gate.d.ts +63 -0
- package/dist/mission-control.d.ts +34 -0
- package/dist/pre-classifier-widgets.d.ts +40 -0
- package/dist/pre-classifier.d.ts +19 -0
- package/dist/prompt/context-budget.d.ts +68 -0
- package/dist/prompt/index.d.ts +3 -0
- package/dist/prompt/system-prompt.d.ts +32 -0
- package/dist/prompt/templates.d.ts +11 -0
- package/dist/providers/anthropic.d.ts +24 -0
- package/dist/providers/auto-detect.d.ts +16 -0
- package/dist/providers/auto-discover.d.ts +28 -0
- package/dist/providers/bedrock.d.ts +38 -0
- package/dist/providers/cache-strategy.d.ts +58 -0
- package/dist/providers/circuit-breaker.d.ts +33 -0
- package/dist/providers/cost-meter.d.ts +74 -0
- package/dist/providers/cost-tracking.d.ts +36 -0
- package/dist/providers/google.d.ts +35 -0
- package/dist/providers/index.d.ts +32 -0
- package/dist/providers/interface.d.ts +98 -0
- package/dist/providers/json-repair.d.ts +10 -0
- package/dist/providers/key-rotation.d.ts +36 -0
- package/dist/providers/manager.d.ts +64 -0
- package/dist/providers/model-registry.d.ts +50 -0
- package/dist/providers/openai-compatible.d.ts +26 -0
- package/dist/providers/optimization-modes.d.ts +38 -0
- package/dist/providers/provider-manager.d.ts +71 -0
- package/dist/providers/runtime-crud.d.ts +68 -0
- package/dist/providers/sidecar-lifecycle.d.ts +40 -0
- package/dist/providers/stream-wrapper.d.ts +21 -0
- package/dist/providers/structured-verify.d.ts +31 -0
- package/dist/providers/versioning.d.ts +18 -0
- package/dist/quality-gates.d.ts +10 -0
- package/dist/scheduler/engine.d.ts +95 -0
- package/dist/scheduler/index.d.ts +4 -0
- package/dist/scheduler/webhook-handler.d.ts +37 -0
- package/dist/sdk/agent.d.ts +22 -0
- package/dist/sdk/cli.d.ts +2 -0
- package/dist/sdk/client.d.ts +19 -0
- package/dist/sdk/index.d.ts +24 -0
- package/dist/sdk/jobs.d.ts +25 -0
- package/dist/sdk/memory.d.ts +18 -0
- package/dist/sdk/types.d.ts +69 -0
- package/dist/security/approval-gates.d.ts +166 -0
- package/dist/security/content-wrapper.d.ts +38 -0
- package/dist/security/guard-rails.d.ts +6 -0
- package/dist/security/index.d.ts +21 -0
- package/dist/security/instruction-hierarchy.d.ts +109 -0
- package/dist/security/pii-tokenizer.d.ts +30 -0
- package/dist/security/reputation.d.ts +53 -0
- package/dist/security/secret-store.d.ts +41 -0
- package/dist/security/security-engine.d.ts +53 -0
- package/dist/security/shell-bleed.d.ts +15 -0
- package/dist/security/ssrf.d.ts +12 -0
- package/dist/security/taint-tracker.d.ts +63 -0
- package/dist/security/tool-access-control.d.ts +114 -0
- package/dist/session-compaction.d.ts +20 -0
- package/dist/session-orient.d.ts +22 -0
- package/dist/session-repair.d.ts +6 -0
- package/dist/storage/index.d.ts +24 -0
- package/dist/storage/interface.d.ts +245 -0
- package/dist/storage/postgres.d.ts +6 -0
- package/dist/storage/sqlite.d.ts +2 -0
- package/dist/streaming/reasoning.d.ts +67 -0
- package/dist/task-tracker.d.ts +26 -0
- package/dist/testing/action-cache.d.ts +39 -0
- package/dist/testing/incident-eval.d.ts +49 -0
- package/dist/testing/workflow-evals.d.ts +73 -0
- package/dist/tools/access-control.d.ts +60 -0
- package/dist/tools/browser-engine.d.ts +73 -0
- package/dist/tools/builtins/jobs-router.d.ts +7 -0
- package/dist/tools/builtins/tasks-router.d.ts +25 -0
- package/dist/tools/index.d.ts +20 -0
- package/dist/tools/map-reduce.d.ts +64 -0
- package/dist/tools/registry.d.ts +39 -0
- package/dist/tools/router.d.ts +30 -0
- package/dist/tools/routers/browser-router.d.ts +12 -0
- package/dist/tools/routers/code-router.d.ts +34 -0
- package/dist/tools/routers/file-router.d.ts +35 -0
- package/dist/tools/routers/memory-router.d.ts +21 -0
- package/dist/tools/routers/schedule-router.d.ts +31 -0
- package/dist/tools/routers/search-backends.d.ts +47 -0
- package/dist/tools/routers/task-router.d.ts +32 -0
- package/dist/tools/routers/web-router.d.ts +36 -0
- package/dist/tools/skill-discovery.d.ts +32 -0
- package/dist/tools/skill-loader.d.ts +76 -0
- package/dist/tools/skill-types.d.ts +21 -0
- package/dist/voice/audio-intelligence.d.ts +42 -0
- package/dist/voice/barge-in.d.ts +51 -0
- package/dist/voice/index.d.ts +22 -0
- package/dist/voice/marker-parser.d.ts +31 -0
- package/dist/voice/sidecar-manager.d.ts +68 -0
- package/dist/voice/speaker-focus.d.ts +41 -0
- package/dist/voice/speaker-voiceprint.d.ts +47 -0
- package/dist/voice/speech-intent.d.ts +51 -0
- package/dist/voice/speechmatics-stt.d.ts +77 -0
- package/dist/voice/speechmatics-tts.d.ts +39 -0
- package/dist/voice/stt-provider.d.ts +40 -0
- package/dist/voice/transcript.d.ts +19 -0
- package/dist/voice/turn-detection.d.ts +53 -0
- package/dist/wrapup.d.ts +15 -0
- package/package.json +39 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interrupt and Resume — allow users to interrupt a running agent loop
|
|
3
|
+
* mid-execution, save a checkpoint, and resume later.
|
|
4
|
+
*
|
|
5
|
+
* The agent loop checks an AbortSignal between iterations. When interrupted:
|
|
6
|
+
* 1. Save checkpoint via CheckpointManager
|
|
7
|
+
* 2. Emit agent:interrupted event
|
|
8
|
+
* 3. Return partial results with resume instructions
|
|
9
|
+
*
|
|
10
|
+
* Channel implementations:
|
|
11
|
+
* - Telegram: /stop command
|
|
12
|
+
* - HTTP: POST /api/v1/conversations/:id/interrupt
|
|
13
|
+
* - WebSocket: { type: "interrupt" }
|
|
14
|
+
*
|
|
15
|
+
* Depends on Checkpoint (Task 3.10).
|
|
16
|
+
*/
|
|
17
|
+
import type { CheckpointManager, CheckpointMessage, Checkpoint } from "./checkpoint.js";
|
|
18
|
+
export interface InterruptState {
|
|
19
|
+
/** Whether an interrupt has been requested. */
|
|
20
|
+
readonly interrupted: boolean;
|
|
21
|
+
/** The AbortSignal to check in the agent loop. */
|
|
22
|
+
readonly signal: AbortSignal;
|
|
23
|
+
/** Request an interrupt. */
|
|
24
|
+
interrupt(): void;
|
|
25
|
+
/** Reset for a new run. */
|
|
26
|
+
reset(): void;
|
|
27
|
+
}
|
|
28
|
+
export interface InterruptResult {
|
|
29
|
+
/** The checkpoint saved at interrupt time. */
|
|
30
|
+
checkpoint: Checkpoint;
|
|
31
|
+
/** Partial results collected before interruption. */
|
|
32
|
+
partialMessages: CheckpointMessage[];
|
|
33
|
+
/** Human-readable status message. */
|
|
34
|
+
message: string;
|
|
35
|
+
}
|
|
36
|
+
export interface ResumeRequest {
|
|
37
|
+
/** Session to resume. */
|
|
38
|
+
sessionId: string;
|
|
39
|
+
/** Specific checkpoint to resume from (default: latest). */
|
|
40
|
+
checkpointId?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ResumeResult {
|
|
43
|
+
/** The checkpoint being resumed from. */
|
|
44
|
+
checkpoint: Checkpoint;
|
|
45
|
+
/** Messages to feed back into the agent loop. */
|
|
46
|
+
messages: CheckpointMessage[];
|
|
47
|
+
/** Restored memory snapshot. */
|
|
48
|
+
memorySnapshot: Record<string, unknown>;
|
|
49
|
+
/** Restored tool state. */
|
|
50
|
+
toolState: Record<string, unknown>;
|
|
51
|
+
/** Restored task tracker state. */
|
|
52
|
+
taskTrackerState: Record<string, unknown>;
|
|
53
|
+
}
|
|
54
|
+
export type InterruptEventType = "agent:interrupted" | "agent:resuming" | "agent:resumed";
|
|
55
|
+
export interface InterruptEvent {
|
|
56
|
+
type: InterruptEventType;
|
|
57
|
+
timestamp: Date;
|
|
58
|
+
sessionId: string;
|
|
59
|
+
checkpointId?: string;
|
|
60
|
+
detail: string;
|
|
61
|
+
}
|
|
62
|
+
export type InterruptEventListener = (event: InterruptEvent) => void;
|
|
63
|
+
export declare function createInterruptState(): InterruptState;
|
|
64
|
+
export interface InterruptManagerConfig {
|
|
65
|
+
checkpoints: CheckpointManager;
|
|
66
|
+
}
|
|
67
|
+
export interface InterruptManager {
|
|
68
|
+
/** Create an interrupt state for a session. */
|
|
69
|
+
createState(sessionId: string): InterruptState;
|
|
70
|
+
/** Get the interrupt state for a session. */
|
|
71
|
+
getState(sessionId: string): InterruptState | undefined;
|
|
72
|
+
/** Interrupt a running session, saving a checkpoint. */
|
|
73
|
+
interruptSession(sessionId: string, currentMessages: CheckpointMessage[], state?: {
|
|
74
|
+
memorySnapshot?: Record<string, unknown>;
|
|
75
|
+
toolState?: Record<string, unknown>;
|
|
76
|
+
taskTrackerState?: Record<string, unknown>;
|
|
77
|
+
}): InterruptResult | undefined;
|
|
78
|
+
/** Resume a session from a checkpoint. */
|
|
79
|
+
resume(request: ResumeRequest): ResumeResult | undefined;
|
|
80
|
+
/** Events. */
|
|
81
|
+
on(listener: InterruptEventListener): void;
|
|
82
|
+
off(listener: InterruptEventListener): void;
|
|
83
|
+
}
|
|
84
|
+
export declare function createInterruptManager(config: InterruptManagerConfig): InterruptManager;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
type Listener = (...args: any[]) => void;
|
|
2
|
+
declare class TypedEmitter {
|
|
3
|
+
private _listeners;
|
|
4
|
+
on(event: string, fn: Listener): this;
|
|
5
|
+
off(event: string, fn: Listener): this;
|
|
6
|
+
emit(event: string, ...args: unknown[]): boolean;
|
|
7
|
+
}
|
|
8
|
+
export type JobStatus = "queued" | "running" | "completed" | "dead" | "cancelled";
|
|
9
|
+
export type JobPriority = "critical" | "high" | "normal" | "low";
|
|
10
|
+
export interface Job<T = unknown> {
|
|
11
|
+
id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
status: JobStatus;
|
|
14
|
+
priority: JobPriority;
|
|
15
|
+
payload: T;
|
|
16
|
+
result: unknown | null;
|
|
17
|
+
error: string | null;
|
|
18
|
+
attempts: number;
|
|
19
|
+
maxRetries: number;
|
|
20
|
+
retryBaseMs: number;
|
|
21
|
+
retryJitter: boolean;
|
|
22
|
+
nextRetryAt: Date | null;
|
|
23
|
+
concurrencyGroup: string | null;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
startedAt: Date | null;
|
|
27
|
+
completedAt: Date | null;
|
|
28
|
+
}
|
|
29
|
+
export interface JobOptions {
|
|
30
|
+
priority?: JobPriority;
|
|
31
|
+
maxRetries?: number;
|
|
32
|
+
retryBaseMs?: number;
|
|
33
|
+
retryJitter?: boolean;
|
|
34
|
+
concurrencyGroup?: string;
|
|
35
|
+
}
|
|
36
|
+
export type JobHandler = (job: Job) => Promise<unknown>;
|
|
37
|
+
export interface ConcurrencyGroupConfig {
|
|
38
|
+
[group: string]: number;
|
|
39
|
+
}
|
|
40
|
+
export interface JobQueueConfig {
|
|
41
|
+
pollIntervalMs?: number;
|
|
42
|
+
workerPoolSize?: number;
|
|
43
|
+
concurrencyGroups?: ConcurrencyGroupConfig;
|
|
44
|
+
}
|
|
45
|
+
export interface StorageAdapter {
|
|
46
|
+
query<R = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<{
|
|
47
|
+
rows: R[];
|
|
48
|
+
}>;
|
|
49
|
+
}
|
|
50
|
+
export declare class JobQueue extends TypedEmitter {
|
|
51
|
+
private storage;
|
|
52
|
+
private config;
|
|
53
|
+
private workerRunning;
|
|
54
|
+
private shutdownRequested;
|
|
55
|
+
private activeJobs;
|
|
56
|
+
constructor(storage: StorageAdapter, config?: JobQueueConfig);
|
|
57
|
+
enqueue<T>(type: string, payload: T, opts?: JobOptions): Promise<string>;
|
|
58
|
+
claimNext(workerTypes?: string[]): Promise<Job | null>;
|
|
59
|
+
completeJob(jobId: string, result?: unknown): Promise<void>;
|
|
60
|
+
failJob(jobId: string, error: Error): Promise<void>;
|
|
61
|
+
cancelJob(jobId: string): Promise<void>;
|
|
62
|
+
getJob(jobId: string): Promise<Job>;
|
|
63
|
+
getJobsByStatus(status: JobStatus, type?: string): Promise<Job[]>;
|
|
64
|
+
startWorker(handlers: Record<string, JobHandler>): void;
|
|
65
|
+
stopWorker(): Promise<void>;
|
|
66
|
+
private processJob;
|
|
67
|
+
}
|
|
68
|
+
export declare const JOB_QUEUE_SCHEMA = "\nCREATE TABLE IF NOT EXISTS jobs (\n id TEXT PRIMARY KEY,\n type TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'queued',\n priority TEXT NOT NULL DEFAULT 'normal',\n priority_num INTEGER NOT NULL DEFAULT 2,\n payload JSONB NOT NULL DEFAULT '{}',\n result JSONB,\n error TEXT,\n attempts INTEGER NOT NULL DEFAULT 0,\n max_retries INTEGER NOT NULL DEFAULT 3,\n retry_base_ms INTEGER NOT NULL DEFAULT 1000,\n retry_jitter BOOLEAN NOT NULL DEFAULT true,\n next_retry_at TIMESTAMPTZ,\n concurrency_group TEXT,\n created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),\n started_at TIMESTAMPTZ,\n completed_at TIMESTAMPTZ\n);\n\nCREATE INDEX IF NOT EXISTS idx_jobs_claim\n ON jobs (priority_num, created_at)\n WHERE status = 'queued';\nCREATE INDEX IF NOT EXISTS idx_jobs_status ON jobs(status);\nCREATE INDEX IF NOT EXISTS idx_jobs_type ON jobs(type);\nCREATE INDEX IF NOT EXISTS idx_jobs_concurrency\n ON jobs (concurrency_group)\n WHERE status = 'running';\n";
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { JobQueue, type Job, type JobStatus, type JobPriority, type JobOptions, type JobQueueConfig } from "./queue.js";
|
|
2
|
+
export { JobWorker, type JobHandler, type JobWorkerConfig } from "./worker.js";
|
|
3
|
+
export { createWorkerPool } from "./worker-pool.js";
|
|
4
|
+
export { createJobRouter } from "./router.js";
|
|
5
|
+
export { LOCAL_JOB_TYPES } from "./types.js";
|
|
6
|
+
export type { JobType } from "./types.js";
|
|
7
|
+
export type { WorkerPool, WorkerPoolOptions } from "./worker-pool.js";
|
|
8
|
+
export type { JobRouter, ToolRoute } from "./router.js";
|
|
9
|
+
export { createJobQueue, createJobWorker, _resetIdCounter } from "./memory-queue.js";
|
|
10
|
+
export type { MemoryJobWorker, MemoryWorkerOptions } from "./memory-queue.js";
|
|
11
|
+
export { createPlannedTaskScheduler, _resetTaskIds } from "./planned-tasks.js";
|
|
12
|
+
export type { PlannedStepStatus, PlannedTaskStatus, PlannedStep, PlannedTask, PlannedStepInput, CreatePlannedTaskInput, SchedulerJobQueue, SchedulerEventType, SchedulerEvent, SchedulerEventListener, PlannedTaskSchedulerConfig, PlannedTaskScheduler, } from "./planned-tasks.js";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory FIFO job queue — used by Mobile edition.
|
|
3
|
+
* For the production PostgreSQL-backed queue, use ./queue.ts.
|
|
4
|
+
*/
|
|
5
|
+
import type { JobQueue, JobQueueOptions, JobType, JobHandler } from "./types.js";
|
|
6
|
+
export declare function createJobQueue(opts?: JobQueueOptions): JobQueue;
|
|
7
|
+
/** Reset the auto-increment counter (for testing). */
|
|
8
|
+
export declare function _resetIdCounter(): void;
|
|
9
|
+
/**
|
|
10
|
+
* Simple single-threaded worker for in-memory queue.
|
|
11
|
+
*/
|
|
12
|
+
export interface MemoryJobWorker {
|
|
13
|
+
register(type: JobType, handler: JobHandler): void;
|
|
14
|
+
start(): void;
|
|
15
|
+
stop(): void;
|
|
16
|
+
readonly processed: number;
|
|
17
|
+
readonly isRunning: boolean;
|
|
18
|
+
}
|
|
19
|
+
export interface MemoryWorkerOptions {
|
|
20
|
+
pollInterval?: number;
|
|
21
|
+
name?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function createJobWorker(queue: JobQueue, opts?: MemoryWorkerOptions): MemoryJobWorker;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Planned Tasks Scheduler — multi-step datetime queues with
|
|
3
|
+
* job queue integration.
|
|
4
|
+
*
|
|
5
|
+
* A PlannedTask is a named sequence of steps, each with a
|
|
6
|
+
* scheduled datetime. The scheduler manages progression by
|
|
7
|
+
* enqueuing the next step as an individual job when the
|
|
8
|
+
* previous one completes. Steps are fired via setTimeout
|
|
9
|
+
* at their scheduled time, then enqueued into the job queue
|
|
10
|
+
* for async processing by workers.
|
|
11
|
+
*
|
|
12
|
+
* Features:
|
|
13
|
+
* - Multi-step tasks with per-step scheduling
|
|
14
|
+
* - Steps enqueued as individual jobs in the job queue
|
|
15
|
+
* - Automatic progression: next step enqueues when previous completes
|
|
16
|
+
* - Manual step completion callback for worker integration
|
|
17
|
+
* - Pause/resume support
|
|
18
|
+
* - Cancellation
|
|
19
|
+
* - Event system for observability
|
|
20
|
+
*/
|
|
21
|
+
export type PlannedStepStatus = "scheduled" | "waiting" | "enqueued" | "running" | "completed" | "failed" | "cancelled";
|
|
22
|
+
export type PlannedTaskStatus = "pending" | "active" | "paused" | "completed" | "failed" | "cancelled";
|
|
23
|
+
export interface PlannedStep {
|
|
24
|
+
/** Step index (0-based). */
|
|
25
|
+
index: number;
|
|
26
|
+
/** Human-readable label for this step. */
|
|
27
|
+
label: string;
|
|
28
|
+
/** When this step should fire. */
|
|
29
|
+
scheduledAt: Date;
|
|
30
|
+
/** Job type to enqueue. */
|
|
31
|
+
jobType: string;
|
|
32
|
+
/** Payload for the job. */
|
|
33
|
+
payload: Record<string, unknown>;
|
|
34
|
+
/** Current status. */
|
|
35
|
+
status: PlannedStepStatus;
|
|
36
|
+
/** Job ID once enqueued. */
|
|
37
|
+
jobId?: string;
|
|
38
|
+
/** Result from job completion. */
|
|
39
|
+
result?: unknown;
|
|
40
|
+
/** Error message if failed. */
|
|
41
|
+
error?: string;
|
|
42
|
+
/** When the step actually fired. */
|
|
43
|
+
firedAt?: Date;
|
|
44
|
+
/** When the step completed. */
|
|
45
|
+
completedAt?: Date;
|
|
46
|
+
}
|
|
47
|
+
export interface PlannedTask {
|
|
48
|
+
id: string;
|
|
49
|
+
/** Human-readable name. */
|
|
50
|
+
name: string;
|
|
51
|
+
/** Steps in execution order. */
|
|
52
|
+
steps: PlannedStep[];
|
|
53
|
+
/** Current overall status. */
|
|
54
|
+
status: PlannedTaskStatus;
|
|
55
|
+
/** Index of the current step (next to execute). */
|
|
56
|
+
currentStepIndex: number;
|
|
57
|
+
/** Chat/conversation to associate jobs with. */
|
|
58
|
+
chatId?: string;
|
|
59
|
+
/** Created timestamp. */
|
|
60
|
+
createdAt: Date;
|
|
61
|
+
/** When the task last changed state. */
|
|
62
|
+
updatedAt: Date;
|
|
63
|
+
}
|
|
64
|
+
export interface PlannedStepInput {
|
|
65
|
+
label: string;
|
|
66
|
+
scheduledAt: Date;
|
|
67
|
+
jobType: string;
|
|
68
|
+
payload?: Record<string, unknown>;
|
|
69
|
+
}
|
|
70
|
+
export interface CreatePlannedTaskInput {
|
|
71
|
+
name: string;
|
|
72
|
+
steps: PlannedStepInput[];
|
|
73
|
+
chatId?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface SchedulerJobQueue {
|
|
76
|
+
enqueue(type: string, payload: unknown, chatId?: string): {
|
|
77
|
+
id: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export type SchedulerEventType = "task_created" | "task_started" | "task_completed" | "task_failed" | "task_cancelled" | "task_paused" | "task_resumed" | "step_scheduled" | "step_enqueued" | "step_completed" | "step_failed";
|
|
81
|
+
export interface SchedulerEvent {
|
|
82
|
+
type: SchedulerEventType;
|
|
83
|
+
timestamp: Date;
|
|
84
|
+
taskId: string;
|
|
85
|
+
stepIndex?: number;
|
|
86
|
+
detail: string;
|
|
87
|
+
}
|
|
88
|
+
export type SchedulerEventListener = (event: SchedulerEvent) => void;
|
|
89
|
+
export declare function _resetTaskIds(): void;
|
|
90
|
+
export interface PlannedTaskSchedulerConfig {
|
|
91
|
+
/** Job queue to enqueue steps into. */
|
|
92
|
+
queue: SchedulerJobQueue;
|
|
93
|
+
/** Override Date.now() for testing. */
|
|
94
|
+
nowFn?: () => number;
|
|
95
|
+
}
|
|
96
|
+
export interface PlannedTaskScheduler {
|
|
97
|
+
/** Create and start a planned task. Returns the task. */
|
|
98
|
+
create(input: CreatePlannedTaskInput): PlannedTask;
|
|
99
|
+
/** Get a task by ID. */
|
|
100
|
+
get(taskId: string): PlannedTask | undefined;
|
|
101
|
+
/** List all tasks. */
|
|
102
|
+
list(): PlannedTask[];
|
|
103
|
+
/** List tasks by status. */
|
|
104
|
+
listByStatus(...statuses: PlannedTaskStatus[]): PlannedTask[];
|
|
105
|
+
/** Mark a step as completed (called by worker when job finishes).
|
|
106
|
+
* Triggers the next step if available. */
|
|
107
|
+
completeStep(taskId: string, stepIndex: number, result?: unknown): boolean;
|
|
108
|
+
/** Mark a step as failed. */
|
|
109
|
+
failStep(taskId: string, stepIndex: number, error: string): boolean;
|
|
110
|
+
/** Pause a task (prevents next step from being scheduled). */
|
|
111
|
+
pause(taskId: string): boolean;
|
|
112
|
+
/** Resume a paused task (schedules the next pending step). */
|
|
113
|
+
resume(taskId: string): boolean;
|
|
114
|
+
/** Cancel a task and all remaining steps. */
|
|
115
|
+
cancel(taskId: string): boolean;
|
|
116
|
+
on(listener: SchedulerEventListener): void;
|
|
117
|
+
off(listener: SchedulerEventListener): void;
|
|
118
|
+
/** Clean up all timers. */
|
|
119
|
+
dispose(): void;
|
|
120
|
+
}
|
|
121
|
+
export declare function createPlannedTaskScheduler(config: PlannedTaskSchedulerConfig): PlannedTaskScheduler;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JobQueue — PostgreSQL-backed async job queue wrapping the jobs table.
|
|
3
|
+
*
|
|
4
|
+
* Methods: enqueue, claim (SELECT FOR UPDATE SKIP LOCKED), complete,
|
|
5
|
+
* fail, dead. Priority ordering. Concurrency groups.
|
|
6
|
+
*/
|
|
7
|
+
import type { StorageAdapter } from "../storage/interface.js";
|
|
8
|
+
import type { AgentEvent } from "../events/types.js";
|
|
9
|
+
export type JobStatus = "queued" | "running" | "completed" | "failed" | "dead";
|
|
10
|
+
export type JobPriority = "critical" | "high" | "normal" | "low";
|
|
11
|
+
export interface Job<T = unknown> {
|
|
12
|
+
id: string;
|
|
13
|
+
type: string;
|
|
14
|
+
status: JobStatus;
|
|
15
|
+
priority: JobPriority;
|
|
16
|
+
payload: T;
|
|
17
|
+
result: unknown | null;
|
|
18
|
+
error: string | null;
|
|
19
|
+
attempts: number;
|
|
20
|
+
maxRetries: number;
|
|
21
|
+
retryBaseMs: number;
|
|
22
|
+
retryJitter: boolean;
|
|
23
|
+
concurrencyGroup: string | null;
|
|
24
|
+
createdAt: Date;
|
|
25
|
+
updatedAt: Date;
|
|
26
|
+
}
|
|
27
|
+
export interface JobOptions {
|
|
28
|
+
priority?: JobPriority;
|
|
29
|
+
maxRetries?: number;
|
|
30
|
+
retryBaseMs?: number;
|
|
31
|
+
retryJitter?: boolean;
|
|
32
|
+
concurrencyGroup?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ConcurrencyGroupConfig {
|
|
35
|
+
[group: string]: number;
|
|
36
|
+
}
|
|
37
|
+
export interface JobQueueConfig {
|
|
38
|
+
concurrencyGroups?: ConcurrencyGroupConfig;
|
|
39
|
+
}
|
|
40
|
+
export declare class JobQueue {
|
|
41
|
+
private storage;
|
|
42
|
+
private concurrency;
|
|
43
|
+
constructor(storage: StorageAdapter, config?: JobQueueConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Enqueue a new job. Returns the job ID.
|
|
46
|
+
*/
|
|
47
|
+
enqueue<T>(type: string, payload: T, opts?: JobOptions): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Enqueue and yield a job:enqueued event.
|
|
50
|
+
*/
|
|
51
|
+
enqueueWithEvents<T>(type: string, payload: T, opts?: JobOptions, sessionId?: string): AsyncGenerator<AgentEvent, string>;
|
|
52
|
+
/**
|
|
53
|
+
* Claim the next available job using SELECT FOR UPDATE SKIP LOCKED.
|
|
54
|
+
* Respects concurrency group limits.
|
|
55
|
+
*/
|
|
56
|
+
claim(workerTypes?: string[]): Promise<Job | null>;
|
|
57
|
+
/**
|
|
58
|
+
* Mark a job as completed with an optional result.
|
|
59
|
+
*/
|
|
60
|
+
complete(jobId: string, result?: unknown): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Mark a job as failed. If retries remain, re-queues with backoff.
|
|
63
|
+
*/
|
|
64
|
+
fail(jobId: string, error: string): Promise<{
|
|
65
|
+
dead: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Force a job to dead state (no more retries).
|
|
69
|
+
*/
|
|
70
|
+
dead(jobId: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a single job by ID.
|
|
73
|
+
*/
|
|
74
|
+
getJob(jobId: string): Promise<Job | null>;
|
|
75
|
+
/**
|
|
76
|
+
* List jobs by status and optional type filter.
|
|
77
|
+
*/
|
|
78
|
+
getJobsByStatus(status: JobStatus, type?: string): Promise<Job[]>;
|
|
79
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Job tool router — exposes the job queue as callable "tools"
|
|
3
|
+
* that the Telegram adapter (or any channel) can present to users.
|
|
4
|
+
*
|
|
5
|
+
* Provides a tool-like interface for:
|
|
6
|
+
* - Submitting jobs
|
|
7
|
+
* - Listing jobs
|
|
8
|
+
* - Cancelling jobs
|
|
9
|
+
* - Querying job status
|
|
10
|
+
*/
|
|
11
|
+
import type { JobQueue } from "./types.js";
|
|
12
|
+
export interface ToolRoute {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
handler: (args: Record<string, unknown>) => Promise<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface JobRouter {
|
|
18
|
+
/** All registered tool routes. */
|
|
19
|
+
readonly routes: ReadonlyArray<ToolRoute>;
|
|
20
|
+
/** Get a route by name. */
|
|
21
|
+
get(name: string): ToolRoute | undefined;
|
|
22
|
+
}
|
|
23
|
+
export declare function createJobRouter(queue: JobQueue): JobRouter;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Job } from "../job-queue.js";
|
|
2
|
+
import type { StorageAdapter } from "../storage/interface.js";
|
|
3
|
+
import { type LLMSynthesizeFn } from "../memory/synthesis.js";
|
|
4
|
+
export declare const SYNTHESIZE_JOB_TYPE = "memory.synthesize";
|
|
5
|
+
export interface SynthesizeJobPayload {
|
|
6
|
+
userId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SynthesizeJobResult {
|
|
9
|
+
patternsExtracted: number;
|
|
10
|
+
diariesProcessed: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a job handler for memory synthesis.
|
|
14
|
+
*
|
|
15
|
+
* Usage with JobQueue:
|
|
16
|
+
* ```ts
|
|
17
|
+
* const handler = createSynthesizeHandler(storage, llmFn);
|
|
18
|
+
* queue.startWorker({ [SYNTHESIZE_JOB_TYPE]: handler });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function createSynthesizeHandler(storage: StorageAdapter, llmSynthesize: LLMSynthesizeFn): (job: Job) => Promise<SynthesizeJobResult>;
|
|
22
|
+
/**
|
|
23
|
+
* Enqueue a memory synthesis job for a user.
|
|
24
|
+
* Typically called after task wrapup.
|
|
25
|
+
*/
|
|
26
|
+
export declare function enqueueSynthesisJob(enqueue: (type: string, payload: SynthesizeJobPayload) => Promise<string>, userId: string): Promise<string>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Job queue type definitions.
|
|
3
|
+
*/
|
|
4
|
+
export type JobStatus = "pending" | "running" | "done" | "failed";
|
|
5
|
+
export type JobType = "llm.complete" | "web.search" | "web.scrape" | "file.read" | "file.write" | "tool.execute" | "memory.search" | "browser.navigate" | "image.generate" | "audio.transcribe" | "notification.send";
|
|
6
|
+
/** Subset of job types safe for mobile (no heavy network / browser). */
|
|
7
|
+
export declare const LOCAL_JOB_TYPES: ReadonlySet<JobType>;
|
|
8
|
+
export interface Job<T = unknown> {
|
|
9
|
+
id: string;
|
|
10
|
+
type: JobType;
|
|
11
|
+
payload: T;
|
|
12
|
+
status: JobStatus;
|
|
13
|
+
result?: unknown;
|
|
14
|
+
error?: string;
|
|
15
|
+
createdAt: Date;
|
|
16
|
+
startedAt?: Date;
|
|
17
|
+
completedAt?: Date;
|
|
18
|
+
/** Which chat/conversation originated this job. */
|
|
19
|
+
chatId?: string;
|
|
20
|
+
}
|
|
21
|
+
export type JobHandler<T = unknown> = (payload: T) => Promise<unknown>;
|
|
22
|
+
export interface JobQueueOptions {
|
|
23
|
+
/** Maximum number of queued jobs before rejecting. Default 1000. */
|
|
24
|
+
maxSize?: number;
|
|
25
|
+
/** Restrict to only these job types (mobile edition). */
|
|
26
|
+
allowedTypes?: ReadonlySet<JobType>;
|
|
27
|
+
}
|
|
28
|
+
export interface JobQueue {
|
|
29
|
+
/** Enqueue a new job. Returns the job. */
|
|
30
|
+
enqueue<T>(type: JobType, payload: T, chatId?: string): Job<T>;
|
|
31
|
+
/** Take the next pending job (FIFO), or undefined if empty. */
|
|
32
|
+
dequeue(): Job | undefined;
|
|
33
|
+
/** Mark a job as running. */
|
|
34
|
+
markRunning(jobId: string): void;
|
|
35
|
+
/** Mark a job as completed with a result. */
|
|
36
|
+
markDone(jobId: string, result: unknown): void;
|
|
37
|
+
/** Mark a job as failed. */
|
|
38
|
+
markFailed(jobId: string, error: string): void;
|
|
39
|
+
/** Get a single job by ID. */
|
|
40
|
+
get(jobId: string): Job | undefined;
|
|
41
|
+
/** All jobs for a given chat. */
|
|
42
|
+
listByChatId(chatId: string): Job[];
|
|
43
|
+
/** All jobs matching a set of statuses. */
|
|
44
|
+
listByStatus(...statuses: JobStatus[]): Job[];
|
|
45
|
+
/** Current queue depth (pending jobs). */
|
|
46
|
+
readonly pendingCount: number;
|
|
47
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Worker pool — runs N workers against a shared job queue.
|
|
3
|
+
*
|
|
4
|
+
* Used by Pro and Voices editions (default 3 workers).
|
|
5
|
+
*/
|
|
6
|
+
import type { JobHandler, JobQueue, JobType } from "./types.js";
|
|
7
|
+
export interface WorkerPoolOptions {
|
|
8
|
+
/** Number of concurrent workers. Default 3. */
|
|
9
|
+
size?: number;
|
|
10
|
+
/** Per-worker poll interval in ms. Default 250. */
|
|
11
|
+
pollInterval?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface WorkerPool {
|
|
14
|
+
/** Register a handler on all workers. */
|
|
15
|
+
register(type: JobType, handler: JobHandler): void;
|
|
16
|
+
/** Start all workers. */
|
|
17
|
+
start(): void;
|
|
18
|
+
/** Stop all workers. */
|
|
19
|
+
stop(): void;
|
|
20
|
+
/** Total jobs processed across all workers. */
|
|
21
|
+
readonly totalProcessed: number;
|
|
22
|
+
readonly size: number;
|
|
23
|
+
readonly isRunning: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function createWorkerPool(queue: JobQueue, opts?: WorkerPoolOptions): WorkerPool;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JobWorker — poll loop that claims jobs, executes handlers, and
|
|
3
|
+
* completes or fails them with retry and event emission.
|
|
4
|
+
*
|
|
5
|
+
* Features:
|
|
6
|
+
* - Configurable poll interval (default 1s)
|
|
7
|
+
* - Concurrency group enforcement (via JobQueue.claim)
|
|
8
|
+
* - Retry with exponential backoff + jitter (via JobQueue.fail)
|
|
9
|
+
* - Yields job lifecycle events (started, completed, failed, dead)
|
|
10
|
+
*/
|
|
11
|
+
import type { AgentEvent } from "../events/types.js";
|
|
12
|
+
import { type Job, type JobQueue } from "./queue.js";
|
|
13
|
+
export type JobHandler = (job: Job) => Promise<unknown>;
|
|
14
|
+
export interface JobWorkerConfig {
|
|
15
|
+
/** Poll interval in milliseconds. Default 1000. */
|
|
16
|
+
pollIntervalMs?: number;
|
|
17
|
+
/** Max concurrent jobs to process. Default 3. */
|
|
18
|
+
concurrency?: number;
|
|
19
|
+
/** Worker name for logging. */
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class JobWorker {
|
|
23
|
+
private queue;
|
|
24
|
+
private handlers;
|
|
25
|
+
private config;
|
|
26
|
+
private running;
|
|
27
|
+
private shutdownRequested;
|
|
28
|
+
private activeJobs;
|
|
29
|
+
private events;
|
|
30
|
+
constructor(queue: JobQueue, config?: JobWorkerConfig);
|
|
31
|
+
/** Register a handler for a job type. */
|
|
32
|
+
register(type: string, handler: JobHandler): void;
|
|
33
|
+
/** Start the worker poll loop. Returns an async generator of lifecycle events. */
|
|
34
|
+
start(sessionId?: string): AsyncGenerator<AgentEvent, void>;
|
|
35
|
+
/** Stop the worker loop gracefully. */
|
|
36
|
+
stop(): void;
|
|
37
|
+
get isRunning(): boolean;
|
|
38
|
+
get activeCount(): number;
|
|
39
|
+
private processJob;
|
|
40
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { EventBus } from "../events/bus.js";
|
|
2
|
+
export type LoopState = "idle" | "running" | "paused" | "circuit-open" | "complete" | "aborted";
|
|
3
|
+
export type CircuitBreakerState = "closed" | "half-open" | "open";
|
|
4
|
+
export interface LoopIteration {
|
|
5
|
+
index: number;
|
|
6
|
+
startedAt: Date;
|
|
7
|
+
completedAt?: Date;
|
|
8
|
+
exitSignalDetected: boolean;
|
|
9
|
+
completionIndicators: string[];
|
|
10
|
+
progressMade: boolean;
|
|
11
|
+
errorPatterns: string[];
|
|
12
|
+
outputHash?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AutonomousLoopConfig {
|
|
15
|
+
/** Max iterations before forced abort */
|
|
16
|
+
maxIterations: number;
|
|
17
|
+
/** Exit signal string to detect in agent output */
|
|
18
|
+
exitSignal: string;
|
|
19
|
+
/** Minimum completion indicators required to exit */
|
|
20
|
+
completionThreshold: number;
|
|
21
|
+
/** Iterations with no progress before half-open */
|
|
22
|
+
stagnationThreshold: number;
|
|
23
|
+
/** Iterations in half-open before circuit opens */
|
|
24
|
+
halfOpenLimit: number;
|
|
25
|
+
/** Cooldown ms before auto-retry after circuit open */
|
|
26
|
+
circuitCooldownMs: number;
|
|
27
|
+
/** Max API calls per hour (0 = unlimited) */
|
|
28
|
+
rateLimitPerHour: number;
|
|
29
|
+
/** Workspace root for .loop/ state files */
|
|
30
|
+
workspaceDir: string;
|
|
31
|
+
/** Callback to run one agent iteration */
|
|
32
|
+
runIteration: (context: IterationContext) => Promise<IterationResult>;
|
|
33
|
+
/** Optional event bus for lifecycle events */
|
|
34
|
+
eventBus?: EventBus;
|
|
35
|
+
}
|
|
36
|
+
export interface IterationContext {
|
|
37
|
+
index: number;
|
|
38
|
+
sessionId: string | null;
|
|
39
|
+
previousErrors: string[];
|
|
40
|
+
backpressurePrefix: string | null;
|
|
41
|
+
}
|
|
42
|
+
export interface IterationResult {
|
|
43
|
+
output: string;
|
|
44
|
+
sessionId: string;
|
|
45
|
+
filesChanged: string[];
|
|
46
|
+
newCommits: number;
|
|
47
|
+
testResultsChanged: boolean;
|
|
48
|
+
completionIndicators: string[];
|
|
49
|
+
}
|
|
50
|
+
export declare class AutonomousLoopController {
|
|
51
|
+
private config;
|
|
52
|
+
private state;
|
|
53
|
+
private circuitState;
|
|
54
|
+
private iterations;
|
|
55
|
+
private loopGuard;
|
|
56
|
+
private sessionId;
|
|
57
|
+
private noProgressCount;
|
|
58
|
+
private callTimestamps;
|
|
59
|
+
private backpressurePrefix;
|
|
60
|
+
constructor(config: AutonomousLoopConfig);
|
|
61
|
+
/** Run the autonomous loop to completion or abort. */
|
|
62
|
+
run(): Promise<AutonomousLoopResult>;
|
|
63
|
+
/** Inject backpressure failure context for next iteration. */
|
|
64
|
+
setBackpressure(prefix: string | null): void;
|
|
65
|
+
/** Signal progress from external sources (e.g. backpressure pass). */
|
|
66
|
+
signalProgress(): void;
|
|
67
|
+
/** Abort the loop. */
|
|
68
|
+
abort(): void;
|
|
69
|
+
/** Pause the loop (requires external resume). */
|
|
70
|
+
pause(): void;
|
|
71
|
+
/** Resume from pause or circuit-open. */
|
|
72
|
+
resume(sessionId?: string): void;
|
|
73
|
+
getState(): LoopState;
|
|
74
|
+
getCircuitState(): CircuitBreakerState;
|
|
75
|
+
getIterations(): readonly LoopIteration[];
|
|
76
|
+
private executeIteration;
|
|
77
|
+
/**
|
|
78
|
+
* Dual-condition exit: BOTH exit signal AND enough completion indicators.
|
|
79
|
+
*/
|
|
80
|
+
private shouldExit;
|
|
81
|
+
private updateCircuitBreaker;
|
|
82
|
+
private enforceRateLimit;
|
|
83
|
+
private waitCooldown;
|
|
84
|
+
private lastErrors;
|
|
85
|
+
private emit;
|
|
86
|
+
}
|
|
87
|
+
export interface AutonomousLoopResult {
|
|
88
|
+
state: LoopState;
|
|
89
|
+
iterations: LoopIteration[];
|
|
90
|
+
totalIterations: number;
|
|
91
|
+
}
|