qlogicagent 1.2.1 → 2.0.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 +27 -0
- package/dist/agent.js +14 -14
- package/dist/cli.js +217 -203
- package/dist/index.js +216 -203
- package/dist/orchestration.js +10 -10
- package/dist/qlogicagent.cmd +2 -0
- package/dist/types/agent/constants.d.ts +12 -2
- package/dist/types/agent/types.d.ts +3 -0
- package/dist/types/cli/main.d.ts +5 -1
- package/dist/types/cli/stdio-server.d.ts +58 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/llm/index.d.ts +1 -1
- package/dist/types/llm/transports/volcengine-media.d.ts +2 -1
- package/dist/types/orchestration/tool-loop/tool-schema.d.ts +1 -0
- package/dist/types/protocol/notifications.d.ts +1 -1
- package/dist/types/runtime/infra/acp-protocol-adapter.d.ts +72 -18
- package/dist/types/runtime/infra/acp-types.d.ts +30 -17
- package/dist/types/runtime/infra/agent-paths.d.ts +1 -1
- package/dist/types/runtime/infra/index.d.ts +2 -2
- package/dist/types/runtime/prompt/environment-context.d.ts +9 -1
- package/dist/types/runtime/prompt/index.d.ts +2 -1
- package/dist/types/runtime/prompt/task-domain.d.ts +82 -0
- package/dist/types/skills/index.d.ts +1 -1
- package/dist/types/skills/tools/media-cancel-tool.d.ts +30 -0
- package/dist/types/skills/tools/shell/index.d.ts +1 -0
- package/dist/types/skills/tools/shell/subprocess-env.d.ts +6 -0
- package/dist/types/skills/tools/three-d-generate-tool.d.ts +1 -0
- package/dist/types/skills/tools.d.ts +15 -0
- package/dist/types/transport/acp-event-emitter.d.ts +21 -0
- package/dist/types/transport/acp-server.d.ts +130 -0
- package/dist/types/transport/index.d.ts +6 -0
- package/package.json +1 -1
|
@@ -136,39 +136,52 @@ export interface AgentConfigStoreData {
|
|
|
136
136
|
/** ACP initialize result (from agent's response). */
|
|
137
137
|
export interface AcpInitializeResult {
|
|
138
138
|
protocolVersion: number;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
/** Standard ACP agentCapabilities (official SDK field). */
|
|
140
|
+
agentCapabilities: {
|
|
141
|
+
loadSession?: boolean;
|
|
142
|
+
mcpCapabilities?: {
|
|
143
|
+
http?: boolean;
|
|
144
|
+
sse?: boolean;
|
|
145
|
+
};
|
|
146
|
+
promptCapabilities?: {
|
|
147
|
+
audio?: boolean;
|
|
148
|
+
embeddedContext?: boolean;
|
|
149
|
+
image?: boolean;
|
|
150
|
+
};
|
|
151
|
+
sessionCapabilities?: Record<string, unknown>;
|
|
143
152
|
[key: string]: unknown;
|
|
144
153
|
};
|
|
145
|
-
|
|
154
|
+
/** Standard ACP agentInfo (official SDK field). */
|
|
155
|
+
agentInfo?: {
|
|
146
156
|
name: string;
|
|
147
157
|
version?: string;
|
|
148
158
|
};
|
|
159
|
+
authMethods?: Array<{
|
|
160
|
+
type: string;
|
|
161
|
+
[key: string]: unknown;
|
|
162
|
+
}>;
|
|
149
163
|
}
|
|
150
|
-
/** ACP session/new result. */
|
|
164
|
+
/** ACP session/new result (official: { sessionId, configOptions?, models?, modes? }). */
|
|
151
165
|
export interface AcpSessionResult {
|
|
152
|
-
|
|
166
|
+
sessionId: string;
|
|
153
167
|
}
|
|
154
|
-
/** ACP
|
|
155
|
-
export
|
|
156
|
-
|
|
157
|
-
text?: string;
|
|
158
|
-
data?: string;
|
|
159
|
-
mimeType?: string;
|
|
160
|
-
}
|
|
161
|
-
/** ACP prompt response. */
|
|
168
|
+
/** Standard ACP stopReason. */
|
|
169
|
+
export type AcpStopReason = "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled";
|
|
170
|
+
/** ACP prompt response (official: { stopReason, usage?, userMessageId? }). */
|
|
162
171
|
export interface AcpPromptResponse {
|
|
163
|
-
|
|
172
|
+
stopReason: AcpStopReason;
|
|
164
173
|
usage?: AcpPromptResponseUsage;
|
|
174
|
+
userMessageId?: string;
|
|
175
|
+
/** Aggregated text from session/update notifications (populated by adapter). */
|
|
176
|
+
text?: string;
|
|
165
177
|
}
|
|
166
|
-
/** ACP per-turn usage stats. */
|
|
178
|
+
/** ACP per-turn usage stats (aligned with SDK zUsage). */
|
|
167
179
|
export interface AcpPromptResponseUsage {
|
|
168
180
|
inputTokens?: number;
|
|
169
181
|
outputTokens?: number;
|
|
170
182
|
totalTokens?: number;
|
|
171
183
|
cachedReadTokens?: number;
|
|
184
|
+
cachedWriteTokens?: number;
|
|
172
185
|
thoughtTokens?: number;
|
|
173
186
|
}
|
|
174
187
|
/** ACP usage_update notification payload (session-level). */
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
/** Dot-directory name used for both user-level and project-level storage. */
|
|
9
9
|
export declare const AGENT_DOT_DIR = ".qlogicagent";
|
|
10
|
-
/** `~/.qlogicagent/` */
|
|
10
|
+
/** `~/.qlogicagent/` (or QLOGICAGENT_HOME override) */
|
|
11
11
|
export declare function getUserAgentHome(): string;
|
|
12
12
|
/** `~/.qlogicagent/sessions/` */
|
|
13
13
|
export declare function getUserSessionsRoot(): string;
|
|
@@ -7,12 +7,12 @@ export { createWorktreeBackend } from "./worktree-backend.js";
|
|
|
7
7
|
export { registerCleanup, runCleanupFunctions } from "./cleanup-registry.js";
|
|
8
8
|
export { atomicWriteFile, readJsonFile, writeJsonFile, loadPersistedMemory, savePersistedMemory, getMemoryFilePath, type PersistedMemory, } from "./disk-storage.js";
|
|
9
9
|
export { AcpDetector, ACP_BACKENDS } from "./acp-detector.js";
|
|
10
|
-
export { AcpProtocolAdapter, type TranslatedNotification } from "./acp-protocol-adapter.js";
|
|
10
|
+
export { AcpProtocolAdapter, type TranslatedNotification, type AcpHostRequestHandler } from "./acp-protocol-adapter.js";
|
|
11
11
|
export { AcpUsageTracker, type AccumulatedUsage } from "./acp-usage-tracker.js";
|
|
12
12
|
export { AgentConfigStore } from "./agent-config-store.js";
|
|
13
13
|
export { ModelIdTranslator } from "./model-id-translator.js";
|
|
14
14
|
export { SkillInjector } from "./skill-injector.js";
|
|
15
15
|
export { ACP_FAULT_LEVEL, type AcpFaultLevel, buildLlmEnvForTeammate } from "./agent-process.js";
|
|
16
16
|
export { McpBridge, MCP_BRIDGE_TOOLS } from "./mcp-bridge.js";
|
|
17
|
-
export type { AgentCategory, AgentProtocol, AgentStatus, AcpBackendConfig, AgentDescriptor, ExternalAgentDescriptor, CustomAgentDef, AgentConfig, AgentConfigStoreData, AgentCapabilities, AcpInitializeResult, AcpSessionResult, AcpPromptResponse,
|
|
17
|
+
export type { AgentCategory, AgentProtocol, AgentStatus, AcpBackendConfig, AgentDescriptor, ExternalAgentDescriptor, CustomAgentDef, AgentConfig, AgentConfigStoreData, AgentCapabilities, AcpInitializeResult, AcpSessionResult, AcpPromptResponse, AcpPromptResponseUsage, AcpStopReason, AcpUsageUpdatePayload, McpServerConfig, AgentsScanParams, AgentsConfigParams, AgentsSetConfigParams, AgentsGetConfigParams, AgentsRemoveConfigParams, AgentsSetGatewayParams, SoloState, SoloAgentState, SoloAgentResult, SoloEvaluation, SoloStatus, SoloStartParams, SoloIdParams, SoloSelectParams, ProductPhase, ProductInstanceState, ProductTaskStatus, ProductBudget, ProductInstanceDef, ProductTaskDef, ProductCreateParams, ProductIdParams, ProductInstanceStatus, ProductTaskState, ProductStatus, ProductSummary, AgentsGetGatewayResult, AgentsListConfiguredItem, AgentsProcessInfo, AgentsKillParams, AgentsGetLogParams, AgentsGetLogResult, AgentsTestConnectionParams, AgentsTestConnectionResult, SoloDeleteParams, ProductDeleteParams, AgentSource, } from "./acp-types.js";
|
|
18
18
|
export type { AgentsStatusNotification, AgentsErrorNotification, SoloProgressNotification, SoloEvaluationNotification, SoloAgentDeltaNotification, ProductTaskStartedNotification, ProductTaskCompletedNotification, ProductTaskFailedNotification, ProductCheckpointedNotification, ProductBudgetWarningNotification, ProductCompletedNotification, } from "../../protocol/notifications.js";
|
|
@@ -15,15 +15,23 @@
|
|
|
15
15
|
* - Available package managers
|
|
16
16
|
*/
|
|
17
17
|
import { type SystemPromptSection } from "./system-prompt-sections.js";
|
|
18
|
+
import type { TaskDomain } from "./task-domain.js";
|
|
18
19
|
export type ShellType = "bash" | "powershell" | "zsh" | "cmd" | "fish" | "unknown";
|
|
19
20
|
/**
|
|
20
21
|
* Create a system prompt section that provides environment context.
|
|
21
22
|
* Memoized — computed once per session (environment doesn't change mid-session).
|
|
22
23
|
*/
|
|
23
24
|
export declare function createEnvironmentContextSection(cwdOverride?: string): SystemPromptSection;
|
|
25
|
+
/**
|
|
26
|
+
* Create the task guidance system prompt section.
|
|
27
|
+
* Domain-aware: selects appropriate guidance based on detected or overridden task domain.
|
|
28
|
+
*
|
|
29
|
+
* @param domain - Task domain from auto-detection or host override.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createTaskGuidanceSection(domain?: TaskDomain): SystemPromptSection;
|
|
24
32
|
/**
|
|
25
33
|
* Create a system prompt section that provides tool usage guidance.
|
|
26
|
-
* CC parity: matches claude-code's
|
|
34
|
+
* CC parity: matches claude-code's getUsingYourToolsSection().
|
|
27
35
|
* Tells the LLM when to use specialized tools vs. primitives.
|
|
28
36
|
*/
|
|
29
37
|
export declare function createToolGuidanceSection(): SystemPromptSection;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { assembleSystemPrompt, clearSystemPromptSections, systemPromptSection, type SystemPromptSection, } from "./system-prompt-sections.js";
|
|
2
2
|
export { getInstructions, buildInstructionsPrompt, resetInstructionCache, } from "./instruction-loader.js";
|
|
3
|
-
export { createEnvironmentContextSection } from "./environment-context.js";
|
|
3
|
+
export { createEnvironmentContextSection, createTaskGuidanceSection, createToolGuidanceSection } from "./environment-context.js";
|
|
4
|
+
export { detectTaskDomain, resolveTaskDomain, loadProjectTaskDomain, persistTaskDomain, shouldPersistDomain, type TaskDomain, type DomainResolutionContext } from "./task-domain.js";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Task Domain Detection — three-tier domain resolution for system prompt routing.
|
|
3
|
+
*
|
|
4
|
+
* qlogicagent handles coding, office, AND creative tasks.
|
|
5
|
+
* A coding-only system prompt hurts non-coding performance.
|
|
6
|
+
*
|
|
7
|
+
* Resolution priority (highest → lowest):
|
|
8
|
+
* 1. Project file: `.qlogicagent/settings.yaml` → `taskDomain: coding`
|
|
9
|
+
* Persisted, user-editable, checked into repo. Strongest signal.
|
|
10
|
+
* 2. Host override: `config.taskDomain` in thread.turn params.
|
|
11
|
+
* Set by Electron/Hub per-request.
|
|
12
|
+
* 3. Session sticky: once a domain is established in a session,
|
|
13
|
+
* keep it unless a new turn has a STRONG signal for a different domain.
|
|
14
|
+
* 4. Auto-detect: regex keyword matching on the current user message.
|
|
15
|
+
* Falls back to "general" if ambiguous.
|
|
16
|
+
*
|
|
17
|
+
* The `resolveTaskDomain()` function implements this full chain.
|
|
18
|
+
* The `detectTaskDomain()` function is the low-level keyword matcher (tier 4).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Task domain determines which system prompt sections are injected.
|
|
22
|
+
*
|
|
23
|
+
* - "coding" — software engineering: bug fixes, refactoring, code gen, etc.
|
|
24
|
+
* - "office" — data analysis, reports, documents, spreadsheets, emails
|
|
25
|
+
* - "creative" — writing, copywriting, marketing, storytelling, brainstorming
|
|
26
|
+
* - "general" — undetectable or mixed domain, uses universal guidance
|
|
27
|
+
*/
|
|
28
|
+
export type TaskDomain = "coding" | "office" | "creative" | "general";
|
|
29
|
+
/**
|
|
30
|
+
* Load task domain from project-level `.qlogicagent/settings.yaml`.
|
|
31
|
+
* Returns undefined if file doesn't exist or doesn't contain a valid domain.
|
|
32
|
+
*
|
|
33
|
+
* Uses sync I/O — called once per turn, file is tiny (<1KB).
|
|
34
|
+
* Simple key:value parser (no YAML dependency needed for this).
|
|
35
|
+
*/
|
|
36
|
+
export declare function loadProjectTaskDomain(cwd: string): TaskDomain | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Detect task domain from user message text (tier 4 — lowest priority).
|
|
39
|
+
* Uses keyword matching — fast, no LLM call.
|
|
40
|
+
*/
|
|
41
|
+
export declare function detectTaskDomain(userText: string): TaskDomain;
|
|
42
|
+
export interface DomainResolutionContext {
|
|
43
|
+
/** Current working directory (for project file lookup). */
|
|
44
|
+
cwd: string;
|
|
45
|
+
/** Host-provided override from config.taskDomain. */
|
|
46
|
+
hostOverride?: TaskDomain;
|
|
47
|
+
/** Previous session domain (for stickiness). */
|
|
48
|
+
sessionDomain?: TaskDomain;
|
|
49
|
+
/** Current turn's user message text. */
|
|
50
|
+
userText: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Full domain resolution chain — implements the four-tier priority:
|
|
54
|
+
* 1. Project file (.qlogicagent/settings.yaml or INSTRUCTIONS.md frontmatter)
|
|
55
|
+
* 2. Host override (config.taskDomain)
|
|
56
|
+
* 3. Session stickiness (keep previous domain unless strong signal)
|
|
57
|
+
* 4. Auto-detect from keywords
|
|
58
|
+
*
|
|
59
|
+
* Returns both the resolved domain and a "source" tag for debugging.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolveTaskDomain(ctx: DomainResolutionContext): {
|
|
62
|
+
domain: TaskDomain;
|
|
63
|
+
source: "project-file" | "host-override" | "session-sticky" | "auto-detect";
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Persist the detected task domain to `.qlogicagent/settings.yaml`.
|
|
67
|
+
*
|
|
68
|
+
* This runs once per workspace — subsequent sessions skip auto-detect
|
|
69
|
+
* and hit Tier 1 (project file) directly.
|
|
70
|
+
*
|
|
71
|
+
* Conditions for writing:
|
|
72
|
+
* - `domain` is NOT "general" (ambiguous → don't commit)
|
|
73
|
+
* - No existing `settings.yaml` with a `taskDomain` line
|
|
74
|
+
* - The auto-detect score was above the confidence threshold
|
|
75
|
+
*
|
|
76
|
+
* The written file is user-editable and meant to be checked into the repo.
|
|
77
|
+
*/
|
|
78
|
+
export declare function persistTaskDomain(cwd: string, domain: TaskDomain): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Check if auto-detect scored high enough to justify persisting.
|
|
81
|
+
*/
|
|
82
|
+
export declare function shouldPersistDomain(userText: string, domain: TaskDomain): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type { PortableTool, PortableToolResult, ToolContentBlock, } from "./portable-tool.js";
|
|
2
|
-
export { setToolPool, addTool, addTools, removeTool, findTool, hasTool, getToolNames, getToolCount, executeTool, getToolManifest, getTools, AGENT_DISALLOWED_TOOLS, CUSTOM_AGENT_DISALLOWED_TOOLS, filterToolsForAgent, } from "./tools.js";
|
|
2
|
+
export { setToolPool, addTool, addTools, removeTool, findTool, hasTool, getToolNames, getToolCount, executeTool, getToolManifest, getTools, activateTool, isToolActivated, clearActivatedTools, AGENT_DISALLOWED_TOOLS, CUSTOM_AGENT_DISALLOWED_TOOLS, filterToolsForAgent, } from "./tools.js";
|
|
3
3
|
export { MEMORY_TOOL_NAME, MEMORY_TOOL_MAX_CONTENT_LENGTH, MEMORY_TOOL_ACTIONS, MEMORY_TOOL_SCHEMA, MEMORY_TOOL_DESCRIPTION, MEMORY_TOOL_LABEL, isMemoryContentSafe, executeMemoryTool, } from "./memory/memory-tool.js";
|
|
4
4
|
export type { MemoryToolAction, MemoryToolParams, MemoryToolResult, MemoryToolExecutorDeps, MediaPreferencesSummary, } from "./memory/memory-tool.js";
|
|
5
5
|
export { MemoryStore, MEMORY_ENTRY_DELIMITER, DEFAULT_MEMORY_CHAR_LIMIT, DEFAULT_USER_CHAR_LIMIT, } from "./memory/memory-store.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PortableTool } from "../portable-tool.js";
|
|
2
|
+
export declare const MEDIA_CANCEL_TOOL_NAME: "media_cancel";
|
|
3
|
+
export interface MediaCancelToolParams {
|
|
4
|
+
task_id: string;
|
|
5
|
+
provider?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const MEDIA_CANCEL_TOOL_SCHEMA: {
|
|
8
|
+
readonly type: "object";
|
|
9
|
+
readonly properties: {
|
|
10
|
+
readonly task_id: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
readonly description: "The task ID of the media generation to cancel (returned in previous generation results).";
|
|
13
|
+
};
|
|
14
|
+
readonly provider: {
|
|
15
|
+
readonly type: "string";
|
|
16
|
+
readonly description: "Provider name (e.g. 'doubao', 'zhipu'). If omitted, auto-detects from task context.";
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
readonly required: readonly ["task_id"];
|
|
20
|
+
};
|
|
21
|
+
export interface MediaCancelToolDeps {
|
|
22
|
+
cancelTask(params: {
|
|
23
|
+
taskId: string;
|
|
24
|
+
provider?: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
ok: boolean;
|
|
27
|
+
message: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
export declare function createMediaCancelTool(deps: MediaCancelToolDeps): PortableTool<MediaCancelToolParams>;
|
|
@@ -13,5 +13,6 @@ export { TaskOutput, generateTaskId, getTaskOutputDir, setTaskOutputDir, getTask
|
|
|
13
13
|
export type { ProgressCallback } from "./task-output.js";
|
|
14
14
|
export type { ExecResult, ShellCommand } from "./shell-command.js";
|
|
15
15
|
export { wrapSpawn, createAbortedCommand, createFailedCommand, } from "./shell-command.js";
|
|
16
|
+
export { subprocessEnv } from "./subprocess-env.js";
|
|
16
17
|
export { exec, getCwd, setCwd, initCwd, getOriginalCwd, setShellProvider, getShellProvider, } from "./shell-exec.js";
|
|
17
18
|
export type { ExecOptions } from "./shell-exec.js";
|
|
@@ -57,9 +57,24 @@ export declare function executeTool(name: string, toolCallId: string, args: Reco
|
|
|
57
57
|
* CC reference: claude-code-haha/src/tools.ts getTools()
|
|
58
58
|
*/
|
|
59
59
|
export declare function getTools(): PortableTool[];
|
|
60
|
+
/**
|
|
61
|
+
* Activate a deferred tool so it appears in subsequent LLM manifests.
|
|
62
|
+
* CC parity: tool_search select: → activateTool → tool included in manifest.
|
|
63
|
+
* Returns true if the tool exists, is enabled, and was activated.
|
|
64
|
+
*/
|
|
65
|
+
export declare function activateTool(name: string): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Check if a tool has been activated via tool_search.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isToolActivated(name: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Clear all tool activations (call at session/turn boundary if needed).
|
|
72
|
+
*/
|
|
73
|
+
export declare function clearActivatedTools(): void;
|
|
60
74
|
/**
|
|
61
75
|
* Generate ToolDefinition[] manifest for LLM tool_use.
|
|
62
76
|
* Filters by isEnabled() — disabled tools never reach the model.
|
|
77
|
+
* Deferred tools are excluded UNLESS they have been activated via tool_search.
|
|
63
78
|
* CC: getTools() + manifest generation combined.
|
|
64
79
|
*/
|
|
65
80
|
export declare function getToolManifest(includeDeferred?: boolean): ToolDefinition[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Event Emitter — translates internal qlogicagent notifications to ACP
|
|
3
|
+
* session/update notifications.
|
|
4
|
+
*
|
|
5
|
+
* Maps the 47+ internal notification methods (turn.delta, turn.tool_call, etc.)
|
|
6
|
+
* to 9 standard + 19 extended ACP sessionUpdate types.
|
|
7
|
+
*
|
|
8
|
+
* Usage: Called by the StdioServer event loop. Instead of (or in addition to)
|
|
9
|
+
* emitting raw notifications, events are translated and emitted through the
|
|
10
|
+
* AcpServer.emitSessionUpdate() method.
|
|
11
|
+
*/
|
|
12
|
+
import type { AcpServer } from "./acp-server.js";
|
|
13
|
+
/**
|
|
14
|
+
* Translates and emits a qlogicagent internal notification as an ACP session/update.
|
|
15
|
+
*
|
|
16
|
+
* @param server The AcpServer instance to emit through
|
|
17
|
+
* @param sessionId Active ACP session ID
|
|
18
|
+
* @param method Internal notification method name
|
|
19
|
+
* @param params Internal notification payload
|
|
20
|
+
*/
|
|
21
|
+
export declare function emitAcpUpdate(server: AcpServer, sessionId: string, method: string, params: Record<string, unknown>): void;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP Server — Agent-Client Protocol server layer for qlogicagent.
|
|
3
|
+
*
|
|
4
|
+
* This module implements qlogicagent as an ACP Server, allowing any ACP-compliant
|
|
5
|
+
* host (AionUI, Cursor, openclaw, etc.) to connect and interact with the agent.
|
|
6
|
+
*
|
|
7
|
+
* Protocol: ACP v1 over JSON-RPC 2.0 / stdio (line-delimited JSON).
|
|
8
|
+
*
|
|
9
|
+
* Responsibilities:
|
|
10
|
+
* - Accepts ACP standard methods: initialize, session/new, session/prompt, session/end
|
|
11
|
+
* - Accepts x/ extended methods: x/abort, x/dream, x/solo.*, x/product.*
|
|
12
|
+
* - Emits ACP session/update notifications (standard + x_ extended)
|
|
13
|
+
* - Translates host permission responses back to the agent
|
|
14
|
+
*
|
|
15
|
+
* Architecture: AcpServer wraps a Transport and delegates to an AcpRequestHandler
|
|
16
|
+
* interface. The StdioServer implements this interface by routing ACP methods to
|
|
17
|
+
* existing internal handlers.
|
|
18
|
+
*/
|
|
19
|
+
import type { Transport } from "../cli/transport.js";
|
|
20
|
+
import { type AcpInitializeParams, type AcpInitializeResult, type AcpSessionNewParams, type AcpSessionNewResult, type AcpSessionPromptParams, type AcpSessionPromptResult, type AcpSessionEndParams, type AcpSessionSetConfigParams, type AcpSessionUpdateType, type AcpPermissionRequestParams, type AcpPermissionRequestResult } from "qlogicagent-runtime-contracts";
|
|
21
|
+
export declare const ACP_ERROR_CODES: {
|
|
22
|
+
readonly PARSE_ERROR: -32700;
|
|
23
|
+
readonly INVALID_REQUEST: -32600;
|
|
24
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
25
|
+
readonly INVALID_PARAMS: -32602;
|
|
26
|
+
readonly INTERNAL_ERROR: -32603;
|
|
27
|
+
/** Protocol version mismatch */
|
|
28
|
+
readonly PROTOCOL_MISMATCH: -32001;
|
|
29
|
+
/** Session not found */
|
|
30
|
+
readonly SESSION_NOT_FOUND: -32002;
|
|
31
|
+
/** Agent busy (turn in progress) */
|
|
32
|
+
readonly AGENT_BUSY: -32003;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Interface that StdioServer (or any backend) implements to handle ACP requests.
|
|
36
|
+
* Each method corresponds to an ACP protocol method.
|
|
37
|
+
*/
|
|
38
|
+
export interface AcpRequestHandler {
|
|
39
|
+
handleAcpInitialize(params: AcpInitializeParams): Promise<AcpInitializeResult>;
|
|
40
|
+
handleAcpSessionNew(params: AcpSessionNewParams): Promise<AcpSessionNewResult>;
|
|
41
|
+
handleAcpSessionPrompt(params: AcpSessionPromptParams): Promise<AcpSessionPromptResult>;
|
|
42
|
+
handleAcpSessionEnd(params: AcpSessionEndParams): Promise<void>;
|
|
43
|
+
handleAcpSessionSetConfig(params: AcpSessionSetConfigParams): Promise<void>;
|
|
44
|
+
handleAcpSessionSetModel(sessionId: string, model: string): Promise<void>;
|
|
45
|
+
handleAcpSessionSetMode(sessionId: string, mode: string): Promise<void>;
|
|
46
|
+
handleAcpPermissionResponse(permissionId: string, optionId: string): void;
|
|
47
|
+
handleAcpAbort(params: {
|
|
48
|
+
sessionId: string;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
handleAcpDream(params: {
|
|
51
|
+
sessionId: string;
|
|
52
|
+
config?: Record<string, unknown>;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
ok: boolean;
|
|
55
|
+
summary?: string;
|
|
56
|
+
}>;
|
|
57
|
+
handleAcpSoloStart(params: Record<string, unknown>): Promise<unknown>;
|
|
58
|
+
handleAcpSoloStatus(params: Record<string, unknown>): Promise<unknown>;
|
|
59
|
+
handleAcpSoloSelect(params: Record<string, unknown>): Promise<unknown>;
|
|
60
|
+
handleAcpProductCreate(params: Record<string, unknown>): Promise<unknown>;
|
|
61
|
+
handleAcpProductResume(params: Record<string, unknown>): Promise<unknown>;
|
|
62
|
+
handleAcpProductStatus(params: Record<string, unknown>): Promise<unknown>;
|
|
63
|
+
handleAcpTeamDelegate(params: Record<string, unknown>): Promise<unknown>;
|
|
64
|
+
}
|
|
65
|
+
export interface AcpServerConfig {
|
|
66
|
+
verbose?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* AcpServer — manages the ACP protocol state machine.
|
|
70
|
+
*
|
|
71
|
+
* Lifecycle:
|
|
72
|
+
* 1. Host connects (stdio)
|
|
73
|
+
* 2. Host sends `initialize` → agent responds with capabilities
|
|
74
|
+
* 3. Host sends `session/new` → session created
|
|
75
|
+
* 4. Host sends `session/prompt` → agent runs turn, emits session/update notifications
|
|
76
|
+
* 5. Host sends `session/end` → session cleaned up
|
|
77
|
+
*/
|
|
78
|
+
export declare class AcpServer {
|
|
79
|
+
private transport;
|
|
80
|
+
private handler;
|
|
81
|
+
private verbose;
|
|
82
|
+
/** Host capabilities declared during initialize */
|
|
83
|
+
private hostCapabilities;
|
|
84
|
+
/** Whether the host supports x_ extended events */
|
|
85
|
+
private hostSupportsExtendedEvents;
|
|
86
|
+
/** Whether the host supports x/ extended RPC methods */
|
|
87
|
+
private hostSupportsExtendedMethods;
|
|
88
|
+
/** Active session ID (ACP v1 = single session per connection) */
|
|
89
|
+
private activeSessionId;
|
|
90
|
+
/** Pending permission requests (agent → host) waiting for response */
|
|
91
|
+
private pendingPermissions;
|
|
92
|
+
constructor(transport: Transport, handler: AcpRequestHandler, config?: AcpServerConfig);
|
|
93
|
+
/**
|
|
94
|
+
* Route an incoming raw message through ACP protocol handling.
|
|
95
|
+
* Called by the unified message dispatcher in StdioServer.
|
|
96
|
+
* Returns true if the message was handled, false otherwise.
|
|
97
|
+
*/
|
|
98
|
+
dispatchMessage(raw: unknown): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Emit an ACP session/update notification to the host.
|
|
101
|
+
* Standard update types are always sent; x_ types only if host declared
|
|
102
|
+
* capabilities.extendedEvents = true.
|
|
103
|
+
*/
|
|
104
|
+
emitSessionUpdate(sessionId: string, type: AcpSessionUpdateType, payload: Record<string, unknown>): void;
|
|
105
|
+
/**
|
|
106
|
+
* Send a permission request to the host (agent → host RPC).
|
|
107
|
+
* Returns a promise that resolves with the host's chosen option.
|
|
108
|
+
*/
|
|
109
|
+
requestPermission(params: AcpPermissionRequestParams): Promise<AcpPermissionRequestResult>;
|
|
110
|
+
/** Whether the host supports extended events */
|
|
111
|
+
get supportsExtendedEvents(): boolean;
|
|
112
|
+
/** Whether the host supports extended methods */
|
|
113
|
+
get supportsExtendedMethods(): boolean;
|
|
114
|
+
/** Get the active session ID */
|
|
115
|
+
get sessionId(): string | null;
|
|
116
|
+
private handleRequest;
|
|
117
|
+
private handleNotification;
|
|
118
|
+
private handleResponse;
|
|
119
|
+
private onInitialize;
|
|
120
|
+
private onSessionNew;
|
|
121
|
+
private onSessionPrompt;
|
|
122
|
+
private onSessionEnd;
|
|
123
|
+
private onSessionSetConfig;
|
|
124
|
+
private onAbort;
|
|
125
|
+
private onDream;
|
|
126
|
+
private sendResult;
|
|
127
|
+
private sendError;
|
|
128
|
+
private isJsonRpcResponse;
|
|
129
|
+
private log;
|
|
130
|
+
}
|