qlogicagent 0.5.2 → 0.6.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/README.md +403 -402
- package/dist/agent.js +18 -0
- package/dist/cli.js +384 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +383 -0
- package/dist/orchestration.js +34 -0
- package/dist/types/agent/agent.d.ts +43 -0
- package/dist/types/agent/constants.d.ts +47 -0
- package/dist/types/agent/tool-access.d.ts +30 -0
- package/dist/types/agent/tool-loop.d.ts +94 -0
- package/dist/types/agent/types.d.ts +238 -0
- package/dist/types/cli/main.d.ts +11 -0
- package/dist/types/cli/stdio-server.d.ts +78 -0
- package/dist/types/cli/tool-bootstrap.d.ts +40 -0
- package/dist/types/cli/transport.d.ts +40 -0
- package/dist/types/config/config.d.ts +17 -0
- package/dist/types/contracts/hooks.d.ts +175 -0
- package/dist/types/contracts/index.d.ts +9 -0
- package/dist/types/contracts/planner.d.ts +35 -0
- package/dist/types/contracts/todo.d.ts +23 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/llm/builtin-providers.d.ts +10 -0
- package/dist/types/llm/debug-transport.d.ts +12 -0
- package/dist/types/llm/index.d.ts +16 -0
- package/dist/types/llm/llm-client.d.ts +43 -0
- package/dist/types/llm/model-catalog.d.ts +53 -0
- package/dist/types/llm/provider-def.d.ts +59 -0
- package/dist/types/llm/provider-registry.d.ts +54 -0
- package/dist/types/llm/transport.d.ts +62 -0
- package/dist/types/llm/transports/anthropic-messages.d.ts +31 -0
- package/dist/types/llm/transports/openai-chat.d.ts +36 -0
- package/dist/types/orchestration/context/context-collapse.d.ts +58 -0
- package/dist/types/orchestration/context/context-compression.d.ts +301 -0
- package/dist/types/orchestration/context/reactive-compact.d.ts +73 -0
- package/dist/types/orchestration/context/turn-loop-guard.d.ts +86 -0
- package/dist/types/orchestration/error-handling/error-classification.d.ts +12 -0
- package/dist/types/orchestration/error-handling/failover-classification.d.ts +8 -0
- package/dist/types/orchestration/error-handling/failover-error.d.ts +33 -0
- package/dist/types/orchestration/error-handling/retry-loop.d.ts +69 -0
- package/dist/types/orchestration/index.d.ts +15 -0
- package/dist/types/orchestration/skill-improvement.d.ts +59 -0
- package/dist/types/orchestration/subagent/agent-registry.d.ts +46 -0
- package/dist/types/orchestration/subagent/fork-subagent.d.ts +98 -0
- package/dist/types/orchestration/subagent/task-types.d.ts +142 -0
- package/dist/types/orchestration/tool-loop/conversation-repair.d.ts +61 -0
- package/dist/types/orchestration/tool-loop/tool-choice-policy.d.ts +54 -0
- package/dist/types/orchestration/tool-loop/tool-loop-state.d.ts +50 -0
- package/dist/types/orchestration/tool-loop/tool-schema.d.ts +39 -0
- package/dist/types/runtime/execution/dream-agent.d.ts +199 -0
- package/dist/types/runtime/execution/forked-agent.d.ts +109 -0
- package/dist/types/runtime/execution/index.d.ts +6 -0
- package/dist/types/runtime/execution/progress-tracker.d.ts +78 -0
- package/dist/types/runtime/execution/remote-agent.d.ts +63 -0
- package/dist/types/runtime/execution/streaming-tool-executor.d.ts +100 -0
- package/dist/types/runtime/execution/tool-eligibility.d.ts +59 -0
- package/dist/types/runtime/execution/tool-result-storage.d.ts +87 -0
- package/dist/types/runtime/hooks/context-compression.d.ts +61 -0
- package/dist/types/runtime/hooks/hook-registry.d.ts +12 -0
- package/dist/types/runtime/hooks/index.d.ts +3 -0
- package/dist/types/runtime/hooks/memory-hooks.d.ts +49 -0
- package/dist/types/runtime/index.d.ts +5 -0
- package/dist/types/runtime/infra/agent-paths.d.ts +57 -0
- package/dist/types/runtime/infra/checkpoint-backend.d.ts +8 -0
- package/dist/types/runtime/infra/cleanup-registry.d.ts +23 -0
- package/dist/types/runtime/infra/disk-storage.d.ts +36 -0
- package/dist/types/runtime/infra/file-watcher.d.ts +72 -0
- package/dist/types/runtime/infra/index.d.ts +8 -0
- package/dist/types/runtime/infra/secure-storage.d.ts +81 -0
- package/dist/types/runtime/infra/task-runtime.d.ts +108 -0
- package/dist/types/runtime/infra/token-budget.d.ts +92 -0
- package/dist/types/runtime/infra/worktree-backend.d.ts +85 -0
- package/dist/types/runtime/prompt/environment-context.d.ts +23 -0
- package/dist/types/runtime/prompt/index.d.ts +3 -0
- package/dist/types/runtime/prompt/instruction-loader.d.ts +64 -0
- package/dist/types/runtime/prompt/system-prompt-sections.d.ts +63 -0
- package/dist/types/runtime/session/index.d.ts +2 -0
- package/dist/types/runtime/session/session-memory.d.ts +90 -0
- package/dist/types/runtime/session/session-persistence.d.ts +94 -0
- package/dist/types/runtime/session/session-state.d.ts +117 -0
- package/dist/types/skills/index.d.ts +119 -0
- package/dist/types/skills/mcp/index.d.ts +3 -0
- package/dist/types/skills/mcp/mcp-http-client.d.ts +66 -0
- package/dist/types/skills/mcp/mcp-manager.d.ts +83 -0
- package/dist/types/skills/mcp/mcp-stdio-client.d.ts +84 -0
- package/dist/types/skills/memory/memory-extractor.d.ts +64 -0
- package/dist/types/skills/memory/memory-store.d.ts +86 -0
- package/dist/types/skills/memory/memory-tool.d.ts +87 -0
- package/dist/types/skills/memory/qmemory-adapter.d.ts +42 -0
- package/dist/types/skills/permissions/bash-classifier.d.ts +30 -0
- package/dist/types/skills/permissions/classifier-cache.d.ts +51 -0
- package/dist/types/skills/permissions/denial-tracking.d.ts +42 -0
- package/dist/types/skills/permissions/hook-runner.d.ts +85 -0
- package/dist/types/skills/permissions/index.d.ts +12 -0
- package/dist/types/skills/permissions/permission-classifier.d.ts +41 -0
- package/dist/types/skills/permissions/rule-engine.d.ts +41 -0
- package/dist/types/skills/permissions/settings-watcher.d.ts +46 -0
- package/dist/types/skills/permissions/types.d.ts +113 -0
- package/dist/types/skills/plugins/index.d.ts +2 -0
- package/dist/types/skills/plugins/plugin-api.d.ts +38 -0
- package/dist/types/skills/plugins/plugin-loader.d.ts +42 -0
- package/dist/types/skills/plugins/plugin-marketplace.d.ts +61 -0
- package/dist/types/skills/portable-tool.d.ts +104 -0
- package/dist/types/skills/skill-system/skill-frontmatter.d.ts +19 -0
- package/dist/types/skills/skill-system/skill-guard.d.ts +23 -0
- package/dist/types/skills/skill-system/skill-loader.d.ts +16 -0
- package/dist/types/skills/skill-system/skill-source.d.ts +119 -0
- package/dist/types/skills/skill-system/skill-types.d.ts +199 -0
- package/dist/types/skills/think-tool.d.ts +16 -0
- package/dist/types/skills/todo-tool.d.ts +72 -0
- package/dist/types/skills/tools/agent-tool.d.ts +91 -0
- package/dist/types/skills/tools/apply-patch-tool.d.ts +29 -0
- package/dist/types/skills/tools/ask-user-tool.d.ts +80 -0
- package/dist/types/skills/tools/brief-tool.d.ts +74 -0
- package/dist/types/skills/tools/browser-tool.d.ts +114 -0
- package/dist/types/skills/tools/checkpoint-tool.d.ts +66 -0
- package/dist/types/skills/tools/config-tool.d.ts +63 -0
- package/dist/types/skills/tools/cron-tool.d.ts +116 -0
- package/dist/types/skills/tools/edit-tool.d.ts +43 -0
- package/dist/types/skills/tools/exec-tool.d.ts +97 -0
- package/dist/types/skills/tools/image-generate-tool.d.ts +62 -0
- package/dist/types/skills/tools/instructions-tool.d.ts +65 -0
- package/dist/types/skills/tools/lsp-tool.d.ts +153 -0
- package/dist/types/skills/tools/mcp-client-types.d.ts +269 -0
- package/dist/types/skills/tools/mcp-resource-tools.d.ts +14 -0
- package/dist/types/skills/tools/mcp-tool.d.ts +249 -0
- package/dist/types/skills/tools/monitor-tool.d.ts +113 -0
- package/dist/types/skills/tools/music-generate-tool.d.ts +55 -0
- package/dist/types/skills/tools/notebook-edit-tool.d.ts +15 -0
- package/dist/types/skills/tools/notify-tool.d.ts +53 -0
- package/dist/types/skills/tools/patch-tool.d.ts +45 -0
- package/dist/types/skills/tools/plan-mode-tool.d.ts +98 -0
- package/dist/types/skills/tools/read-tool.d.ts +51 -0
- package/dist/types/skills/tools/repl-tool.d.ts +70 -0
- package/dist/types/skills/tools/search-tool.d.ts +112 -0
- package/dist/types/skills/tools/send-message-tool.d.ts +51 -0
- package/dist/types/skills/tools/shell/bash-provider.d.ts +26 -0
- package/dist/types/skills/tools/shell/command-classification.d.ts +44 -0
- package/dist/types/skills/tools/shell/command-semantics.d.ts +14 -0
- package/dist/types/skills/tools/shell/destructive-command-warning.d.ts +10 -0
- package/dist/types/skills/tools/shell/exec-permissions.d.ts +52 -0
- package/dist/types/skills/tools/shell/index.d.ts +17 -0
- package/dist/types/skills/tools/shell/powershell-provider.d.ts +15 -0
- package/dist/types/skills/tools/shell/shell-command.d.ts +54 -0
- package/dist/types/skills/tools/shell/shell-exec.d.ts +33 -0
- package/dist/types/skills/tools/shell/shell-provider.d.ts +85 -0
- package/dist/types/skills/tools/shell/task-output.d.ts +45 -0
- package/dist/types/skills/tools/skill-invoke-tool.d.ts +46 -0
- package/dist/types/skills/tools/skill-list-tool.d.ts +33 -0
- package/dist/types/skills/tools/skill-manage-tool.d.ts +73 -0
- package/dist/types/skills/tools/skill-view-tool.d.ts +37 -0
- package/dist/types/skills/tools/sleep-tool.d.ts +49 -0
- package/dist/types/skills/tools/structured-output-tool.d.ts +116 -0
- package/dist/types/skills/tools/task-tool.d.ts +104 -0
- package/dist/types/skills/tools/team-tool.d.ts +89 -0
- package/dist/types/skills/tools/tool-search-tool.d.ts +51 -0
- package/dist/types/skills/tools/tts-tool.d.ts +38 -0
- package/dist/types/skills/tools/video-edit-tool.d.ts +69 -0
- package/dist/types/skills/tools/video-generate-tool.d.ts +62 -0
- package/dist/types/skills/tools/video-merge-tool.d.ts +105 -0
- package/dist/types/skills/tools/video-upscale-tool.d.ts +45 -0
- package/dist/types/skills/tools/web-fetch-tool.d.ts +78 -0
- package/dist/types/skills/tools/web-search-tool.d.ts +57 -0
- package/dist/types/skills/tools/workflow-tool.d.ts +44 -0
- package/dist/types/skills/tools/worktree-tool.d.ts +69 -0
- package/dist/types/skills/tools/write-tool.d.ts +45 -0
- package/dist/types/skills/tools.d.ts +65 -0
- package/package.json +4 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StdioServer — JSON-RPC 2.0 protocol handler.
|
|
3
|
+
*
|
|
4
|
+
* Receives JSON-RPC messages from a Transport, dispatches to handlers,
|
|
5
|
+
* writes JSON-RPC responses/notifications back through the Transport.
|
|
6
|
+
* All log output goes to stderr.
|
|
7
|
+
*
|
|
8
|
+
* Protocol: each message is a single JSON-RPC 2.0 object.
|
|
9
|
+
* The physical I/O layer is abstracted via the Transport interface.
|
|
10
|
+
*/
|
|
11
|
+
import type { Transport } from "./transport.js";
|
|
12
|
+
export interface StdioServerConfig {
|
|
13
|
+
verbose: boolean;
|
|
14
|
+
transport?: Transport;
|
|
15
|
+
}
|
|
16
|
+
export declare class StdioServer {
|
|
17
|
+
private running;
|
|
18
|
+
private activeTurn;
|
|
19
|
+
private verbose;
|
|
20
|
+
private transport;
|
|
21
|
+
private registry;
|
|
22
|
+
private agent;
|
|
23
|
+
private lastLlmConfigKey;
|
|
24
|
+
private currentSessionId;
|
|
25
|
+
private currentHooks;
|
|
26
|
+
private mcpManager;
|
|
27
|
+
private pluginLoader;
|
|
28
|
+
private permissionChecker;
|
|
29
|
+
private permissionUnregister;
|
|
30
|
+
/** Cached LLM transport for sub-agent forks (dream, session-memory) */
|
|
31
|
+
private currentTransport;
|
|
32
|
+
private currentApiKey;
|
|
33
|
+
private currentModel;
|
|
34
|
+
private sessionState;
|
|
35
|
+
private taskStore;
|
|
36
|
+
/** Session-scoped memory prefetch state (LRU dedup + byte limit). */
|
|
37
|
+
private memoryPrefetchState;
|
|
38
|
+
/** QMemory adapter (when QMEMORY_BASE_URL env is set). Used by Dream hippocampus bridge. */
|
|
39
|
+
private qmemoryAdapter;
|
|
40
|
+
private qmemoryUserId;
|
|
41
|
+
private fileWatcher;
|
|
42
|
+
constructor(config: StdioServerConfig);
|
|
43
|
+
start(): void;
|
|
44
|
+
stop(): void;
|
|
45
|
+
private handleMessage;
|
|
46
|
+
/**
|
|
47
|
+
* `initialize` — the sole handshake handler.
|
|
48
|
+
* Accepts both legacy flat params (`hostName`, `hostVersion`) and
|
|
49
|
+
* Codex-style nested params (`host.name`, `host.version`).
|
|
50
|
+
* Always returns the InitializeResult shape.
|
|
51
|
+
*/
|
|
52
|
+
private handleInitialize;
|
|
53
|
+
/**
|
|
54
|
+
* `thread.create` — create a new thread (session container).
|
|
55
|
+
* Maps threadId → sessionId for the underlying session system.
|
|
56
|
+
*/
|
|
57
|
+
private handleThreadCreate;
|
|
58
|
+
/**
|
|
59
|
+
* `thread.list` — list available threads. Delegates to session listing.
|
|
60
|
+
*/
|
|
61
|
+
private handleThreadList;
|
|
62
|
+
private handlePing;
|
|
63
|
+
private handleAbort;
|
|
64
|
+
private handleApprovalResponse;
|
|
65
|
+
private handleSessionResume;
|
|
66
|
+
private handleTurn;
|
|
67
|
+
private handleDream;
|
|
68
|
+
private resolveAgent;
|
|
69
|
+
/**
|
|
70
|
+
* Load LLM settings from ~/.qlogicagent/settings.json (sync).
|
|
71
|
+
* Returns provider/model/apiKey if found, undefined otherwise.
|
|
72
|
+
*/
|
|
73
|
+
private loadSettingsSync;
|
|
74
|
+
private sendResponse;
|
|
75
|
+
private sendNotification;
|
|
76
|
+
private writeStdout;
|
|
77
|
+
private log;
|
|
78
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PortableTool } from "../skills/portable-tool.js";
|
|
2
|
+
import { type ExecProgress } from "../skills/tools/exec-tool.js";
|
|
3
|
+
import type { AgentLogger } from "../agent/types.js";
|
|
4
|
+
export interface MediaRelayConfig {
|
|
5
|
+
imageEndpoint?: string;
|
|
6
|
+
ttsEndpoint?: string;
|
|
7
|
+
videoEndpoint?: string;
|
|
8
|
+
videoEditEndpoint?: string;
|
|
9
|
+
videoMergeEndpoint?: string;
|
|
10
|
+
videoUpscaleEndpoint?: string;
|
|
11
|
+
musicEndpoint?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Set the media relay config for multimedia tools.
|
|
15
|
+
* CC parity: tools use isEnabled() gates instead of conditional addTool().
|
|
16
|
+
* Call this before getAllBaseTools() or when config changes.
|
|
17
|
+
*/
|
|
18
|
+
export declare function setMediaConfig(config: MediaRelayConfig | undefined): void;
|
|
19
|
+
export interface BootstrapConfig {
|
|
20
|
+
workdir?: string;
|
|
21
|
+
log?: AgentLogger;
|
|
22
|
+
/** Called during foreground shell execution with incremental progress. */
|
|
23
|
+
onExecProgress?(progress: ExecProgress): void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create all locally-executable tools and install into centralized tool pool.
|
|
27
|
+
*
|
|
28
|
+
* CC parity: getAllBaseTools() returns flat array, installed via setToolPool().
|
|
29
|
+
* Tools execute IN-PROCESS (zero IPC).
|
|
30
|
+
*
|
|
31
|
+
* @alias initToolDeps — kept for backward compat with existing call sites.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getAllBaseTools(config?: BootstrapConfig): PortableTool[];
|
|
34
|
+
/** @deprecated Use getAllBaseTools() instead. */
|
|
35
|
+
export declare const initToolDeps: typeof getAllBaseTools;
|
|
36
|
+
/**
|
|
37
|
+
* Update the working directory for all local tool deps.
|
|
38
|
+
* Called when Gateway sends a new workdir via config.
|
|
39
|
+
*/
|
|
40
|
+
export declare function setBootstrapWorkdir(newWorkdir: string): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transport — abstract I/O layer for JSON-RPC message exchange.
|
|
3
|
+
*
|
|
4
|
+
* Decouples the agent protocol handler from the physical transport
|
|
5
|
+
* (stdin/stdout, WebSocket, Unix Domain Socket, etc.).
|
|
6
|
+
*
|
|
7
|
+
* Each transport reads incoming JSON-RPC messages and emits them
|
|
8
|
+
* to a registered handler; outgoing messages are sent via send().
|
|
9
|
+
*/
|
|
10
|
+
export interface Transport {
|
|
11
|
+
/** Register the message handler (called for each valid parsed message). */
|
|
12
|
+
onMessage(handler: (msg: unknown) => void): void;
|
|
13
|
+
/** Register the close handler (called when the transport closes). */
|
|
14
|
+
onClose(handler: () => void): void;
|
|
15
|
+
/** Send a JSON-RPC message (object will be serialized to JSON). */
|
|
16
|
+
send(msg: unknown): void;
|
|
17
|
+
/** Start listening for incoming messages. */
|
|
18
|
+
start(): void;
|
|
19
|
+
/** Close the transport gracefully. */
|
|
20
|
+
close(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Line-delimited JSON over stdin/stdout.
|
|
24
|
+
* Each line on stdin is a JSON message; each send() writes one JSON line to stdout.
|
|
25
|
+
* All diagnostic logging goes to stderr.
|
|
26
|
+
*/
|
|
27
|
+
export declare class StdioTransport implements Transport {
|
|
28
|
+
private messageHandler;
|
|
29
|
+
private closeHandler;
|
|
30
|
+
private verbose;
|
|
31
|
+
constructor(opts?: {
|
|
32
|
+
verbose?: boolean;
|
|
33
|
+
});
|
|
34
|
+
onMessage(handler: (msg: unknown) => void): void;
|
|
35
|
+
onClose(handler: () => void): void;
|
|
36
|
+
send(msg: unknown): void;
|
|
37
|
+
start(): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
private log;
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized CLI startup configuration.
|
|
3
|
+
*
|
|
4
|
+
* Parses and validates all configuration from CLI args and environment.
|
|
5
|
+
* Single source of truth for qlogicagent runtime config.
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentConfig {
|
|
8
|
+
/** Enable verbose logging to stderr. */
|
|
9
|
+
verbose: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Parse CLI arguments into AgentConfig.
|
|
13
|
+
*
|
|
14
|
+
* Supports:
|
|
15
|
+
* --verbose / -v Enable verbose logging
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseCliArgs(argv: string[]): AgentConfig;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook system types for the Agent Runtime.
|
|
3
|
+
*
|
|
4
|
+
* Hooks allow hosts and middleware to intercept, modify, or observe events
|
|
5
|
+
* at well-defined lifecycle points during session, turn, and tool execution.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* All supported hook points in the Agent Runtime lifecycle.
|
|
9
|
+
*/
|
|
10
|
+
export type HookPoint = "session.created" | "session.ended" | "turn.submitted" | "turn.before_inference" | "turn.after_inference" | "turn.completed" | "turn.failed" | "tool.before_invoke" | "tool.after_invoke" | "tool.invoke_failed" | "approval.requested" | "approval.responded" | "permission.denied" | "context.before_compact" | "context.after_compact" | "memory.before_recall" | "memory.after_recall" | "subagent.started" | "subagent.stopped" | "stop" | "stop.failed" | "stop.failure" | "task.created" | "task.completed" | "file.changed" | "cwd.changed" | "config.changed" | "instructions.loaded";
|
|
11
|
+
export interface HookSessionContext {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
gatewayId?: string;
|
|
14
|
+
deviceId?: string;
|
|
15
|
+
mode?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface HookTurnContext extends HookSessionContext {
|
|
18
|
+
turnId: string;
|
|
19
|
+
executionId?: string;
|
|
20
|
+
rootExecutionId?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface HookToolContext extends HookTurnContext {
|
|
23
|
+
callId: string;
|
|
24
|
+
toolName: string;
|
|
25
|
+
arguments?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export interface HookApprovalContext extends HookTurnContext {
|
|
28
|
+
approvalId: string;
|
|
29
|
+
callId?: string;
|
|
30
|
+
toolName?: string;
|
|
31
|
+
decision?: "approved" | "denied" | "expired" | "cancelled";
|
|
32
|
+
}
|
|
33
|
+
export interface HookSubagentContext extends HookTurnContext {
|
|
34
|
+
subagentId: string;
|
|
35
|
+
agentType?: string;
|
|
36
|
+
parentExecutionId?: string;
|
|
37
|
+
/** Exit reason when stopped (normal / error / timeout) */
|
|
38
|
+
reason?: string;
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface HookStopContext extends HookSessionContext {
|
|
42
|
+
reason?: string;
|
|
43
|
+
error?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface HookTaskContext extends HookSessionContext {
|
|
46
|
+
taskId: string;
|
|
47
|
+
taskType?: string;
|
|
48
|
+
label?: string;
|
|
49
|
+
error?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface HookFileChangedContext extends HookSessionContext {
|
|
52
|
+
filePath: string;
|
|
53
|
+
changeType: "created" | "modified" | "deleted";
|
|
54
|
+
}
|
|
55
|
+
export interface HookCwdChangedContext extends HookSessionContext {
|
|
56
|
+
oldCwd: string;
|
|
57
|
+
newCwd: string;
|
|
58
|
+
}
|
|
59
|
+
export interface HookConfigChangedContext extends HookSessionContext {
|
|
60
|
+
key: string;
|
|
61
|
+
oldValue?: unknown;
|
|
62
|
+
newValue?: unknown;
|
|
63
|
+
}
|
|
64
|
+
export interface HookInstructionsLoadedContext extends HookSessionContext {
|
|
65
|
+
source: string;
|
|
66
|
+
fileCount: number;
|
|
67
|
+
}
|
|
68
|
+
export interface HookContextMap {
|
|
69
|
+
"session.created": HookSessionContext;
|
|
70
|
+
"session.ended": HookSessionContext;
|
|
71
|
+
"turn.submitted": HookTurnContext & {
|
|
72
|
+
prompt?: string;
|
|
73
|
+
};
|
|
74
|
+
"turn.before_inference": HookTurnContext & {
|
|
75
|
+
model?: string;
|
|
76
|
+
messages?: unknown[];
|
|
77
|
+
};
|
|
78
|
+
"turn.after_inference": HookTurnContext & {
|
|
79
|
+
model?: string;
|
|
80
|
+
response?: unknown;
|
|
81
|
+
success?: boolean;
|
|
82
|
+
error?: string;
|
|
83
|
+
};
|
|
84
|
+
"turn.completed": HookTurnContext & {
|
|
85
|
+
outcomeId?: string;
|
|
86
|
+
};
|
|
87
|
+
"turn.failed": HookTurnContext & {
|
|
88
|
+
code?: string;
|
|
89
|
+
error?: string;
|
|
90
|
+
};
|
|
91
|
+
"tool.before_invoke": HookToolContext;
|
|
92
|
+
"tool.after_invoke": HookToolContext & {
|
|
93
|
+
result?: unknown;
|
|
94
|
+
ok: boolean;
|
|
95
|
+
};
|
|
96
|
+
"tool.invoke_failed": HookToolContext & {
|
|
97
|
+
error?: string;
|
|
98
|
+
};
|
|
99
|
+
"approval.requested": HookApprovalContext;
|
|
100
|
+
"approval.responded": HookApprovalContext;
|
|
101
|
+
"permission.denied": HookApprovalContext & {
|
|
102
|
+
reason?: string;
|
|
103
|
+
};
|
|
104
|
+
"context.before_compact": HookTurnContext & {
|
|
105
|
+
tokenCount?: number;
|
|
106
|
+
messageCount?: number;
|
|
107
|
+
};
|
|
108
|
+
"context.after_compact": HookTurnContext & {
|
|
109
|
+
tokenCount?: number;
|
|
110
|
+
removedCount?: number;
|
|
111
|
+
};
|
|
112
|
+
"memory.before_recall": HookTurnContext & {
|
|
113
|
+
query?: string;
|
|
114
|
+
recalledMemories?: Array<{
|
|
115
|
+
text: string;
|
|
116
|
+
score?: number;
|
|
117
|
+
}>;
|
|
118
|
+
};
|
|
119
|
+
"memory.after_recall": HookTurnContext & {
|
|
120
|
+
blockCount?: number;
|
|
121
|
+
};
|
|
122
|
+
"subagent.started": HookSubagentContext;
|
|
123
|
+
"subagent.stopped": HookSubagentContext;
|
|
124
|
+
"stop": HookStopContext;
|
|
125
|
+
"stop.failed": HookStopContext;
|
|
126
|
+
"stop.failure": HookStopContext & {
|
|
127
|
+
errorDetails?: string;
|
|
128
|
+
};
|
|
129
|
+
"task.created": HookTaskContext;
|
|
130
|
+
"task.completed": HookTaskContext;
|
|
131
|
+
"file.changed": HookFileChangedContext;
|
|
132
|
+
"cwd.changed": HookCwdChangedContext;
|
|
133
|
+
"config.changed": HookConfigChangedContext;
|
|
134
|
+
"instructions.loaded": HookInstructionsLoadedContext;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Result of a hook handler invocation.
|
|
138
|
+
*
|
|
139
|
+
* - `continue`: proceed normally (optionally with modified context)
|
|
140
|
+
* - `abort`: stop execution (for "before" hooks only)
|
|
141
|
+
* - `skip`: skip this step but continue the overall flow
|
|
142
|
+
*/
|
|
143
|
+
export interface HookResult<T = unknown> {
|
|
144
|
+
action: "continue" | "abort" | "skip" | "prevent";
|
|
145
|
+
/** Modified context to pass downstream (only for "continue") */
|
|
146
|
+
context?: T;
|
|
147
|
+
/** Reason for abort/skip/prevent (for logging) */
|
|
148
|
+
reason?: string;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A hook handler function.
|
|
152
|
+
*
|
|
153
|
+
* @param point - The hook point being invoked
|
|
154
|
+
* @param context - Event-specific context data
|
|
155
|
+
* @returns A HookResult or void (treated as "continue")
|
|
156
|
+
*/
|
|
157
|
+
export type HookHandler<P extends HookPoint = HookPoint> = (point: P, context: HookContextMap[P]) => HookResult<HookContextMap[P]> | void | Promise<HookResult<HookContextMap[P]> | void>;
|
|
158
|
+
/**
|
|
159
|
+
* Hook registration entry.
|
|
160
|
+
*/
|
|
161
|
+
export interface HookRegistration<P extends HookPoint = HookPoint> {
|
|
162
|
+
point: P;
|
|
163
|
+
handler: HookHandler<P>;
|
|
164
|
+
/** Priority (lower = earlier). Default: 100 */
|
|
165
|
+
priority?: number;
|
|
166
|
+
/** Optional label for debugging */
|
|
167
|
+
label?: string;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Interface for a hook registry that manages hook handlers.
|
|
171
|
+
*/
|
|
172
|
+
export interface HookRegistry {
|
|
173
|
+
register<P extends HookPoint>(registration: HookRegistration<P>): () => void;
|
|
174
|
+
invoke<P extends HookPoint>(point: P, context: HookContextMap[P]): Promise<HookResult<HookContextMap[P]>>;
|
|
175
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal contracts — types internalized from qlogicagent-runtime-contracts.
|
|
3
|
+
*
|
|
4
|
+
* These types are only consumed within qlogicagent itself (agent runtime + hub).
|
|
5
|
+
* They were removed from the public npm package to slim the cross-repo API surface.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./planner.js";
|
|
8
|
+
export * from "./todo.js";
|
|
9
|
+
export * from "./hooks.js";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const TASK_STEP_STATUS_VALUES: readonly ["pending", "in-progress", "completed", "skipped"];
|
|
2
|
+
export type TaskStepStatus = (typeof TASK_STEP_STATUS_VALUES)[number];
|
|
3
|
+
export declare const TASK_PLAN_STATUS_VALUES: readonly ["active", "completed", "abandoned"];
|
|
4
|
+
export type TaskPlanStatus = (typeof TASK_PLAN_STATUS_VALUES)[number];
|
|
5
|
+
export interface TaskStep {
|
|
6
|
+
index: number;
|
|
7
|
+
description: string;
|
|
8
|
+
status: TaskStepStatus;
|
|
9
|
+
result?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface TaskPlan {
|
|
12
|
+
id: string;
|
|
13
|
+
sessionId: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
goal: string;
|
|
16
|
+
steps: TaskStep[];
|
|
17
|
+
status: TaskPlanStatus;
|
|
18
|
+
createdAt: string;
|
|
19
|
+
updatedAt: string;
|
|
20
|
+
constraints?: string[];
|
|
21
|
+
keyIdentifiers?: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface TaskPlanContextSnippet {
|
|
24
|
+
text: string;
|
|
25
|
+
tokens: number;
|
|
26
|
+
planId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface TaskPlanProgressSnapshot {
|
|
29
|
+
goal: string;
|
|
30
|
+
steps: Array<{
|
|
31
|
+
description: string;
|
|
32
|
+
status: TaskStepStatus | string;
|
|
33
|
+
result?: string;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const TODO_ITEM_STATUS_VALUES: readonly ["not-started", "in-progress", "completed"];
|
|
2
|
+
export type TodoItemStatus = (typeof TODO_ITEM_STATUS_VALUES)[number];
|
|
3
|
+
export interface TodoItem {
|
|
4
|
+
id: number;
|
|
5
|
+
title: string;
|
|
6
|
+
status: TodoItemStatus;
|
|
7
|
+
/** Detailed task description (V2). */
|
|
8
|
+
description?: string;
|
|
9
|
+
/** Owner agent/subagent identifier for per-agent isolation (V2). */
|
|
10
|
+
owner?: string;
|
|
11
|
+
/** IDs of tasks that must complete before this one can start (V2). */
|
|
12
|
+
blockedBy?: number[];
|
|
13
|
+
/** IDs of tasks this one blocks from starting (V2). */
|
|
14
|
+
blocks?: number[];
|
|
15
|
+
}
|
|
16
|
+
export interface TodoListSummary {
|
|
17
|
+
total: number;
|
|
18
|
+
completed: number;
|
|
19
|
+
inProgress: number;
|
|
20
|
+
notStarted: number;
|
|
21
|
+
blocked: number;
|
|
22
|
+
}
|
|
23
|
+
export declare function summarizeTodoList(items: readonly TodoItem[]): TodoListSummary;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* qlogicagent — Public API surface.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports core types and constructors for programmatic embedding.
|
|
5
|
+
*/
|
|
6
|
+
export { Agent } from "./agent/agent.js";
|
|
7
|
+
export type { AgentLogger, ChatMessage, ToolDefinition, ToolInvoker, TurnConfig, TurnEvent, TurnRequest, HookRegistry, } from "./agent/types.js";
|
|
8
|
+
export { parseCliArgs } from "./config/config.js";
|
|
9
|
+
export type { AgentConfig } from "./config/config.js";
|
|
10
|
+
export type { Transport } from "./cli/transport.js";
|
|
11
|
+
export { StdioTransport } from "./cli/transport.js";
|
|
12
|
+
export { StdioServer, type StdioServerConfig } from "./cli/stdio-server.js";
|
|
13
|
+
export { ProviderRegistry, createLLMClient, autoDetectProvider, } from "./llm/index.js";
|
|
14
|
+
export type { LLMTransport, LLMRequest, LLMChunk } from "./llm/index.js";
|
|
15
|
+
export { createHookRegistry } from "./runtime/hooks/hook-registry.js";
|
|
16
|
+
export { buildSkillInstruction, } from "./orchestration/index.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builtin provider definitions — hardcoded fallback list (~30 providers).
|
|
3
|
+
*
|
|
4
|
+
* This is Layer 1 (lowest priority) of the three-layer merge strategy.
|
|
5
|
+
* Used when remote model catalog is unavailable.
|
|
6
|
+
*
|
|
7
|
+
* Aligned with Hermes hermes_cli/models.py hardcoded fallback.
|
|
8
|
+
*/
|
|
9
|
+
import type { ProviderDef } from "./provider-def.js";
|
|
10
|
+
export declare const BUILTIN_PROVIDERS: ProviderDef[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LLMTransport } from "./transport.js";
|
|
2
|
+
/**
|
|
3
|
+
* Check whether debug transport should be enabled.
|
|
4
|
+
*/
|
|
5
|
+
export declare function isDebugTransportEnabled(): boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Create a DebugTransport decorator that wraps a base LLMTransport,
|
|
8
|
+
* logging request metadata + timing + usage to JSONL.
|
|
9
|
+
*
|
|
10
|
+
* CC parity: createDumpPromptsFetch — but vendor-agnostic via transport abstraction.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDebugTransport(base: LLMTransport, sessionId: string): LLMTransport;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Provider layer — public API surface.
|
|
3
|
+
*
|
|
4
|
+
* Provides: ProviderDef + LLMTransport + ProviderRegistry + LLMClient factory
|
|
5
|
+
*/
|
|
6
|
+
export type { ProviderDef, ModelInfo, TransportType, AuthType } from "./provider-def.js";
|
|
7
|
+
export type { LLMTransport, LLMRequest, LLMChunk, AccumulatedToolCall, } from "./transport.js";
|
|
8
|
+
export { accumulateToolCalls } from "./transport.js";
|
|
9
|
+
export { ProviderRegistry } from "./provider-registry.js";
|
|
10
|
+
export { BUILTIN_PROVIDERS } from "./builtin-providers.js";
|
|
11
|
+
export { ModelCatalog } from "./model-catalog.js";
|
|
12
|
+
export type { LLMClientConfig, LLMClient } from "./llm-client.js";
|
|
13
|
+
export { createLLMClient, autoDetectProvider } from "./llm-client.js";
|
|
14
|
+
export { OpenAIChatTransport } from "./transports/openai-chat.js";
|
|
15
|
+
export { AnthropicMessagesTransport } from "./transports/anthropic-messages.js";
|
|
16
|
+
export { isDebugTransportEnabled, createDebugTransport } from "./debug-transport.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Client factory — resolves ProviderDef → creates LLMTransport instance.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the old createAdminInferProxyClient() call chain.
|
|
5
|
+
* User API key + ProviderDef → direct provider connection.
|
|
6
|
+
*/
|
|
7
|
+
import type { ProviderDef } from "./provider-def.js";
|
|
8
|
+
import type { LLMTransport } from "./transport.js";
|
|
9
|
+
import { ProviderRegistry } from "./provider-registry.js";
|
|
10
|
+
export interface LLMClientConfig {
|
|
11
|
+
/** Provider id, e.g. "deepseek" */
|
|
12
|
+
provider: string;
|
|
13
|
+
/** Model id, e.g. "deepseek-chat" */
|
|
14
|
+
model: string;
|
|
15
|
+
/** User API key */
|
|
16
|
+
apiKey: string;
|
|
17
|
+
/** Optional base URL override */
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface LLMClient {
|
|
21
|
+
transport: LLMTransport;
|
|
22
|
+
apiKey: string;
|
|
23
|
+
resolvedModel: string;
|
|
24
|
+
providerDef: ProviderDef;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Create an LLM client from config + registry.
|
|
28
|
+
*
|
|
29
|
+
* 1. Look up provider in registry
|
|
30
|
+
* 2. Apply baseUrl override if provided
|
|
31
|
+
* 3. Instantiate the correct transport
|
|
32
|
+
*/
|
|
33
|
+
export declare function createLLMClient(config: LLMClientConfig, registry: ProviderRegistry): LLMClient;
|
|
34
|
+
/**
|
|
35
|
+
* Auto-detect provider from API key environment variables.
|
|
36
|
+
* Scans registry for providers whose env vars are set.
|
|
37
|
+
* Returns the first match.
|
|
38
|
+
*/
|
|
39
|
+
export declare function autoDetectProvider(registry: ProviderRegistry): {
|
|
40
|
+
providerId: string;
|
|
41
|
+
apiKey: string;
|
|
42
|
+
defaultModel: string;
|
|
43
|
+
} | undefined;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModelCatalog — remote model directory with disk cache + fallback.
|
|
3
|
+
*
|
|
4
|
+
* Fetches model metadata from models.dev (open community catalog, 4000+ models).
|
|
5
|
+
* Aligned with Hermes agent/models_dev.py caching strategy.
|
|
6
|
+
*
|
|
7
|
+
* Three-layer fallback:
|
|
8
|
+
* 1. In-memory cache (process-level, TTL check against disk mtime)
|
|
9
|
+
* 2. Disk cache (~/.qlogicagent/cache/model_catalog.json)
|
|
10
|
+
* 3. Remote fetch (https://models.dev/api.json)
|
|
11
|
+
* 4. Stale disk cache (if remote fails)
|
|
12
|
+
* 5. Empty (caller falls back to builtin-providers.ts hardcoded)
|
|
13
|
+
*
|
|
14
|
+
* Non-blocking: first startup without cache returns empty immediately,
|
|
15
|
+
* triggers background async fetch. Agent uses builtin providers until
|
|
16
|
+
* catalog arrives.
|
|
17
|
+
*/
|
|
18
|
+
import type { ModelInfo } from "./provider-def.js";
|
|
19
|
+
export declare class ModelCatalog {
|
|
20
|
+
private cache;
|
|
21
|
+
private cacheDir;
|
|
22
|
+
private cacheFile;
|
|
23
|
+
private ttlMs;
|
|
24
|
+
private fetching;
|
|
25
|
+
private lastFetchAttempt;
|
|
26
|
+
constructor(opts?: {
|
|
27
|
+
cacheDir?: string;
|
|
28
|
+
ttlMs?: number;
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* Get models for a provider. Non-blocking: returns whatever is cached.
|
|
32
|
+
* Triggers background refresh if stale.
|
|
33
|
+
*/
|
|
34
|
+
getModels(providerId: string): ModelInfo[];
|
|
35
|
+
/**
|
|
36
|
+
* Get a single model by provider + model id.
|
|
37
|
+
*/
|
|
38
|
+
getModel(providerId: string, modelId: string): ModelInfo | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* List all known provider ids from the catalog.
|
|
41
|
+
*/
|
|
42
|
+
listProviderIds(): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Force refresh from remote. Returns true if successful.
|
|
45
|
+
*/
|
|
46
|
+
refreshCatalog(): Promise<boolean>;
|
|
47
|
+
private ensureLoaded;
|
|
48
|
+
private isStale;
|
|
49
|
+
private loadFromDisk;
|
|
50
|
+
private saveToDisk;
|
|
51
|
+
private backgroundFetch;
|
|
52
|
+
private fetchRemote;
|
|
53
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ProviderDef — defines how to connect to an LLM provider.
|
|
3
|
+
*
|
|
4
|
+
* Aligned with Hermes `ProviderDef` dataclass pattern:
|
|
5
|
+
* id + name + transport type + baseUrl + auth config + model list
|
|
6
|
+
*
|
|
7
|
+
* Three-layer merge strategy (Layer 3 > Layer 2 > Layer 1):
|
|
8
|
+
* Layer 1: builtin-providers.ts hardcoded (fallback)
|
|
9
|
+
* Layer 2: model-catalog.ts remote (models.dev)
|
|
10
|
+
* Layer 3: user config (from agent.turn.config)
|
|
11
|
+
*/
|
|
12
|
+
export type TransportType = "openai-chat" | "anthropic-messages";
|
|
13
|
+
export type AuthType = "bearer" | "x-api-key" | "none";
|
|
14
|
+
export interface ProviderDef {
|
|
15
|
+
/** Unique provider id, e.g. "deepseek", "openai", "anthropic" */
|
|
16
|
+
id: string;
|
|
17
|
+
/** Display name, e.g. "DeepSeek" */
|
|
18
|
+
name: string;
|
|
19
|
+
/** Which transport to use for LLM calls */
|
|
20
|
+
transport: TransportType;
|
|
21
|
+
/** API base URL, e.g. "https://api.deepseek.com" */
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
/** Env var names for API key (priority order) */
|
|
24
|
+
apiKeyEnvVars: string[];
|
|
25
|
+
/** Auth header style */
|
|
26
|
+
authType: AuthType;
|
|
27
|
+
/** Is an aggregator (OpenRouter, 硅基) — model ids may have prefix */
|
|
28
|
+
isAggregator: boolean;
|
|
29
|
+
/** Recommended default model */
|
|
30
|
+
defaultModel?: string;
|
|
31
|
+
/** Known models for this provider */
|
|
32
|
+
models?: ModelInfo[];
|
|
33
|
+
/** Extra headers to send with every request (e.g. aggregator-specific) */
|
|
34
|
+
extraHeaders?: Record<string, string>;
|
|
35
|
+
/** Whether this provider supports stream_options (default true for openai-chat) */
|
|
36
|
+
supportsStreamOptions?: boolean;
|
|
37
|
+
/** Whether to omit temperature when it equals 0 (some providers reject 0) */
|
|
38
|
+
omitZeroTemperature?: boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface ModelInfo {
|
|
41
|
+
/** Model id, e.g. "deepseek-chat" */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Display name, e.g. "DeepSeek Chat V3" */
|
|
44
|
+
name: string;
|
|
45
|
+
/** Context window in tokens */
|
|
46
|
+
contextWindow: number;
|
|
47
|
+
/** Max output tokens */
|
|
48
|
+
maxOutput: number;
|
|
49
|
+
/** Supports function/tool calling */
|
|
50
|
+
toolCall: boolean;
|
|
51
|
+
/** Has reasoning/thinking mode */
|
|
52
|
+
reasoning: boolean;
|
|
53
|
+
/** Supports vision (image input) */
|
|
54
|
+
vision: boolean;
|
|
55
|
+
/** Cost per 1M input tokens (USD) */
|
|
56
|
+
costInput?: number;
|
|
57
|
+
/** Cost per 1M output tokens (USD) */
|
|
58
|
+
costOutput?: number;
|
|
59
|
+
}
|