qlogicagent 0.5.2 → 0.5.3
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 +402 -402
- package/dist/agent.js +18 -0
- package/dist/cli.js +360 -0
- package/dist/contracts.js +1 -0
- package/dist/index.js +22 -0
- package/dist/orchestration.js +125 -0
- package/dist/types/agent/agent.d.ts +43 -0
- package/dist/types/agent/constants.d.ts +47 -0
- package/dist/types/agent/tool-loop.d.ts +96 -0
- package/dist/types/agent/types.d.ts +250 -0
- package/dist/types/cli/main.d.ts +11 -0
- package/dist/types/cli/stdio-server.d.ts +56 -0
- package/dist/types/cli/tool-bootstrap.d.ts +21 -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 +10 -0
- package/dist/types/contracts/planner.d.ts +35 -0
- package/dist/types/contracts/skill-candidate.d.ts +63 -0
- package/dist/types/contracts/todo.d.ts +14 -0
- package/dist/types/index.d.ts +13 -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/agent-registry.d.ts +46 -0
- package/dist/types/orchestration/context-collapse.d.ts +58 -0
- package/dist/types/orchestration/context-compression.d.ts +301 -0
- package/dist/types/orchestration/conversation-repair.d.ts +61 -0
- package/dist/types/orchestration/curator-scheduler.d.ts +119 -0
- package/dist/types/orchestration/error-classification.d.ts +12 -0
- package/dist/types/orchestration/failover-classification.d.ts +8 -0
- package/dist/types/orchestration/failover-error.d.ts +33 -0
- package/dist/types/orchestration/fork-subagent.d.ts +100 -0
- package/dist/types/orchestration/index.d.ts +113 -0
- package/dist/types/orchestration/memory-provider.d.ts +14 -0
- package/dist/types/orchestration/reactive-compact.d.ts +73 -0
- package/dist/types/orchestration/retry-loop.d.ts +69 -0
- package/dist/types/orchestration/skill-candidate.d.ts +52 -0
- package/dist/types/orchestration/skill-consolidation.d.ts +123 -0
- package/dist/types/orchestration/skill-improvement.d.ts +59 -0
- package/dist/types/orchestration/skill-similarity.d.ts +98 -0
- package/dist/types/orchestration/task-types.d.ts +142 -0
- package/dist/types/orchestration/team-orchestration.d.ts +195 -0
- package/dist/types/orchestration/team-tool-loop-wiring.d.ts +92 -0
- package/dist/types/orchestration/tool-choice-policy.d.ts +54 -0
- package/dist/types/orchestration/tool-loop-state.d.ts +50 -0
- package/dist/types/orchestration/tool-schema.d.ts +39 -0
- package/dist/types/orchestration/turn-loop-guard.d.ts +86 -0
- package/dist/types/runtime/execution/dream-agent.d.ts +199 -0
- package/dist/types/runtime/execution/forked-agent.d.ts +111 -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/cleanup-registry.d.ts +23 -0
- package/dist/types/runtime/infra/file-watcher.d.ts +72 -0
- package/dist/types/runtime/infra/index.d.ts +6 -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 +91 -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 +125 -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 +84 -0
- package/dist/types/skills/mcp/mcp-stdio-client.d.ts +84 -0
- package/dist/types/skills/memory-extractor.d.ts +64 -0
- package/dist/types/skills/memory-query-tool.d.ts +43 -0
- package/dist/types/skills/memory-store.d.ts +66 -0
- package/dist/types/skills/memory-tool.d.ts +67 -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 +45 -0
- package/dist/types/skills/plugins/plugin-marketplace.d.ts +61 -0
- package/dist/types/skills/portable-tool.d.ts +71 -0
- package/dist/types/skills/qmemory-adapter.d.ts +42 -0
- package/dist/types/skills/skill-frontmatter.d.ts +19 -0
- package/dist/types/skills/skill-guard.d.ts +23 -0
- package/dist/types/skills/skill-loader.d.ts +16 -0
- package/dist/types/skills/skill-source.d.ts +119 -0
- package/dist/types/skills/skill-types.d.ts +199 -0
- package/dist/types/skills/think-tool.d.ts +16 -0
- package/dist/types/skills/todo-tool.d.ts +63 -0
- package/dist/types/skills/tool-registry.d.ts +29 -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 +103 -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/memory-tool.d.ts +74 -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/pdf-tool.d.ts +66 -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/package.json +3 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool loop state machine — CC query.ts aligned.
|
|
3
|
+
*
|
|
4
|
+
* Architecture:
|
|
5
|
+
* - Infinite while(true) loop with centralized State object (CC parity)
|
|
6
|
+
* - 7 labeled continue sites matching CC's query loop transitions
|
|
7
|
+
* - Error Withholding: 413 / max_output_tokens / media errors are
|
|
8
|
+
* withheld from callers during recovery attempts
|
|
9
|
+
* - Context Collapse drain: staged collapses committed on 413
|
|
10
|
+
* BEFORE falling through to reactive compact
|
|
11
|
+
* - Media error recovery: image/media errors → reactive compact retry
|
|
12
|
+
* - Hermes delta suppression preserved
|
|
13
|
+
* - StreamingToolExecutor preserved
|
|
14
|
+
* - Sidechain depth/policy preserved
|
|
15
|
+
* - Skill learning evaluation preserved
|
|
16
|
+
*
|
|
17
|
+
* CC reference: src/query.ts queryLoop()
|
|
18
|
+
*
|
|
19
|
+
* Zero imports from express/pg/ioredis/ws.
|
|
20
|
+
*/
|
|
21
|
+
import type { AgentLogger, ChatMessage, ToolDefinition, ToolInvoker, TurnEvent, HookRegistry } from "./types.js";
|
|
22
|
+
import type { LLMTransport } from "../llm/transport.js";
|
|
23
|
+
export interface ToolLoopParams {
|
|
24
|
+
turnId: string;
|
|
25
|
+
sessionId: string;
|
|
26
|
+
messages: ChatMessage[];
|
|
27
|
+
tools: ToolDefinition[];
|
|
28
|
+
model: string;
|
|
29
|
+
apiKey: string;
|
|
30
|
+
temperature?: number;
|
|
31
|
+
maxRounds?: number;
|
|
32
|
+
/** Context window size in tokens (for turn-loop-guard budget checks) */
|
|
33
|
+
contextWindowTokens?: number;
|
|
34
|
+
/** Max output tokens for current model */
|
|
35
|
+
maxOutputTokens?: number;
|
|
36
|
+
/** Model's absolute max output tokens (escalation ceiling) */
|
|
37
|
+
modelMaxOutputTokens?: number;
|
|
38
|
+
/** Tool choice strategy (default "auto") */
|
|
39
|
+
toolChoice?: "auto" | "none" | "required";
|
|
40
|
+
/** Parent sidechain depth (0 = top-level) */
|
|
41
|
+
parentDepth?: number;
|
|
42
|
+
/** Sidechain type for tool access policy (default "code-repair" = full access) */
|
|
43
|
+
sidechainType?: import("../orchestration/index.js").SidechainType;
|
|
44
|
+
/** Tool eligibility context for policy-based filtering */
|
|
45
|
+
toolEligibilityContext?: import("../runtime/execution/tool-eligibility.js").ToolEligibilityContext;
|
|
46
|
+
/** Hook registry for lifecycle events (optional, fire-and-forget) */
|
|
47
|
+
hooks?: HookRegistry;
|
|
48
|
+
/** Max turns (loop iterations). 0 = use maxRounds. */
|
|
49
|
+
maxTurns?: number;
|
|
50
|
+
/** Fallback model to switch to after repeated 529 errors (CC parity). */
|
|
51
|
+
fallbackModel?: string;
|
|
52
|
+
/** Query source for foreground/background retry distinction (CC parity). */
|
|
53
|
+
querySource?: string;
|
|
54
|
+
/** Token budget for this turn (>0 enables budget continuation). */
|
|
55
|
+
tokenBudget?: number;
|
|
56
|
+
/**
|
|
57
|
+
* Refresh tools callback — called between turns (CC refreshTools parity).
|
|
58
|
+
* Returns updated tool definitions if tools have changed (e.g. MCP reconnect),
|
|
59
|
+
* or the same array reference if unchanged.
|
|
60
|
+
*/
|
|
61
|
+
refreshTools?: () => ToolDefinition[];
|
|
62
|
+
/**
|
|
63
|
+
* Generate a human-readable summary label for a tool batch (CC generateToolUseSummary parity).
|
|
64
|
+
* Fire-and-forget: called after tool execution, result yielded as tool_use_summary event
|
|
65
|
+
* when the next LLM round starts streaming. ~30 chars, git-commit-subject style.
|
|
66
|
+
*/
|
|
67
|
+
generateToolUseSummary?: (toolCalls: Array<{
|
|
68
|
+
name: string;
|
|
69
|
+
arguments: string;
|
|
70
|
+
result?: string;
|
|
71
|
+
}>) => Promise<string | null>;
|
|
72
|
+
/**
|
|
73
|
+
* Post-sampling hooks — fire-and-forget after LLM response completes (CC executePostSamplingHooks parity).
|
|
74
|
+
* Cannot modify messages. Used for background tasks (memory extraction, skill learning, etc.).
|
|
75
|
+
*/
|
|
76
|
+
postSamplingHooks?: Array<(context: {
|
|
77
|
+
messages: unknown[];
|
|
78
|
+
model: string;
|
|
79
|
+
sessionId: string;
|
|
80
|
+
}) => Promise<void> | void>;
|
|
81
|
+
/** Max concurrent tool executions (0 = unlimited, CC parity: semantic concurrency control). */
|
|
82
|
+
maxConcurrentTools?: number;
|
|
83
|
+
signal?: AbortSignal;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Execute the tool loop — CC query.ts queryLoop() aligned.
|
|
87
|
+
*
|
|
88
|
+
* Yields TurnEvent stream. The caller (Agent class) wraps this with
|
|
89
|
+
* start/end lifecycle and error handling.
|
|
90
|
+
*
|
|
91
|
+
* Architecture: infinite while(true) with centralized State + 7 continue
|
|
92
|
+
* labels. Error withholding gates recoverable errors through collapse
|
|
93
|
+
* drain → reactive compact → escalation → recovery message pipeline
|
|
94
|
+
* before surfacing to callers.
|
|
95
|
+
*/
|
|
96
|
+
export declare function executeToolLoop(params: ToolLoopParams, transport: LLMTransport, toolInvoker: ToolInvoker, log: AgentLogger): AsyncGenerator<TurnEvent>;
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure agent types — zero I/O framework dependencies.
|
|
3
|
+
*
|
|
4
|
+
* These types define the contract between:
|
|
5
|
+
* - CLI stdio layer ↔ Agent class
|
|
6
|
+
* - Agent class ↔ LLM Provider
|
|
7
|
+
* - Agent class ↔ Tool loop
|
|
8
|
+
*
|
|
9
|
+
* Ported from Hub semantic-turn-shared.ts / semantic-turn-tools.ts,
|
|
10
|
+
* with Hub infrastructure (WS/PG/Redis) replaced by DI interfaces.
|
|
11
|
+
*
|
|
12
|
+
* No imports from express/pg/ioredis/ws.
|
|
13
|
+
*/
|
|
14
|
+
import type { SkillInstruction } from "../orchestration/index.js";
|
|
15
|
+
import type { HookRegistry } from "../contracts/hooks.js";
|
|
16
|
+
export type ChatMessageRole = "system" | "user" | "assistant" | "tool";
|
|
17
|
+
export interface ChatMessage {
|
|
18
|
+
role: ChatMessageRole;
|
|
19
|
+
content: string | null;
|
|
20
|
+
/** For assistant messages with tool calls */
|
|
21
|
+
tool_calls?: ToolCallMessage[];
|
|
22
|
+
/** For tool result messages */
|
|
23
|
+
tool_call_id?: string;
|
|
24
|
+
/** For tool result messages — tool name */
|
|
25
|
+
name?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ToolCallMessage {
|
|
28
|
+
id: string;
|
|
29
|
+
type: "function";
|
|
30
|
+
function: {
|
|
31
|
+
name: string;
|
|
32
|
+
arguments: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export interface ToolDefinition {
|
|
36
|
+
type: "function";
|
|
37
|
+
function: {
|
|
38
|
+
name: string;
|
|
39
|
+
description: string;
|
|
40
|
+
parameters?: Record<string, unknown>;
|
|
41
|
+
};
|
|
42
|
+
/** Tool scheduling metadata from host manifest (optional) */
|
|
43
|
+
meta?: {
|
|
44
|
+
serialOnly?: boolean;
|
|
45
|
+
parallelSafe?: boolean;
|
|
46
|
+
/** If true, host should request user approval before execution (CC PreToolUse parity) */
|
|
47
|
+
requiresApproval?: boolean;
|
|
48
|
+
/** Tool is read-only / safe — skip approval even in strict mode */
|
|
49
|
+
isReadOnly?: boolean;
|
|
50
|
+
/** Tool can cause irreversible side-effects — force approval in default mode */
|
|
51
|
+
isDangerous?: boolean;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Backfill derived/legacy fields onto a shallow copy of the tool input
|
|
55
|
+
* before hooks and observers see it (CC backfillObservableInput parity).
|
|
56
|
+
* The original API-bound input is never modified.
|
|
57
|
+
*/
|
|
58
|
+
backfillObservableInput?: (input: Record<string, unknown>) => void;
|
|
59
|
+
}
|
|
60
|
+
export interface TokenUsage {
|
|
61
|
+
prompt: number;
|
|
62
|
+
completion: number;
|
|
63
|
+
/** Reasoning tokens (for models like o1/DeepSeek-R1) */
|
|
64
|
+
reasoning?: number;
|
|
65
|
+
/** Prompt cache read tokens (CC cache_read_input_tokens parity) */
|
|
66
|
+
cacheRead?: number;
|
|
67
|
+
/** Prompt cache creation tokens (CC cache_creation_input_tokens parity) */
|
|
68
|
+
cacheCreation?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Why the previous iteration continued — each variant corresponds to one of
|
|
72
|
+
* the 7 `continue` sites in the main while(true) loop.
|
|
73
|
+
* Tests can assert recovery paths fired without inspecting message contents.
|
|
74
|
+
*/
|
|
75
|
+
export type ToolLoopTransition = {
|
|
76
|
+
reason: "collapse_drain_retry";
|
|
77
|
+
committed: number;
|
|
78
|
+
} | {
|
|
79
|
+
reason: "reactive_compact_retry";
|
|
80
|
+
} | {
|
|
81
|
+
reason: "max_output_tokens_escalate";
|
|
82
|
+
} | {
|
|
83
|
+
reason: "max_output_tokens_recovery";
|
|
84
|
+
attempt: number;
|
|
85
|
+
} | {
|
|
86
|
+
reason: "stop_hook_blocking";
|
|
87
|
+
} | {
|
|
88
|
+
reason: "token_budget_continuation";
|
|
89
|
+
} | {
|
|
90
|
+
reason: "next_turn";
|
|
91
|
+
};
|
|
92
|
+
/** Terminal exit reasons from the tool loop. */
|
|
93
|
+
export type ToolLoopTerminal = {
|
|
94
|
+
reason: "completed";
|
|
95
|
+
} | {
|
|
96
|
+
reason: "aborted";
|
|
97
|
+
} | {
|
|
98
|
+
reason: "prompt_too_long";
|
|
99
|
+
} | {
|
|
100
|
+
reason: "image_error";
|
|
101
|
+
} | {
|
|
102
|
+
reason: "model_error";
|
|
103
|
+
error?: unknown;
|
|
104
|
+
} | {
|
|
105
|
+
reason: "max_turns";
|
|
106
|
+
} | {
|
|
107
|
+
reason: "budget_exhausted";
|
|
108
|
+
} | {
|
|
109
|
+
reason: "tool_loop_limit";
|
|
110
|
+
} | {
|
|
111
|
+
reason: "stop_hook_prevented";
|
|
112
|
+
} | {
|
|
113
|
+
reason: "hook_stopped";
|
|
114
|
+
};
|
|
115
|
+
export interface TurnRequest {
|
|
116
|
+
turnId: string;
|
|
117
|
+
sessionId: string;
|
|
118
|
+
messages: ChatMessage[];
|
|
119
|
+
tools: ToolDefinition[];
|
|
120
|
+
systemPrompt?: string;
|
|
121
|
+
config?: TurnConfig;
|
|
122
|
+
}
|
|
123
|
+
export interface TurnConfig {
|
|
124
|
+
/** LLM provider id, e.g. "deepseek" */
|
|
125
|
+
provider?: string;
|
|
126
|
+
/** Model id, e.g. "deepseek-chat" */
|
|
127
|
+
model?: string;
|
|
128
|
+
/** User API key */
|
|
129
|
+
apiKey?: string;
|
|
130
|
+
/** Optional base URL override */
|
|
131
|
+
baseUrl?: string;
|
|
132
|
+
/** Max tool-call rounds per turn (default 25, max 100) */
|
|
133
|
+
maxRounds?: number;
|
|
134
|
+
/** Temperature override */
|
|
135
|
+
temperature?: number;
|
|
136
|
+
/** Context window size in tokens (for turn-loop-guard budget checks) */
|
|
137
|
+
contextWindowTokens?: number;
|
|
138
|
+
/** Max output tokens for current model */
|
|
139
|
+
maxOutputTokens?: number;
|
|
140
|
+
/** Model's absolute max output tokens (for escalation ceiling) */
|
|
141
|
+
modelMaxOutputTokens?: number;
|
|
142
|
+
/** Tool choice strategy: "auto" (default), "none", "required" */
|
|
143
|
+
toolChoice?: "auto" | "none" | "required";
|
|
144
|
+
/** Parent sidechain depth (0 = top-level, default 0) */
|
|
145
|
+
parentDepth?: number;
|
|
146
|
+
/** Sidechain type for tool access policy (default "code-repair" = full access) */
|
|
147
|
+
sidechainType?: import("../orchestration/index.js").SidechainType;
|
|
148
|
+
/** Per-turn token budget (prompt + completion). 0 or undefined = unlimited. */
|
|
149
|
+
tokenBudget?: number;
|
|
150
|
+
/** Fallback model to switch to after repeated 529 errors (CC parity). */
|
|
151
|
+
fallbackModel?: string;
|
|
152
|
+
/** Max turns (tool loop iterations). 0 or undefined = use maxRounds. */
|
|
153
|
+
maxTurns?: number;
|
|
154
|
+
/** Model for generating tool use summaries (CC parity: Haiku). If set, enables summary generation. */
|
|
155
|
+
summaryModel?: string;
|
|
156
|
+
/** Max concurrent tool executions (0 = unlimited). */
|
|
157
|
+
maxConcurrentTools?: number;
|
|
158
|
+
}
|
|
159
|
+
export type TurnEvent = {
|
|
160
|
+
type: "start";
|
|
161
|
+
turnId: string;
|
|
162
|
+
} | {
|
|
163
|
+
type: "delta";
|
|
164
|
+
turnId: string;
|
|
165
|
+
text: string;
|
|
166
|
+
} | {
|
|
167
|
+
type: "tool_call";
|
|
168
|
+
turnId: string;
|
|
169
|
+
callId: string;
|
|
170
|
+
name: string;
|
|
171
|
+
arguments: string;
|
|
172
|
+
} | {
|
|
173
|
+
type: "end";
|
|
174
|
+
turnId: string;
|
|
175
|
+
content: string;
|
|
176
|
+
usage?: TokenUsage;
|
|
177
|
+
model?: string;
|
|
178
|
+
provider?: string;
|
|
179
|
+
} | {
|
|
180
|
+
type: "error";
|
|
181
|
+
turnId: string;
|
|
182
|
+
error: string;
|
|
183
|
+
code?: string;
|
|
184
|
+
} | {
|
|
185
|
+
type: "skill_instruction";
|
|
186
|
+
turnId: string;
|
|
187
|
+
instruction: SkillInstruction;
|
|
188
|
+
} | {
|
|
189
|
+
type: "tool_result";
|
|
190
|
+
turnId: string;
|
|
191
|
+
callId: string;
|
|
192
|
+
name: string;
|
|
193
|
+
ok: boolean;
|
|
194
|
+
error?: string;
|
|
195
|
+
} | {
|
|
196
|
+
type: "sidechain_started";
|
|
197
|
+
turnId: string;
|
|
198
|
+
depth: number;
|
|
199
|
+
role: "orchestrator" | "leaf";
|
|
200
|
+
} | {
|
|
201
|
+
type: "sidechain_completed";
|
|
202
|
+
turnId: string;
|
|
203
|
+
depth: number;
|
|
204
|
+
toolCallCount: number;
|
|
205
|
+
} | {
|
|
206
|
+
type: "tool_blocked";
|
|
207
|
+
turnId: string;
|
|
208
|
+
callId: string;
|
|
209
|
+
name: string;
|
|
210
|
+
reason: string;
|
|
211
|
+
} | {
|
|
212
|
+
type: "recovery";
|
|
213
|
+
turnId: string;
|
|
214
|
+
action: string;
|
|
215
|
+
detail?: string;
|
|
216
|
+
} | {
|
|
217
|
+
type: "plan_update";
|
|
218
|
+
turnId: string;
|
|
219
|
+
slug: string;
|
|
220
|
+
content: string;
|
|
221
|
+
} | {
|
|
222
|
+
type: "heartbeat";
|
|
223
|
+
turnId: string;
|
|
224
|
+
message: string;
|
|
225
|
+
} | {
|
|
226
|
+
type: "tool_use_summary";
|
|
227
|
+
turnId: string;
|
|
228
|
+
summary: string;
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* ToolInvoker: request tool execution from the host process (Gateway).
|
|
232
|
+
* In CLI mode this sends a JSON-RPC notification over stdio and waits for result.
|
|
233
|
+
*/
|
|
234
|
+
export interface ToolInvoker {
|
|
235
|
+
invoke(turnId: string, name: string, args: string, signal?: AbortSignal): Promise<{
|
|
236
|
+
result: string;
|
|
237
|
+
error?: string;
|
|
238
|
+
}>;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* AgentLogger: structured logging interface.
|
|
242
|
+
* In CLI mode this writes to stderr; in Hub mode this uses pino.
|
|
243
|
+
*/
|
|
244
|
+
export interface AgentLogger {
|
|
245
|
+
info(message: string): void;
|
|
246
|
+
warn(message: string): void;
|
|
247
|
+
error(message: string): void;
|
|
248
|
+
debug(message: string): void;
|
|
249
|
+
}
|
|
250
|
+
export type { HookRegistry };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* qlogicagent CLI — Agent subprocess entry point.
|
|
4
|
+
*
|
|
5
|
+
* Communicates with openclaw Gateway via JSON-RPC over stdio.
|
|
6
|
+
* All log/debug output goes to stderr (never pollutes the stdio protocol).
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* qlogicagent [--verbose]
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StdioServer — JSON-RPC 2.0 over stdio protocol handler.
|
|
3
|
+
*
|
|
4
|
+
* Reads line-delimited JSON from stdin, dispatches to handlers,
|
|
5
|
+
* writes JSON-RPC responses/notifications to stdout.
|
|
6
|
+
* All log output goes to stderr.
|
|
7
|
+
*
|
|
8
|
+
* Protocol: each line on stdin/stdout is a single JSON-RPC 2.0 message.
|
|
9
|
+
*/
|
|
10
|
+
export interface StdioServerConfig {
|
|
11
|
+
verbose: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class StdioServer {
|
|
14
|
+
private running;
|
|
15
|
+
private activeTurn;
|
|
16
|
+
private verbose;
|
|
17
|
+
private registry;
|
|
18
|
+
private toolRegistry;
|
|
19
|
+
private agent;
|
|
20
|
+
private lastLlmConfigKey;
|
|
21
|
+
private currentSessionId;
|
|
22
|
+
private currentHooks;
|
|
23
|
+
private mcpManager;
|
|
24
|
+
private pluginLoader;
|
|
25
|
+
private permissionChecker;
|
|
26
|
+
private permissionUnregister;
|
|
27
|
+
/** Cached LLM transport for sub-agent forks (dream, session-memory) */
|
|
28
|
+
private currentTransport;
|
|
29
|
+
private currentApiKey;
|
|
30
|
+
private currentModel;
|
|
31
|
+
private sessionState;
|
|
32
|
+
private taskStore;
|
|
33
|
+
/** Session-scoped memory prefetch state (LRU dedup + byte limit). */
|
|
34
|
+
private memoryPrefetchState;
|
|
35
|
+
/** QMemory adapter (when QMEMORY_BASE_URL env is set). Used by Dream hippocampus bridge. */
|
|
36
|
+
private qmemoryAdapter;
|
|
37
|
+
private qmemoryUserId;
|
|
38
|
+
private fileWatcher;
|
|
39
|
+
constructor(config: StdioServerConfig);
|
|
40
|
+
start(): void;
|
|
41
|
+
stop(): void;
|
|
42
|
+
private handleMessage;
|
|
43
|
+
private handleHello;
|
|
44
|
+
private handlePing;
|
|
45
|
+
private handleAbort;
|
|
46
|
+
private handleApprovalResponse;
|
|
47
|
+
private handleSessionList;
|
|
48
|
+
private handleSessionResume;
|
|
49
|
+
private handleTurn;
|
|
50
|
+
private handleDream;
|
|
51
|
+
private resolveAgent;
|
|
52
|
+
private sendResponse;
|
|
53
|
+
private sendNotification;
|
|
54
|
+
private writeStdout;
|
|
55
|
+
private log;
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ToolRegistry } from "../skills/tool-registry.js";
|
|
2
|
+
import { type ExecProgress } from "../skills/tools/exec-tool.js";
|
|
3
|
+
import type { AgentLogger } from "../agent/types.js";
|
|
4
|
+
export interface BootstrapConfig {
|
|
5
|
+
workdir?: string;
|
|
6
|
+
log?: AgentLogger;
|
|
7
|
+
/** Called during foreground shell execution with incremental progress. */
|
|
8
|
+
onExecProgress?(progress: ExecProgress): void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create and populate a ToolRegistry with all locally-executable tools.
|
|
12
|
+
*
|
|
13
|
+
* Tools registered here execute IN-PROCESS (zero IPC).
|
|
14
|
+
* All tools are agent-local — no Gateway relay.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bootstrapToolRegistry(config?: BootstrapConfig): ToolRegistry;
|
|
17
|
+
/**
|
|
18
|
+
* Update the working directory for all local tool deps.
|
|
19
|
+
* Called when Gateway sends a new workdir via config.
|
|
20
|
+
*/
|
|
21
|
+
export declare function setBootstrapWorkdir(newWorkdir: string): void;
|
|
@@ -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,10 @@
|
|
|
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";
|
|
10
|
+
export * from "./skill-candidate.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
|
+
}
|