the-citadel 0.12.7

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 (38) hide show
  1. package/.citadel/instructions/tag-planning.md +14 -0
  2. package/README.md +132 -0
  3. package/dist/agents/evaluator.d.ts +8 -0
  4. package/dist/agents/index.d.ts +2 -0
  5. package/dist/agents/worker.d.ts +10 -0
  6. package/dist/bridge/components/Dashboard.d.ts +1 -0
  7. package/dist/bridge/components/MoleculeTree.d.ts +1 -0
  8. package/dist/bridge/index.d.ts +1 -0
  9. package/dist/cli.d.ts +10 -0
  10. package/dist/cli.js +97093 -0
  11. package/dist/config/index.d.ts +6 -0
  12. package/dist/config/schema.d.ts +89 -0
  13. package/dist/core/agent.d.ts +59 -0
  14. package/dist/core/formula.d.ts +63 -0
  15. package/dist/core/gitignore.d.ts +1 -0
  16. package/dist/core/hooks.d.ts +19 -0
  17. package/dist/core/instruction.d.ts +103 -0
  18. package/dist/core/llm.d.ts +3 -0
  19. package/dist/core/logger.d.ts +31 -0
  20. package/dist/core/mcp-resource-provider.d.ts +14 -0
  21. package/dist/core/memory.d.ts +8 -0
  22. package/dist/core/pearls.d.ts +77 -0
  23. package/dist/core/pool.d.ts +31 -0
  24. package/dist/core/queue.d.ts +99 -0
  25. package/dist/core/registry.d.ts +3 -0
  26. package/dist/core/schema-utils.d.ts +11 -0
  27. package/dist/index.d.ts +9 -0
  28. package/dist/index.js +94741 -0
  29. package/dist/services/conductor.d.ts +21 -0
  30. package/dist/services/mcp.d.ts +17 -0
  31. package/dist/services/piper.d.ts +21 -0
  32. package/dist/services/project-context.d.ts +37 -0
  33. package/dist/services/workflow-engine.d.ts +17 -0
  34. package/dist/tools/evaluator.d.ts +25 -0
  35. package/dist/tools/inspection.d.ts +18 -0
  36. package/dist/tools/shell.d.ts +18 -0
  37. package/dist/tools/worker.d.ts +46 -0
  38. package/package.json +64 -0
@@ -0,0 +1,6 @@
1
+ import { type CitadelConfig, type CitadelConfigInput } from "./schema";
2
+ export declare const CONFIG_KEY = "config_cache";
3
+ export declare function loadConfig(): Promise<CitadelConfig>;
4
+ export declare function setConfig(config: CitadelConfigInput): void;
5
+ export declare function resetConfig(): void;
6
+ export declare function getConfig(): CitadelConfig;
@@ -0,0 +1,89 @@
1
+ import { z } from "zod";
2
+ export declare const ConfigSchema: z.ZodObject<{
3
+ env: z.ZodDefault<z.ZodEnum<{
4
+ development: "development";
5
+ production: "production";
6
+ }>>;
7
+ providers: z.ZodObject<{
8
+ openai: z.ZodOptional<z.ZodObject<{
9
+ apiKey: z.ZodOptional<z.ZodString>;
10
+ }, z.core.$strip>>;
11
+ anthropic: z.ZodOptional<z.ZodObject<{
12
+ apiKey: z.ZodOptional<z.ZodString>;
13
+ }, z.core.$strip>>;
14
+ ollama: z.ZodOptional<z.ZodObject<{
15
+ baseURL: z.ZodDefault<z.ZodString>;
16
+ apiKey: z.ZodDefault<z.ZodString>;
17
+ }, z.core.$strip>>;
18
+ }, z.core.$strip>;
19
+ agents: z.ZodRecord<z.ZodString, z.ZodObject<{
20
+ provider: z.ZodEnum<{
21
+ openai: "openai";
22
+ anthropic: "anthropic";
23
+ ollama: "ollama";
24
+ }>;
25
+ model: z.ZodString;
26
+ mcpTools: z.ZodOptional<z.ZodArray<z.ZodString>>;
27
+ mcpResources: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
28
+ }, z.core.$strip>>;
29
+ mcpServers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
30
+ command: z.ZodOptional<z.ZodString>;
31
+ args: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
+ env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
33
+ url: z.ZodOptional<z.ZodString>;
34
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
35
+ }, z.core.$strip>>>;
36
+ worker: z.ZodObject<{
37
+ timeout: z.ZodDefault<z.ZodNumber>;
38
+ maxRetries: z.ZodDefault<z.ZodNumber>;
39
+ costLimit: z.ZodDefault<z.ZodNumber>;
40
+ min_workers: z.ZodDefault<z.ZodNumber>;
41
+ max_workers: z.ZodDefault<z.ZodNumber>;
42
+ load_factor: z.ZodDefault<z.ZodNumber>;
43
+ }, z.core.$strip>;
44
+ gatekeeper: z.ZodDefault<z.ZodObject<{
45
+ min_workers: z.ZodDefault<z.ZodNumber>;
46
+ max_workers: z.ZodDefault<z.ZodNumber>;
47
+ load_factor: z.ZodDefault<z.ZodNumber>;
48
+ auto_close_epics: z.ZodDefault<z.ZodBoolean>;
49
+ }, z.core.$strip>>;
50
+ pearls: z.ZodObject<{
51
+ path: z.ZodDefault<z.ZodString>;
52
+ binary: z.ZodDefault<z.ZodString>;
53
+ autoSync: z.ZodDefault<z.ZodBoolean>;
54
+ }, z.core.$strip>;
55
+ bridge: z.ZodDefault<z.ZodObject<{
56
+ maxLogs: z.ZodDefault<z.ZodNumber>;
57
+ }, z.core.$strip>>;
58
+ context: z.ZodDefault<z.ZodObject<{
59
+ maxHistoryMessages: z.ZodDefault<z.ZodNumber>;
60
+ maxToolResponseSize: z.ZodDefault<z.ZodNumber>;
61
+ maxInspectContextSize: z.ZodDefault<z.ZodNumber>;
62
+ offloadThresholds: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodNumber>>;
63
+ maxMessageSize: z.ZodDefault<z.ZodNumber>;
64
+ }, z.core.$strip>>;
65
+ hooks: z.ZodOptional<z.ZodObject<{
66
+ onPearlStart: z.ZodOptional<z.ZodAny>;
67
+ onPearlDone: z.ZodOptional<z.ZodAny>;
68
+ onMoleculeStart: z.ZodOptional<z.ZodAny>;
69
+ onMoleculeDone: z.ZodOptional<z.ZodAny>;
70
+ }, z.core.$strip>>;
71
+ logging: z.ZodOptional<z.ZodObject<{
72
+ path: z.ZodOptional<z.ZodString>;
73
+ level: z.ZodDefault<z.ZodEnum<{
74
+ debug: "debug";
75
+ info: "info";
76
+ warn: "warn";
77
+ error: "error";
78
+ }>>;
79
+ fileEnabled: z.ZodDefault<z.ZodBoolean>;
80
+ rotation: z.ZodDefault<z.ZodEnum<{
81
+ daily: "daily";
82
+ none: "none";
83
+ }>>;
84
+ }, z.core.$strip>>;
85
+ }, z.core.$strip>;
86
+ export type CitadelConfig = z.infer<typeof ConfigSchema>;
87
+ export type CitadelConfigInput = z.input<typeof ConfigSchema>;
88
+ export type AgentRole = string;
89
+ export declare function defineConfig(config: CitadelConfigInput): CitadelConfigInput;
@@ -0,0 +1,59 @@
1
+ import { generateText, type LanguageModel, type ModelMessage, type Tool } from "ai";
2
+ import { z } from "zod";
3
+ import type { AgentRole } from "../config/schema";
4
+ import { type PearlsClient } from "./pearls";
5
+ export interface AgentContext {
6
+ pearlId?: string;
7
+ [key: string]: unknown;
8
+ }
9
+ export declare class AgentStepLimitReachedError extends Error {
10
+ constructor(message: string);
11
+ }
12
+ export interface ToolContext extends AgentContext {
13
+ toolCallId: string;
14
+ messages: ModelMessage[];
15
+ pearlsClient?: PearlsClient;
16
+ }
17
+ export declare abstract class CoreAgent {
18
+ protected role: AgentRole;
19
+ protected model: LanguageModel;
20
+ protected tools: Record<string, Tool>;
21
+ protected dynamicTools: Record<string, Tool>;
22
+ protected schemas: Record<string, z.ZodTypeAny>;
23
+ protected requiresExplicitCompletion: boolean;
24
+ protected pearlsClient?: PearlsClient;
25
+ constructor(role: AgentRole, model?: LanguageModel, pearlsClient?: PearlsClient);
26
+ /**
27
+ * Override this to provide tools dynamically based on context.
28
+ * These will be merged with registered static tools (like MCP tools).
29
+ */
30
+ protected getDynamicTools(_context?: AgentContext): Promise<Record<string, Tool>>;
31
+ private mcpLoaded;
32
+ protected executeGenerateText(messages: ModelMessage[]): Promise<Awaited<ReturnType<typeof generateText>>>;
33
+ protected registerBuiltinTools(): Promise<void>;
34
+ protected registerTool<T extends z.ZodTypeAny, R>(name: string, description: string, schema: T, execute: (args: z.infer<T>, toolContext?: ToolContext) => Promise<R>): void;
35
+ /**
36
+ * Registers an AI SDK Tool directly, ensuring its schema is discoverable.
37
+ */
38
+ protected registerSdkTool(name: string, sdkTool: Tool): void;
39
+ /**
40
+ * Override this to provide the system prompt.
41
+ */
42
+ protected getSystemPrompt(defaultPrompt: string): string;
43
+ /**
44
+ * Check permissions based on AGENTS.md frontmatter.
45
+ * NOTE: It could be useful to return the actual path that was blocked, this
46
+ * would give agent more context to fix the issue.
47
+ */
48
+ protected checkPermissions(toolName: string, args: Record<string, unknown>): Promise<{
49
+ allowed: boolean;
50
+ error?: string;
51
+ }>;
52
+ /**
53
+ * The Unified Loop:
54
+ * - Loads Project Context (AGENTS.md)
55
+ * - Runs a manual loop interacting with the LLM
56
+ * - Handles tool execution manually for better control/logging
57
+ */
58
+ run(prompt: string, context?: AgentContext): Promise<string>;
59
+ }
@@ -0,0 +1,63 @@
1
+ import { z } from "zod";
2
+ export declare const FormulaVariableSchema: z.ZodObject<{
3
+ description: z.ZodString;
4
+ required: z.ZodDefault<z.ZodBoolean>;
5
+ default: z.ZodOptional<z.ZodString>;
6
+ }, z.core.$strip>;
7
+ export declare const FormulaStepSchema: z.ZodObject<{
8
+ id: z.ZodString;
9
+ title: z.ZodString;
10
+ description: z.ZodString;
11
+ needs: z.ZodOptional<z.ZodArray<z.ZodString>>;
12
+ if: z.ZodOptional<z.ZodString>;
13
+ for: z.ZodOptional<z.ZodObject<{
14
+ items: z.ZodString;
15
+ as: z.ZodString;
16
+ }, z.core.$strip>>;
17
+ on_failure: z.ZodOptional<z.ZodString>;
18
+ output_schema: z.ZodOptional<z.ZodAny>;
19
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
20
+ labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
21
+ agent: z.ZodOptional<z.ZodString>;
22
+ }, z.core.$strip>;
23
+ export declare const FormulaSchema: z.ZodObject<{
24
+ formula: z.ZodString;
25
+ description: z.ZodString;
26
+ vars: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
27
+ description: z.ZodString;
28
+ required: z.ZodDefault<z.ZodBoolean>;
29
+ default: z.ZodOptional<z.ZodString>;
30
+ }, z.core.$strip>>>;
31
+ prompts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
32
+ mcp_resources: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
33
+ context_files: z.ZodOptional<z.ZodArray<z.ZodString>>;
34
+ steps: z.ZodArray<z.ZodObject<{
35
+ id: z.ZodString;
36
+ title: z.ZodString;
37
+ description: z.ZodString;
38
+ needs: z.ZodOptional<z.ZodArray<z.ZodString>>;
39
+ if: z.ZodOptional<z.ZodString>;
40
+ for: z.ZodOptional<z.ZodObject<{
41
+ items: z.ZodString;
42
+ as: z.ZodString;
43
+ }, z.core.$strip>>;
44
+ on_failure: z.ZodOptional<z.ZodString>;
45
+ output_schema: z.ZodOptional<z.ZodAny>;
46
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
47
+ labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
48
+ agent: z.ZodOptional<z.ZodString>;
49
+ }, z.core.$strip>>;
50
+ }, z.core.$strip>;
51
+ export type Formula = z.infer<typeof FormulaSchema>;
52
+ export type FormulaStep = z.infer<typeof FormulaStepSchema>;
53
+ export declare class FormulaRegistry {
54
+ private formulas;
55
+ private basePath;
56
+ constructor(basePath?: string);
57
+ loadAll(): Promise<void>;
58
+ private loadFormula;
59
+ get(name: string): Formula | undefined;
60
+ list(): Formula[];
61
+ }
62
+ export declare function getFormulaRegistry(basePath?: string): FormulaRegistry;
63
+ export declare function setFormulaRegistry(registry: FormulaRegistry): void;
@@ -0,0 +1 @@
1
+ export declare function getIgnoredPatterns(baseDir?: string): string[];
@@ -0,0 +1,19 @@
1
+ import { type Ticket, type WorkQueue } from "./queue";
2
+ export type TicketHandler = (ticket: Ticket) => Promise<unknown>;
3
+ export declare class Hook {
4
+ private agentId;
5
+ private queue;
6
+ private handler;
7
+ private pollingInterval;
8
+ private isRunning;
9
+ private heartbeatTimer;
10
+ private role;
11
+ private maxRetries;
12
+ constructor(agentId: string, role: string, handler: TicketHandler, queue?: WorkQueue, maxRetries?: number);
13
+ start(): void;
14
+ stop(): void;
15
+ private loop;
16
+ private cycle;
17
+ private startHeartbeat;
18
+ private stopHeartbeat;
19
+ }
@@ -0,0 +1,103 @@
1
+ import type { AgentRole } from "../config/schema";
2
+ import { type PearlsClient } from "./pearls";
3
+ import { type FormulaRegistry } from "./formula";
4
+ import type { MCPService } from "../services/mcp";
5
+ export interface InstructionContext {
6
+ role: AgentRole;
7
+ pearlId?: string;
8
+ labels?: string[];
9
+ context?: Record<string, unknown>;
10
+ }
11
+ export interface InstructionProvider {
12
+ name: string;
13
+ priority: number;
14
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
15
+ }
16
+ /**
17
+ * Loads project-specific top-level protocol from .citadel/instructions/protocol.md
18
+ * This has the lowest priority value (5), meaning it appears at the very top.
19
+ */
20
+ export declare class CustomProtocolProvider implements InstructionProvider {
21
+ name: string;
22
+ priority: number;
23
+ getInstructions(_ctx: InstructionContext): Promise<string | null>;
24
+ }
25
+ /**
26
+ * Loads AGENTS.md from project root.
27
+ */
28
+ export declare class GlobalProvider implements InstructionProvider {
29
+ name: string;
30
+ priority: number;
31
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
32
+ }
33
+ /**
34
+ * Hardcoded defaults for Citadel roles.
35
+ * Provides a universal System Integrity block for all roles,
36
+ * and a Worker base protocol for worker-type roles.
37
+ */
38
+ export declare class BuiltinProvider implements InstructionProvider {
39
+ name: string;
40
+ priority: number;
41
+ private static readonly WORKER_TYPE_ROLES;
42
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
43
+ }
44
+ /**
45
+ * Loads role-specific instructions from .citadel/instructions/role-${role}.md
46
+ */
47
+ export declare class RoleProvider implements InstructionProvider {
48
+ name: string;
49
+ priority: number;
50
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
51
+ }
52
+ /**
53
+ * Loads instructions from Formula if the pearl is part of a formula.
54
+ */
55
+ export declare class FormulaProvider implements InstructionProvider {
56
+ name: string;
57
+ priority: number;
58
+ private pearls;
59
+ private formulaRegistry;
60
+ constructor(pearls?: PearlsClient, formulaRegistry?: FormulaRegistry);
61
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
62
+ }
63
+ /**
64
+ * Loads instructions based on tags (labels) like .citadel/instructions/tag-git.md
65
+ */
66
+ export declare class TagProvider implements InstructionProvider {
67
+ name: string;
68
+ priority: number;
69
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
70
+ }
71
+ /**
72
+ * Loads status of blocking sub-tasks for the current pearl.
73
+ */
74
+ export declare class SubTaskProvider implements InstructionProvider {
75
+ name: string;
76
+ priority: number;
77
+ private pearls;
78
+ constructor(pearls?: PearlsClient);
79
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
80
+ }
81
+ /**
82
+ * Loads custom instructions from pearl context.
83
+ */
84
+ export declare class ContextProvider implements InstructionProvider {
85
+ name: string;
86
+ priority: number;
87
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
88
+ }
89
+ /**
90
+ * Enforcement of Completion Protocol.
91
+ * This is the HIGHEST priority (priority=100) and appears at the bottom.
92
+ */
93
+ export declare class EnforcementProvider implements InstructionProvider {
94
+ name: string;
95
+ priority: number;
96
+ getInstructions(_ctx: InstructionContext): Promise<string | null>;
97
+ }
98
+ export declare class InstructionService {
99
+ private providers;
100
+ constructor(pearls?: PearlsClient, mcpService?: MCPService, formulaRegistry?: FormulaRegistry);
101
+ buildPrompt(ctx: InstructionContext, basePrompt: string): Promise<string>;
102
+ }
103
+ export declare function getInstructionService(pearls?: PearlsClient, mcpService?: MCPService, formulaRegistry?: FormulaRegistry): InstructionService;
@@ -0,0 +1,3 @@
1
+ import type { LanguageModel } from "ai";
2
+ import type { AgentRole } from "../config/schema";
3
+ export declare function getAgentModel(role: AgentRole): LanguageModel;
@@ -0,0 +1,31 @@
1
+ import { EventEmitter } from "node:events";
2
+ export type LogLevel = "debug" | "info" | "warn" | "error";
3
+ export interface LogEntry {
4
+ timestamp: string;
5
+ level: LogLevel;
6
+ message: string;
7
+ meta?: Record<string, unknown>;
8
+ }
9
+ export interface LoggerOptions {
10
+ path?: string;
11
+ level?: LogLevel;
12
+ fileEnabled?: boolean;
13
+ consoleEnabled?: boolean;
14
+ rotation?: "daily" | "none";
15
+ }
16
+ export declare class CitadelLogger extends EventEmitter {
17
+ private consoleEnabled;
18
+ private fileEnabled;
19
+ private filePath?;
20
+ private rotation;
21
+ private lastRotationCheck;
22
+ setOptions(options: LoggerOptions): void;
23
+ setConsoleEnabled(enabled: boolean): void;
24
+ debug(message: string, meta?: Record<string, unknown>): void;
25
+ info(message: string, meta?: Record<string, unknown>): void;
26
+ warn(message: string, meta?: Record<string, unknown>): void;
27
+ error(message: string, error?: any, meta?: Record<string, unknown>): void;
28
+ private log;
29
+ private ensureRotation;
30
+ }
31
+ export declare const logger: CitadelLogger;
@@ -0,0 +1,14 @@
1
+ import { type PearlsClient } from "./pearls";
2
+ import { type FormulaRegistry } from "./formula";
3
+ import type { InstructionContext, InstructionProvider } from "./instruction";
4
+ import { type MCPService } from "../services/mcp";
5
+ export declare class MCPResourceProvider implements InstructionProvider {
6
+ name: string;
7
+ priority: number;
8
+ private explicitMcpService?;
9
+ private pearls;
10
+ private formulaRegistry;
11
+ constructor(mcpService?: MCPService, pearls?: PearlsClient, formulaRegistry?: FormulaRegistry);
12
+ getInstructions(ctx: InstructionContext): Promise<string | null>;
13
+ private mergeResources;
14
+ }
@@ -0,0 +1,8 @@
1
+ export declare class ToolResultMemory {
2
+ private baseDir;
3
+ constructor(baseDir?: string);
4
+ private ensureDir;
5
+ store(pearlId: string, content: string): Promise<string>;
6
+ get(pearlId: string, id: string): Promise<string | null>;
7
+ }
8
+ export declare function getToolResultMemory(): ToolResultMemory;
@@ -0,0 +1,77 @@
1
+ import { z } from "zod";
2
+ export declare const PearlStatusSchema: z.ZodEnum<{
3
+ open: "open";
4
+ in_progress: "in_progress";
5
+ verify: "verify";
6
+ done: "done";
7
+ }>;
8
+ export type PearlStatus = z.infer<typeof PearlStatusSchema>;
9
+ export declare const PearlPrioritySchema: z.ZodPipe<z.ZodAny, z.ZodTransform<0 | 2 | 4 | 3 | 1, any>>;
10
+ export type PearlPriority = z.infer<typeof PearlPrioritySchema>;
11
+ export declare const PearlSchema: z.ZodObject<{
12
+ id: z.ZodString;
13
+ title: z.ZodString;
14
+ status: z.ZodEnum<{
15
+ open: "open";
16
+ in_progress: "in_progress";
17
+ verify: "verify";
18
+ done: "done";
19
+ }>;
20
+ priority: z.ZodPipe<z.ZodAny, z.ZodTransform<0 | 2 | 4 | 3 | 1, any>>;
21
+ assignee: z.ZodOptional<z.ZodString>;
22
+ labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
23
+ blockers: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
+ acceptance_test: z.ZodOptional<z.ZodString>;
25
+ parent: z.ZodOptional<z.ZodString>;
26
+ type: z.ZodOptional<z.ZodString>;
27
+ description: z.ZodOptional<z.ZodString>;
28
+ context: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
29
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
30
+ output: z.ZodOptional<z.ZodUnknown>;
31
+ created_at: z.ZodString;
32
+ updated_at: z.ZodString;
33
+ }, z.core.$strip>;
34
+ export type Pearl = z.infer<typeof PearlSchema>;
35
+ export interface CreateOptions {
36
+ priority?: 0 | 1 | 2 | 3 | 4;
37
+ assignee?: string;
38
+ blockers?: string[];
39
+ acceptance_test?: string;
40
+ description?: string;
41
+ parent?: string;
42
+ type?: string;
43
+ context?: Record<string, unknown>;
44
+ labels?: string[];
45
+ }
46
+ export declare class PearlsClient {
47
+ private basePath;
48
+ private binary;
49
+ constructor(basePath?: string, binary?: string);
50
+ runCommand(args: string[]): Promise<string>;
51
+ init(): Promise<void>;
52
+ protected execute(command: string, args: string[], cwd: string): Promise<{
53
+ stdout: string;
54
+ stderr: string;
55
+ }>;
56
+ sync(): Promise<void>;
57
+ doctor(): Promise<boolean>;
58
+ private parseRaw;
59
+ private parseRawList;
60
+ private mapToDomain;
61
+ list(status?: PearlStatus): Promise<Pearl[]>;
62
+ ready(): Promise<Pearl[]>;
63
+ getAll(): Promise<Pearl[]>;
64
+ get(id: string): Promise<Pearl>;
65
+ create(title: string, options?: CreateOptions): Promise<Pearl>;
66
+ update(id: string, changes: Partial<Pearl>): Promise<Pearl>;
67
+ private validateTransition;
68
+ addDependency(childId: string, parentId: string): Promise<void>;
69
+ addComment(id: string, comment: string): Promise<string>;
70
+ listComments(id: string): Promise<Array<{
71
+ author: string;
72
+ content: string;
73
+ created_at: string;
74
+ }>>;
75
+ }
76
+ export declare function getPearls(basePath?: string): PearlsClient;
77
+ export declare function setPearlsInstance(pearls: PearlsClient): void;
@@ -0,0 +1,31 @@
1
+ import { EventEmitter } from "node:events";
2
+ interface PoolItem {
3
+ start?: () => Promise<void> | void;
4
+ stop?: () => void;
5
+ }
6
+ export declare class WorkerPool extends EventEmitter {
7
+ private workers;
8
+ private busyWorkers;
9
+ private role;
10
+ size: number;
11
+ private factory;
12
+ constructor(role: string, factory: (id: string) => PoolItem, size?: number);
13
+ private initialize;
14
+ /**
15
+ * Dynamic Resizing
16
+ */
17
+ resize(targetSize: number): Promise<void>;
18
+ private addWorker;
19
+ private removeWorker;
20
+ acquire(): Promise<PoolItem>;
21
+ release(worker: PoolItem): void;
22
+ start(): void;
23
+ stop(): void;
24
+ get status(): {
25
+ total: number;
26
+ busy: number;
27
+ idle: number;
28
+ };
29
+ }
30
+ export declare function getGlobalSingleton<T>(key: symbol, factory: () => T): T;
31
+ export {};
@@ -0,0 +1,99 @@
1
+ import { z } from "zod";
2
+ export declare const TicketStatusSchema: z.ZodEnum<{
3
+ completed: "completed";
4
+ failed: "failed";
5
+ queued: "queued";
6
+ processing: "processing";
7
+ }>;
8
+ export type TicketStatus = z.infer<typeof TicketStatusSchema>;
9
+ export declare const TicketSchema: z.ZodObject<{
10
+ id: z.ZodString;
11
+ pearl_id: z.ZodString;
12
+ status: z.ZodEnum<{
13
+ completed: "completed";
14
+ failed: "failed";
15
+ queued: "queued";
16
+ processing: "processing";
17
+ }>;
18
+ priority: z.ZodNumber;
19
+ target_role: z.ZodEnum<{
20
+ worker: "worker";
21
+ gatekeeper: "gatekeeper";
22
+ }>;
23
+ assignee_id: z.ZodNullable<z.ZodString>;
24
+ created_at: z.ZodNumber;
25
+ started_at: z.ZodNullable<z.ZodNumber>;
26
+ completed_at: z.ZodNullable<z.ZodNumber>;
27
+ heartbeat_at: z.ZodNullable<z.ZodNumber>;
28
+ retry_count: z.ZodNumber;
29
+ next_attempt_at: z.ZodNullable<z.ZodNumber>;
30
+ output: z.ZodOptional<z.ZodUnknown>;
31
+ }, z.core.$strip>;
32
+ export type Ticket = z.infer<typeof TicketSchema>;
33
+ export declare class WorkQueue {
34
+ private db;
35
+ constructor(dbPath?: string);
36
+ private init;
37
+ enqueue(pearlId: string, priority?: number, targetRole?: string): void;
38
+ /**
39
+ * Claim a ticket for processing (The Hook)
40
+ */
41
+ claim(assigneeId: string, role: string): Ticket | null;
42
+ /**
43
+ * Signal that the worker is still alive
44
+ */
45
+ heartbeat(ticketId: string): void;
46
+ /**
47
+ * Mark ticket as complete with optional output
48
+ */
49
+ /**
50
+ * Mark ticket as complete with optional output
51
+ */
52
+ complete(ticketId: string, output?: unknown): void;
53
+ /**
54
+ * Get output of a completed ticket by Pearl ID
55
+ */
56
+ getOutput(pearlId: string): unknown;
57
+ /**
58
+ * Release a failed ticket back to queue (or fail permanently)
59
+ */
60
+ fail(ticketId: string, permanent?: boolean, maxRetries?: number): void;
61
+ /**
62
+ * Find stalled tickets and release them
63
+ */
64
+ releaseStalled(timeoutMs: number): number;
65
+ /**
66
+ * Check if a pearl has an active ticket (queued or processing)
67
+ */
68
+ getActiveTicket(pearlId: string): Ticket | null;
69
+ /**
70
+ * Get the latest ticket for a pearl (regardless of status)
71
+ */
72
+ getLatestTicket(pearlId: string): Ticket | null;
73
+ /**
74
+ * Reset tickets for a specific pearl
75
+ */
76
+ resetPearl(pearlId: string): void;
77
+ /**
78
+ * Get tickets currently being processed
79
+ */
80
+ listActive(timeoutMs?: number): Ticket[];
81
+ /**
82
+ * Get tickets by status
83
+ */
84
+ getTicketsByStatus(status: TicketStatus): Ticket[];
85
+ /**
86
+ * Get all tickets, optionally filtered by status
87
+ */
88
+ getAllTickets(status?: TicketStatus): Ticket[];
89
+ /**
90
+ * Get count of pending (queued) tickets for a specific role
91
+ */
92
+ getPendingCount(role: string): number;
93
+ /**
94
+ * Close the database connection
95
+ */
96
+ close(): void;
97
+ }
98
+ export declare function getQueue(): WorkQueue;
99
+ export declare function setQueueInstance(queue: WorkQueue): void;
@@ -0,0 +1,3 @@
1
+ export declare function getGlobalSingleton<T>(key: string, factory: () => T): T;
2
+ export declare function setGlobalSingleton<T>(key: string, value: T): void;
3
+ export declare function clearGlobalSingleton(key: string): void;
@@ -0,0 +1,11 @@
1
+ import { z } from "zod";
2
+ interface JsonSchema {
3
+ type?: string;
4
+ description?: string;
5
+ properties?: Record<string, unknown>;
6
+ required?: string[];
7
+ items?: unknown;
8
+ additionalProperties?: boolean | unknown;
9
+ }
10
+ export declare function jsonSchemaToZod(schema: JsonSchema | string): z.ZodTypeAny;
11
+ export {};
@@ -0,0 +1,9 @@
1
+ export { loadConfig, setConfig, getConfig } from "./config";
2
+ export { getQueue } from "./core/queue";
3
+ export { Conductor } from "./services/conductor";
4
+ export { getWorkflowEngine } from "./services/workflow-engine";
5
+ export { getFormulaRegistry, type Formula } from "./core/formula";
6
+ export { startBridge } from "./bridge/index";
7
+ export { type Pearl, getPearls } from "./core/pearls";
8
+ export { logger, type LogEntry, type LogLevel } from "./core/logger";
9
+ export { getMCPService, type MCPService, type MCPTool } from "./services/mcp";