qlogicagent 1.3.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +35 -8
  2. package/dist/agent.js +14 -14
  3. package/dist/cli.js +261 -224
  4. package/dist/index.js +260 -224
  5. package/dist/qlogicagent.cmd +2 -0
  6. package/dist/types/cli/main.d.ts +5 -1
  7. package/dist/types/cli/stdio-server.d.ts +62 -6
  8. package/dist/types/contracts/hooks.d.ts +3 -0
  9. package/dist/types/index.d.ts +1 -1
  10. package/dist/types/llm/index.d.ts +1 -1
  11. package/dist/types/llm/transports/media-resolve.d.ts +25 -0
  12. package/dist/types/runtime/execution/dream-agent.d.ts +2 -0
  13. package/dist/types/runtime/execution/dream-category-context.d.ts +47 -0
  14. package/dist/types/runtime/execution/dream-category-context.test.d.ts +1 -0
  15. package/dist/types/runtime/execution/index.d.ts +1 -0
  16. package/dist/types/runtime/execution/memory-decay.d.ts +57 -0
  17. package/dist/types/runtime/execution/memory-decay.test.d.ts +1 -0
  18. package/dist/types/runtime/hooks/index.d.ts +1 -0
  19. package/dist/types/runtime/hooks/memory-hooks.d.ts +20 -0
  20. package/dist/types/runtime/hooks/skill-recall-hooks.d.ts +36 -0
  21. package/dist/types/runtime/infra/acp-protocol-adapter.d.ts +72 -18
  22. package/dist/types/runtime/infra/acp-types.d.ts +30 -17
  23. package/dist/types/runtime/infra/agent-paths.d.ts +15 -3
  24. package/dist/types/runtime/infra/disk-storage.d.ts +0 -16
  25. package/dist/types/runtime/infra/index.d.ts +4 -4
  26. package/dist/types/runtime/session/session-persistence.d.ts +3 -1
  27. package/dist/types/skills/index.d.ts +5 -5
  28. package/dist/types/skills/memory/find-relevant-memories.d.ts +70 -0
  29. package/dist/types/skills/memory/memdir.d.ts +80 -0
  30. package/dist/types/skills/memory/memory-tool.d.ts +16 -44
  31. package/dist/types/skills/memory/memory-write-gate.d.ts +46 -0
  32. package/dist/types/skills/memory/memory-write-hook.d.ts +44 -0
  33. package/dist/types/skills/memory/qmemory-adapter.d.ts +12 -0
  34. package/dist/types/skills/memory/recall-category-filter.d.ts +54 -0
  35. package/dist/types/skills/tools/skill-tool.d.ts +16 -3
  36. package/dist/types/transport/acp-event-emitter.d.ts +21 -0
  37. package/dist/types/transport/acp-server.d.ts +130 -0
  38. package/dist/types/transport/index.d.ts +6 -0
  39. package/package.json +1 -1
  40. package/dist/types/skills/memory/memory-store.d.ts +0 -86
  41. package/dist/types/skills/tools/skill-invoke-tool.d.ts +0 -46
  42. package/dist/types/skills/tools/skill-list-tool.d.ts +0 -33
  43. package/dist/types/skills/tools/skill-manage-tool.d.ts +0 -73
  44. package/dist/types/skills/tools/skill-view-tool.d.ts +0 -37
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Transport layer — ACP Server + Event Emitter.
3
+ */
4
+ export { AcpServer, ACP_ERROR_CODES } from "./acp-server.js";
5
+ export type { AcpRequestHandler, AcpServerConfig } from "./acp-server.js";
6
+ export { emitAcpUpdate } from "./acp-event-emitter.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qlogicagent",
3
- "version": "1.3.0",
3
+ "version": "2.1.0",
4
4
  "description": "XiaozhiClaw Agent CLI — subprocess architecture (JSON-RPC over stdio)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,86 +0,0 @@
1
- export declare const MEMORY_ENTRY_DELIMITER = "\n\u00A7\n";
2
- export declare const DEFAULT_MEMORY_CHAR_LIMIT = 2200;
3
- export declare const DEFAULT_USER_CHAR_LIMIT = 1375;
4
- export type MemoryStoreTarget = "memory" | "user";
5
- export interface MemoryStoreResult {
6
- ok: boolean;
7
- message: string;
8
- target: MemoryStoreTarget;
9
- entries: readonly string[];
10
- entryCount: number;
11
- usage: string;
12
- errorCode?: string;
13
- }
14
- export interface MemoryStoreOptions {
15
- memoryCharLimit?: number;
16
- userCharLimit?: number;
17
- /** When true, mutations automatically persist to ~/.qlogicagent/memory.json */
18
- persistToDisk?: boolean;
19
- }
20
- export interface MemoryStoreSerialized {
21
- memory: string;
22
- user: string;
23
- }
24
- export declare class MemoryStore {
25
- private memoryEntries;
26
- private userEntries;
27
- private frozenSnapshot;
28
- private snapshotFrozen;
29
- private saveTimer;
30
- private readonly memoryCharLimit;
31
- private readonly userCharLimit;
32
- private readonly persistToDisk;
33
- constructor(options?: MemoryStoreOptions);
34
- /**
35
- * Load from serialized form (e.g. from PG or filesystem).
36
- * Deduplicates entries on load.
37
- */
38
- loadFromSerialized(data: Partial<MemoryStoreSerialized>): void;
39
- /**
40
- * Serialize current live state for persistence.
41
- */
42
- serialize(): MemoryStoreSerialized;
43
- /**
44
- * Load from disk (~/.qlogicagent/memory.json). No-op if file doesn't exist.
45
- * Call this at startup when persistToDisk is enabled.
46
- */
47
- loadFromDisk(): Promise<void>;
48
- /**
49
- * Synchronous variant for use in sync constructors / init paths.
50
- */
51
- loadFromDiskSync(): void;
52
- /**
53
- * Schedule a debounced save to disk (500ms). Multiple rapid mutations
54
- * coalesce into a single disk write.
55
- */
56
- private scheduleSave;
57
- /** Flush any pending save immediately. Call before shutdown. */
58
- flush(): Promise<void>;
59
- /**
60
- * Freeze current entries for system prompt injection.
61
- * Call once at session start. After freezing, mutations update
62
- * live state but NOT the system prompt block.
63
- */
64
- freezeSnapshot(): void;
65
- /**
66
- * Get frozen system prompt block for the given target.
67
- * Returns empty string if no entries or not yet frozen.
68
- */
69
- getSystemPromptBlock(target: MemoryStoreTarget): string;
70
- add(target: MemoryStoreTarget, content: string): MemoryStoreResult;
71
- replace(target: MemoryStoreTarget, oldText: string, newContent: string): MemoryStoreResult;
72
- remove(target: MemoryStoreTarget, oldText: string): MemoryStoreResult;
73
- getEntries(target: MemoryStoreTarget): readonly string[];
74
- getUsage(target: MemoryStoreTarget): {
75
- used: number;
76
- limit: number;
77
- percent: number;
78
- };
79
- isEmpty(): boolean;
80
- private entriesFor;
81
- private charLimitFor;
82
- private formatUsage;
83
- private renderBlock;
84
- private successResult;
85
- private errorResult;
86
- }
@@ -1,46 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- import type { WorkspaceSkill } from "../skill-system/skill-types.js";
3
- export declare const SKILL_TOOL_NAME: "skill_invoke";
4
- export interface SkillInvokeParams {
5
- skill: string;
6
- args?: string;
7
- }
8
- export declare const SKILL_INVOKE_SCHEMA: {
9
- readonly type: "object";
10
- readonly properties: {
11
- readonly skill: {
12
- readonly type: "string";
13
- readonly description: "Name of the skill to invoke. Use skill_list to see available skills.";
14
- };
15
- readonly args: {
16
- readonly type: "string";
17
- readonly description: string;
18
- };
19
- };
20
- readonly required: readonly ["skill"];
21
- };
22
- export interface SkillToolDeps {
23
- /**
24
- * Get all available skills (Layer 0 metadata).
25
- * Returns name + description pairs for tool manifest enrichment.
26
- */
27
- listSkills(): WorkspaceSkill[];
28
- /**
29
- * Read skill content (Layer 1 instructions).
30
- * Returns the full SKILL.md content for the named skill.
31
- * Returns null if skill not found.
32
- */
33
- readSkillContent(name: string): Promise<string | null>;
34
- /**
35
- * Execute the skill instructions as a sub-turn.
36
- * The implementation should:
37
- * 1. Build system prompt from SKILL.md content
38
- * 2. Run a sub-turn (fork) with skill instructions
39
- * 3. Return the sub-turn's final response
40
- *
41
- * If not provided, the skill content is returned directly
42
- * (the LLM can then follow the instructions in context).
43
- */
44
- executeSkillSubturn?(skillName: string, skillContent: string, userArgs: string | undefined, signal?: AbortSignal): Promise<string>;
45
- }
46
- export declare function createSkillTool(deps: SkillToolDeps): PortableTool<SkillInvokeParams>;
@@ -1,33 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const SKILL_LIST_TOOL_NAME: "skill_list";
3
- export interface SkillListToolParams {
4
- category?: string;
5
- }
6
- export declare const SKILL_LIST_TOOL_SCHEMA: {
7
- readonly type: "object";
8
- readonly properties: {
9
- readonly category: {
10
- readonly type: "string";
11
- readonly description: "Filter skills by category (e.g. 'devops', 'mlops'). Omit to list all.";
12
- };
13
- };
14
- readonly required: readonly [];
15
- };
16
- export interface SkillListItem {
17
- name: string;
18
- description: string;
19
- version?: string;
20
- category?: string;
21
- }
22
- export interface SkillListOutput {
23
- skills: SkillListItem[];
24
- categories: string[];
25
- }
26
- /**
27
- * Host-provided skill registry for listing.
28
- */
29
- export interface SkillListToolDeps {
30
- /** List all available skills, optionally filtered by category. */
31
- listSkills(category?: string): Promise<SkillListOutput>;
32
- }
33
- export declare function createSkillListTool(deps: SkillListToolDeps): PortableTool<SkillListToolParams>;
@@ -1,73 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const SKILL_MANAGE_TOOL_NAME: "skill_manage";
3
- export type SkillManageAction = "create" | "edit" | "patch" | "delete" | "write_file" | "remove_file";
4
- export interface SkillManageToolParams {
5
- action: SkillManageAction;
6
- name: string;
7
- content?: string;
8
- category?: string;
9
- filePath?: string;
10
- fileContent?: string;
11
- oldString?: string;
12
- newString?: string;
13
- }
14
- export declare const SKILL_MANAGE_TOOL_SCHEMA: {
15
- readonly type: "object";
16
- readonly properties: {
17
- readonly action: {
18
- readonly type: "string";
19
- readonly enum: readonly ["create", "edit", "patch", "delete", "write_file", "remove_file"];
20
- readonly description: string;
21
- };
22
- readonly name: {
23
- readonly type: "string";
24
- readonly description: "Skill name (lowercase, max 64 chars, kebab-case: letters, digits, hyphens).";
25
- };
26
- readonly content: {
27
- readonly type: "string";
28
- readonly description: string;
29
- };
30
- readonly category: {
31
- readonly type: "string";
32
- readonly description: "Category/domain (e.g. 'devops', 'mlops'). Used by create to organize skills.";
33
- };
34
- readonly filePath: {
35
- readonly type: "string";
36
- readonly description: string;
37
- };
38
- readonly fileContent: {
39
- readonly type: "string";
40
- readonly description: "Content for write_file action. Max 1 MiB.";
41
- };
42
- readonly oldString: {
43
- readonly type: "string";
44
- readonly description: "Text to find for patch action (must match uniquely in SKILL.md).";
45
- };
46
- readonly newString: {
47
- readonly type: "string";
48
- readonly description: "Replacement text for patch action (can be empty to delete).";
49
- };
50
- };
51
- readonly required: readonly ["action", "name"];
52
- };
53
- export interface SkillManageResult {
54
- success: boolean;
55
- message: string;
56
- path?: string;
57
- }
58
- /**
59
- * Host-provided skill management backend.
60
- */
61
- export interface SkillManageToolDeps {
62
- /**
63
- * Execute a skill management action.
64
- * The host handles file system operations, validation, and security scanning.
65
- */
66
- manageSkill(params: SkillManageToolParams): Promise<SkillManageResult>;
67
- /**
68
- * Validate skill name format.
69
- * If not provided, tool uses built-in validation.
70
- */
71
- validateName?(name: string): string | null;
72
- }
73
- export declare function createSkillManageTool(deps: SkillManageToolDeps): PortableTool<SkillManageToolParams>;
@@ -1,37 +0,0 @@
1
- import type { PortableTool } from "../portable-tool.js";
2
- export declare const SKILL_VIEW_TOOL_NAME: "skill_view";
3
- export interface SkillViewToolParams {
4
- name: string;
5
- filePath?: string;
6
- }
7
- export declare const SKILL_VIEW_TOOL_SCHEMA: {
8
- readonly type: "object";
9
- readonly properties: {
10
- readonly name: {
11
- readonly type: "string";
12
- readonly description: "Skill name to view (e.g. 'code-review', 'deploy-ecs').";
13
- };
14
- readonly filePath: {
15
- readonly type: "string";
16
- readonly description: string;
17
- };
18
- };
19
- readonly required: readonly ["name"];
20
- };
21
- export interface SkillViewOutput {
22
- name: string;
23
- content: string;
24
- referenceFiles?: string[];
25
- tags?: string[];
26
- }
27
- /**
28
- * Host-provided skill viewer.
29
- */
30
- export interface SkillViewToolDeps {
31
- /**
32
- * Read skill content. Returns the main SKILL.md or a specific file.
33
- * Returns null if skill not found.
34
- */
35
- viewSkill(name: string, filePath?: string): Promise<SkillViewOutput | null>;
36
- }
37
- export declare function createSkillViewTool(deps: SkillViewToolDeps): PortableTool<SkillViewToolParams>;