@ai-setting/roy-agent-core 1.5.15-test → 1.5.17-beta.1
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/dist/config/index.d.ts +1250 -0
- package/dist/config/index.js +32 -0
- package/dist/env/agent/index.d.ts +2279 -0
- package/dist/env/agent/index.js +24 -0
- package/dist/env/commands/index.d.ts +1131 -0
- package/dist/env/commands/index.js +14 -0
- package/dist/env/debug/formatters/index.d.ts +236 -0
- package/dist/env/debug/formatters/index.js +11 -0
- package/dist/env/debug/index.d.ts +1652 -0
- package/dist/env/debug/index.js +26 -0
- package/dist/env/hook/index.d.ts +279 -0
- package/dist/env/hook/index.js +29 -0
- package/dist/env/index.d.ts +3481 -0
- package/dist/env/index.js +82 -0
- package/dist/env/llm/index.d.ts +1760 -0
- package/dist/env/llm/index.js +40 -0
- package/dist/env/log-trace/index.d.ts +1574 -0
- package/dist/env/log-trace/index.js +83 -0
- package/dist/env/mcp/index.d.ts +1331 -0
- package/dist/env/mcp/index.js +39 -0
- package/dist/env/mcp/tool/index.d.ts +183 -0
- package/dist/env/mcp/tool/index.js +14 -0
- package/dist/env/memory/built-in/index.d.ts +232 -0
- package/dist/env/memory/built-in/index.js +11 -0
- package/dist/env/memory/index.d.ts +1799 -0
- package/dist/env/memory/index.js +56 -0
- package/dist/env/memory/plugin/index.d.ts +747 -0
- package/dist/env/memory/plugin/index.js +36 -0
- package/dist/env/prompt/index.d.ts +1164 -0
- package/dist/env/prompt/index.js +20 -0
- package/dist/env/session/index.d.ts +1908 -0
- package/dist/env/session/index.js +25 -0
- package/dist/env/session/storage/index.d.ts +564 -0
- package/dist/env/session/storage/index.js +18 -0
- package/dist/env/skill/index.d.ts +1266 -0
- package/dist/env/skill/index.js +34 -0
- package/dist/env/skill/tool/index.d.ts +193 -0
- package/dist/env/skill/tool/index.js +9 -0
- package/dist/env/task/delegate/index.d.ts +1612 -0
- package/dist/env/task/delegate/index.js +18 -0
- package/dist/env/task/events/index.d.ts +171 -0
- package/dist/env/task/events/index.js +7 -0
- package/dist/env/task/hooks/index.d.ts +624 -0
- package/dist/env/task/hooks/index.js +7 -0
- package/dist/env/task/index.d.ts +1553 -0
- package/dist/env/task/index.js +34 -0
- package/dist/env/task/plugins/index.d.ts +466 -0
- package/dist/env/task/plugins/index.js +23 -0
- package/dist/env/task/storage/index.d.ts +241 -0
- package/dist/env/task/storage/index.js +14 -0
- package/dist/env/task/tools/index.d.ts +1485 -0
- package/dist/env/task/tools/index.js +17 -0
- package/dist/env/task/tools/operation/index.d.ts +1484 -0
- package/dist/env/task/tools/operation/index.js +15 -0
- package/dist/env/tool/built-in/index.d.ts +218 -0
- package/dist/env/tool/built-in/index.js +25 -0
- package/dist/env/tool/index.d.ts +1396 -0
- package/dist/env/tool/index.js +39 -0
- package/dist/env/workflow/decorators/index.d.ts +2161 -0
- package/dist/env/workflow/decorators/index.js +27 -0
- package/dist/env/workflow/engine/index.d.ts +3453 -0
- package/dist/env/workflow/engine/index.js +28 -0
- package/dist/env/workflow/index.d.ts +3546 -0
- package/dist/env/workflow/index.js +136 -0
- package/dist/env/workflow/nodes/index.d.ts +2092 -0
- package/dist/env/workflow/nodes/index.js +19 -0
- package/dist/env/workflow/service/index.d.ts +227 -0
- package/dist/env/workflow/service/index.js +13 -0
- package/dist/env/workflow/storage/index.d.ts +165 -0
- package/dist/env/workflow/storage/index.js +27 -0
- package/dist/env/workflow/tools/index.d.ts +416 -0
- package/dist/env/workflow/tools/index.js +159 -0
- package/dist/env/workflow/types/index.d.ts +2255 -0
- package/dist/env/workflow/types/index.js +98 -0
- package/dist/env/workflow/utils/index.d.ts +2031 -0
- package/dist/env/workflow/utils/index.js +637 -0
- package/dist/index.d.ts +7858 -0
- package/dist/index.js +399 -0
- package/dist/shared/@ai-setting/roy-agent-core-0rtxwr28.js +258 -0
- package/dist/shared/@ai-setting/roy-agent-core-0vbdz0x7.js +36 -0
- package/dist/shared/@ai-setting/roy-agent-core-1akcqxj9.js +349 -0
- package/dist/shared/@ai-setting/roy-agent-core-1ce3fqrk.js +117 -0
- package/dist/shared/@ai-setting/roy-agent-core-2dhd60aw.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-3jywqmdd.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-3rr5k71j.js +200 -0
- package/dist/shared/@ai-setting/roy-agent-core-44hnfb02.js +299 -0
- package/dist/shared/@ai-setting/roy-agent-core-4t40mkpv.js +206 -0
- package/dist/shared/@ai-setting/roy-agent-core-4txzpsbt.js +393 -0
- package/dist/shared/@ai-setting/roy-agent-core-5x94xmt6.js +350 -0
- package/dist/shared/@ai-setting/roy-agent-core-69jskqjg.js +180 -0
- package/dist/shared/@ai-setting/roy-agent-core-6kvtahqv.js +408 -0
- package/dist/shared/@ai-setting/roy-agent-core-7fgf85wc.js +284 -0
- package/dist/shared/@ai-setting/roy-agent-core-81w1963m.js +762 -0
- package/dist/shared/@ai-setting/roy-agent-core-8gxth0eh.js +10 -0
- package/dist/shared/@ai-setting/roy-agent-core-92z6t4he.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-93zfb3r1.js +922 -0
- package/dist/shared/@ai-setting/roy-agent-core-9yxb3ty9.js +15 -0
- package/dist/shared/@ai-setting/roy-agent-core-b0x5dda6.js +1130 -0
- package/dist/shared/@ai-setting/roy-agent-core-bcbqy27c.js +14 -0
- package/dist/shared/@ai-setting/roy-agent-core-bvr1761x.js +653 -0
- package/dist/shared/@ai-setting/roy-agent-core-ctdhjv68.js +93 -0
- package/dist/shared/@ai-setting/roy-agent-core-d7cyjkf7.js +872 -0
- package/dist/shared/@ai-setting/roy-agent-core-dh9d7a3m.js +11 -0
- package/dist/shared/@ai-setting/roy-agent-core-e25xkv53.js +64 -0
- package/dist/shared/@ai-setting/roy-agent-core-eajcvp4e.js +378 -0
- package/dist/shared/@ai-setting/roy-agent-core-f7q2x5z6.js +492 -0
- package/dist/shared/@ai-setting/roy-agent-core-fs0mn2jk.js +52 -0
- package/dist/shared/@ai-setting/roy-agent-core-g1s2h0e5.js +171 -0
- package/dist/shared/@ai-setting/roy-agent-core-g99pxzn5.js +862 -0
- package/dist/shared/@ai-setting/roy-agent-core-gbqcyegm.js +1387 -0
- package/dist/shared/@ai-setting/roy-agent-core-gjq1yk68.js +208 -0
- package/dist/shared/@ai-setting/roy-agent-core-gq20wsgv.js +139 -0
- package/dist/shared/@ai-setting/roy-agent-core-gwc4h96n.js +534 -0
- package/dist/shared/@ai-setting/roy-agent-core-jfh9q2qh.js +204 -0
- package/dist/shared/@ai-setting/roy-agent-core-jvatggbb.js +603 -0
- package/dist/shared/@ai-setting/roy-agent-core-kkbwepqb.js +97 -0
- package/dist/shared/@ai-setting/roy-agent-core-pjr12nnd.js +587 -0
- package/dist/shared/@ai-setting/roy-agent-core-psv4v63c.js +176 -0
- package/dist/shared/@ai-setting/roy-agent-core-psvxt4c9.js +60 -0
- package/dist/shared/@ai-setting/roy-agent-core-qqceba6k.js +442 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxhq8ven.js +57 -0
- package/dist/shared/@ai-setting/roy-agent-core-qxnbvgwe.js +66 -0
- package/dist/shared/@ai-setting/roy-agent-core-r9ezzemr.js +10 -0
- package/dist/shared/@ai-setting/roy-agent-core-rhmtwnw1.js +267 -0
- package/dist/shared/@ai-setting/roy-agent-core-rvv6ydff.js +584 -0
- package/dist/shared/@ai-setting/roy-agent-core-rvxg1wps.js +102 -0
- package/dist/shared/@ai-setting/roy-agent-core-satmq6sh.js +549 -0
- package/dist/shared/@ai-setting/roy-agent-core-sx7wsvnn.js +15 -0
- package/dist/shared/@ai-setting/roy-agent-core-t94ktchq.js +213 -0
- package/dist/shared/@ai-setting/roy-agent-core-vf215qfv.js +812 -0
- package/dist/shared/@ai-setting/roy-agent-core-vkz81f7v.js +1316 -0
- package/dist/shared/@ai-setting/roy-agent-core-vn2bc59q.js +1205 -0
- package/dist/shared/@ai-setting/roy-agent-core-wa1kzqky.js +328 -0
- package/dist/shared/@ai-setting/roy-agent-core-wft9ra24.js +20 -0
- package/dist/shared/@ai-setting/roy-agent-core-wrcy0h6z.js +2098 -0
- package/dist/shared/@ai-setting/roy-agent-core-xq8hhqb8.js +419 -0
- package/dist/shared/@ai-setting/roy-agent-core-xs5rsgat.js +368 -0
- package/dist/shared/@ai-setting/roy-agent-core-zbkpc41z.js +377 -0
- package/dist/shared/@ai-setting/roy-agent-core-zgypchmt.js +172 -0
- package/dist/shared/@ai-setting/roy-agent-core-zpn0bqa8.js +103 -0
- package/package.json +29 -8
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AgentComponentAdapter,
|
|
3
|
+
init_agent_component_adapter
|
|
4
|
+
} from "./roy-agent-core-69jskqjg.js";
|
|
5
|
+
import"./roy-agent-core-e25xkv53.js";
|
|
6
|
+
import"./roy-agent-core-fs0mn2jk.js";
|
|
7
|
+
init_agent_component_adapter();
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
AgentComponentAdapter
|
|
11
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__esm
|
|
3
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
4
|
+
|
|
5
|
+
// src/env/workflow/types/workflow-hil.ts
|
|
6
|
+
function createNodeInterruptEvent(runId, nodeId, nodeType, query, agentSessionId) {
|
|
7
|
+
return {
|
|
8
|
+
type: "node.interrupt",
|
|
9
|
+
run_id: runId,
|
|
10
|
+
timestamp: Date.now(),
|
|
11
|
+
node_id: nodeId,
|
|
12
|
+
node_type: nodeType,
|
|
13
|
+
query,
|
|
14
|
+
...agentSessionId ? { agent_session_id: agentSessionId } : {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function createWorkflowAskUserEvent(runId, sessionId, nodeId, nodeType, query) {
|
|
18
|
+
return {
|
|
19
|
+
type: "workflow.ask-user",
|
|
20
|
+
run_id: runId,
|
|
21
|
+
timestamp: Date.now(),
|
|
22
|
+
session_id: sessionId,
|
|
23
|
+
node_id: nodeId,
|
|
24
|
+
node_type: nodeType,
|
|
25
|
+
query
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var AskUserError;
|
|
29
|
+
var init_workflow_hil = __esm(() => {
|
|
30
|
+
AskUserError = class AskUserError extends Error {
|
|
31
|
+
runId;
|
|
32
|
+
sessionId;
|
|
33
|
+
nodeId;
|
|
34
|
+
nodeType;
|
|
35
|
+
query;
|
|
36
|
+
agentSessionId;
|
|
37
|
+
timestamp;
|
|
38
|
+
type = "ask-user";
|
|
39
|
+
name = "AskUserError";
|
|
40
|
+
constructor(runId, sessionId, nodeId, nodeType, query, agentSessionId, timestamp = Date.now()) {
|
|
41
|
+
super(`[${nodeType}:${nodeId}] Ask user: ${query}`);
|
|
42
|
+
this.runId = runId;
|
|
43
|
+
this.sessionId = sessionId;
|
|
44
|
+
this.nodeId = nodeId;
|
|
45
|
+
this.nodeType = nodeType;
|
|
46
|
+
this.query = query;
|
|
47
|
+
this.agentSessionId = agentSessionId;
|
|
48
|
+
this.timestamp = timestamp;
|
|
49
|
+
}
|
|
50
|
+
toEvent() {
|
|
51
|
+
return {
|
|
52
|
+
type: "workflow.ask-user",
|
|
53
|
+
run_id: this.runId,
|
|
54
|
+
timestamp: this.timestamp,
|
|
55
|
+
session_id: this.sessionId,
|
|
56
|
+
node_id: this.nodeId,
|
|
57
|
+
node_type: this.nodeType,
|
|
58
|
+
query: this.query
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export { createNodeInterruptEvent, createWorkflowAskUserEvent, AskUserError, init_workflow_hil };
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TracedAs,
|
|
3
|
+
init_decorator
|
|
4
|
+
} from "./roy-agent-core-zgypchmt.js";
|
|
5
|
+
import {
|
|
6
|
+
createLogger,
|
|
7
|
+
init_logger
|
|
8
|
+
} from "./roy-agent-core-44hnfb02.js";
|
|
9
|
+
import {
|
|
10
|
+
__legacyDecorateClassTS
|
|
11
|
+
} from "./roy-agent-core-fs0mn2jk.js";
|
|
12
|
+
|
|
13
|
+
// src/env/agent/summary-agent.ts
|
|
14
|
+
init_logger();
|
|
15
|
+
init_decorator();
|
|
16
|
+
var logger = createLogger("agent:summary");
|
|
17
|
+
|
|
18
|
+
class SummaryAgent {
|
|
19
|
+
promptComponent;
|
|
20
|
+
llmComponent;
|
|
21
|
+
config;
|
|
22
|
+
constructor(promptComponent, llmComponent, config) {
|
|
23
|
+
this.promptComponent = promptComponent;
|
|
24
|
+
this.llmComponent = llmComponent;
|
|
25
|
+
this.config = {
|
|
26
|
+
type: "summary",
|
|
27
|
+
promptName: "session/compact",
|
|
28
|
+
maxIterations: 1,
|
|
29
|
+
model: undefined,
|
|
30
|
+
...config
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async generateCompactHint(options) {
|
|
34
|
+
const { messages, sessionContext } = options;
|
|
35
|
+
logger.info("[SummaryAgent] Generating compact hint for session");
|
|
36
|
+
const formattedMessages = this.formatMessages(messages);
|
|
37
|
+
const systemPrompt = this.getHintGenerationSystemPrompt();
|
|
38
|
+
const userPrompt = this.buildHintGenerationUserPrompt(formattedMessages, sessionContext);
|
|
39
|
+
let response;
|
|
40
|
+
try {
|
|
41
|
+
response = await this.llmComponent.invoke({
|
|
42
|
+
messages: [
|
|
43
|
+
{ role: "system", content: systemPrompt },
|
|
44
|
+
{ role: "user", content: userPrompt }
|
|
45
|
+
],
|
|
46
|
+
skipThresholdCheck: true
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger.error(`[SummaryAgent] Hint generation LLM invoke failed: ${error}`);
|
|
50
|
+
throw new Error(`LLM invoke failed: ${error}`);
|
|
51
|
+
}
|
|
52
|
+
const responseContent = response.output?.content || response.content || "";
|
|
53
|
+
const hint = this.parseHintResponse(responseContent);
|
|
54
|
+
logger.info("[SummaryAgent] Compact hint generated", { hint: hint.substring(0, 100) });
|
|
55
|
+
return {
|
|
56
|
+
hint,
|
|
57
|
+
rawResponse: responseContent
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async run(options) {
|
|
61
|
+
const { messages, userContext, outputFormat, scenarioHint } = options;
|
|
62
|
+
logger.info("[SummaryAgent] Starting checkpoint generation", {
|
|
63
|
+
hasScenarioHint: !!scenarioHint
|
|
64
|
+
});
|
|
65
|
+
const formattedMessages = this.formatMessages(messages);
|
|
66
|
+
const systemPrompt = this.getSystemPrompt(scenarioHint);
|
|
67
|
+
const userPrompt = this.buildUserPrompt(formattedMessages, userContext);
|
|
68
|
+
let response;
|
|
69
|
+
try {
|
|
70
|
+
response = await this.llmComponent.invoke({
|
|
71
|
+
messages: [
|
|
72
|
+
{ role: "system", content: systemPrompt },
|
|
73
|
+
{ role: "user", content: userPrompt }
|
|
74
|
+
],
|
|
75
|
+
model: this.config.model,
|
|
76
|
+
skipThresholdCheck: true
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
logger.error(`[SummaryAgent] LLM invoke failed: ${error}`);
|
|
80
|
+
throw new Error(`LLM invoke failed: ${error}`);
|
|
81
|
+
}
|
|
82
|
+
const responseContent = response.output?.content || response.content || "";
|
|
83
|
+
if (outputFormat === "json") {
|
|
84
|
+
const result = this.parseJsonResponse(responseContent);
|
|
85
|
+
logger.info(`[SummaryAgent] Checkpoint generated: "${result.title}"`);
|
|
86
|
+
return {
|
|
87
|
+
title: result.title || "Untitled Checkpoint",
|
|
88
|
+
processKeyPoints: result.processKeyPoints || [],
|
|
89
|
+
currentState: result.currentState || "",
|
|
90
|
+
nextSteps: result.nextSteps || [],
|
|
91
|
+
userIntents: result.userIntents || [],
|
|
92
|
+
rawResponse: responseContent
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`Unsupported output format: ${outputFormat}`);
|
|
96
|
+
}
|
|
97
|
+
getSystemPrompt(scenarioHint) {
|
|
98
|
+
let prompt = `You are a professional session analyst assistant. Your task is to extract key information from a conversation and generate a structured checkpoint.
|
|
99
|
+
|
|
100
|
+
A checkpoint captures the progress and state of a session at a point in time. It should contain:
|
|
101
|
+
|
|
102
|
+
1. **Process Key Points**: The key steps, discoveries, or decisions made during this part of the conversation
|
|
103
|
+
2. **Current State**: The current progress and status at the end of the conversation
|
|
104
|
+
3. **Next Steps**: Follow-up items and what needs to be done next
|
|
105
|
+
4. **User Intents**: The underlying goals and intentions of the user (what they want to accomplish)
|
|
106
|
+
|
|
107
|
+
Be concise and accurate. Avoid redundancy. Each section should be appropriately sized - not too long.`;
|
|
108
|
+
if (scenarioHint && scenarioHint.trim()) {
|
|
109
|
+
prompt += `
|
|
110
|
+
|
|
111
|
+
## Scenario Context
|
|
112
|
+
|
|
113
|
+
${scenarioHint.trim()}`;
|
|
114
|
+
}
|
|
115
|
+
return prompt;
|
|
116
|
+
}
|
|
117
|
+
getHintGenerationSystemPrompt() {
|
|
118
|
+
return `You are a compact guidance prompt engineer. Your task is to analyze a conversation and generate a "compact guidance prompt" that will instruct the checkpoint generator on what information to extract and preserve during session compression.
|
|
119
|
+
|
|
120
|
+
**Purpose**: The guidance prompt will be used by the checkpoint generator to understand:
|
|
121
|
+
1. What work is currently in progress
|
|
122
|
+
2. What progress has been made
|
|
123
|
+
3. What information MUST be preserved during compression (this is critical for task continuation)
|
|
124
|
+
4. What information should be the focus of extraction
|
|
125
|
+
|
|
126
|
+
**Key Principle**: The preserved information should enable seamless task continuation. If critical details are lost during compression, the user will have to re-explain context when continuing this work later.
|
|
127
|
+
|
|
128
|
+
**Output Format**: A structured guidance prompt (3-4 sentences) covering:
|
|
129
|
+
1. Current work type and what the user is trying to accomplish
|
|
130
|
+
2. Current progress and key achievements
|
|
131
|
+
3. CRITICAL information that MUST be preserved (decisions, findings, remaining issues)
|
|
132
|
+
4. What the checkpoint generator should focus on when extracting information
|
|
133
|
+
|
|
134
|
+
**Example good outputs**:
|
|
135
|
+
1. "Bug investigation: User is debugging LSP diagnostics not updating after file edits. Progress: identified root cause (getDiagnostics needs to read latest file content and trigger didChange notification), implemented fix, CI verified. CRITICAL to preserve: the fix implementation details (file path, code changes), that 2 agent-node-integration tests still fail due to test assertion timing issue (expects 'running' but completes in ~78ms) - this is unrelated to LSP work. Focus extraction on: root cause analysis, fix implementation, known remaining test issues."
|
|
136
|
+
2. "Feature development: User is implementing JWT authentication for auth-service. Progress: designed auth flow, implemented token refresh logic, middleware partially done. CRITICAL to preserve: auth flow decisions (token storage, refresh strategy), completed middleware components, modules pending implementation. Focus extraction on: architectural decisions, completed components, pending work."
|
|
137
|
+
3. "Refactoring: User is migrating data layer to repository pattern. Progress: migrated UserRepository and OrderRepository, 3 more pending. CRITICAL to preserve: pattern decisions (interface definitions, dependency injection approach), completed repositories, modules pending migration. Focus extraction on: pattern implementation details, completed vs pending modules."`;
|
|
138
|
+
}
|
|
139
|
+
buildHintGenerationUserPrompt(messages, sessionContext) {
|
|
140
|
+
let prompt = `Analyze the following conversation and generate a compact guidance prompt for checkpoint generation.
|
|
141
|
+
|
|
142
|
+
## Your Task
|
|
143
|
+
Generate a structured guidance prompt (3-4 sentences) that will help the checkpoint generator understand:
|
|
144
|
+
1. What work is currently in progress
|
|
145
|
+
2. What progress has been made
|
|
146
|
+
3. What information MUST be preserved during compression (critical for task continuation)
|
|
147
|
+
4. What the checkpoint generator should focus on when extracting information
|
|
148
|
+
|
|
149
|
+
`;
|
|
150
|
+
if (sessionContext) {
|
|
151
|
+
const ctxLines = ["## Session Context"];
|
|
152
|
+
if (sessionContext.activeTaskTitle) {
|
|
153
|
+
ctxLines.push(`- Active Task: ${sessionContext.activeTaskTitle}`);
|
|
154
|
+
}
|
|
155
|
+
if (sessionContext.workingDirectory) {
|
|
156
|
+
ctxLines.push(`- Working Directory: ${sessionContext.workingDirectory}`);
|
|
157
|
+
}
|
|
158
|
+
if (sessionContext.recentActions && sessionContext.recentActions.length > 0) {
|
|
159
|
+
ctxLines.push(`- Recent Actions: ${sessionContext.recentActions.slice(-3).join(" → ")}`);
|
|
160
|
+
}
|
|
161
|
+
if (ctxLines.length > 1) {
|
|
162
|
+
prompt += ctxLines.join(`
|
|
163
|
+
`) + `
|
|
164
|
+
|
|
165
|
+
`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
prompt += `## Conversation to Analyze
|
|
169
|
+
|
|
170
|
+
${messages}
|
|
171
|
+
|
|
172
|
+
`;
|
|
173
|
+
prompt += `---
|
|
174
|
+
|
|
175
|
+
`;
|
|
176
|
+
prompt += `## Output Format
|
|
177
|
+
|
|
178
|
+
`;
|
|
179
|
+
prompt += `Generate a structured guidance prompt covering:
|
|
180
|
+
`;
|
|
181
|
+
prompt += `1. Current work type and what the user is trying to accomplish
|
|
182
|
+
`;
|
|
183
|
+
prompt += `2. Current progress and key achievements
|
|
184
|
+
`;
|
|
185
|
+
prompt += `3. CRITICAL information that MUST be preserved (decisions, findings, remaining issues)
|
|
186
|
+
`;
|
|
187
|
+
prompt += `4. What to focus on during extraction
|
|
188
|
+
|
|
189
|
+
`;
|
|
190
|
+
prompt += `Wrap the output in a JSON object with a \`guidance_prompt\` key:
|
|
191
|
+
|
|
192
|
+
`;
|
|
193
|
+
prompt += `\`\`\`json
|
|
194
|
+
`;
|
|
195
|
+
prompt += `{
|
|
196
|
+
`;
|
|
197
|
+
prompt += ` "guidance_prompt": "Work type: ... Progress: ... CRITICAL to preserve: ... Focus extraction on: ..."
|
|
198
|
+
`;
|
|
199
|
+
prompt += `}
|
|
200
|
+
`;
|
|
201
|
+
prompt += `\`\`\`
|
|
202
|
+
|
|
203
|
+
`;
|
|
204
|
+
prompt += `IMPORTANT: The preserved information should enable seamless task continuation. If critical details are lost, the user will need to re-explain context when continuing this work.`;
|
|
205
|
+
return prompt;
|
|
206
|
+
}
|
|
207
|
+
buildUserPrompt(messages, userContext) {
|
|
208
|
+
let prompt = `Please analyze the following conversation and generate a checkpoint:
|
|
209
|
+
|
|
210
|
+
`;
|
|
211
|
+
if (userContext && userContext !== "无额外上下文") {
|
|
212
|
+
prompt += `## Context
|
|
213
|
+
${userContext}
|
|
214
|
+
|
|
215
|
+
`;
|
|
216
|
+
}
|
|
217
|
+
prompt += `## Conversation Content
|
|
218
|
+
|
|
219
|
+
${messages}
|
|
220
|
+
|
|
221
|
+
`;
|
|
222
|
+
prompt += `---
|
|
223
|
+
|
|
224
|
+
`;
|
|
225
|
+
prompt += `## Output Format
|
|
226
|
+
|
|
227
|
+
Please output in the following JSON format:
|
|
228
|
+
|
|
229
|
+
\`\`\`json
|
|
230
|
+
{
|
|
231
|
+
"title": "Brief checkpoint title (max 30 characters)",
|
|
232
|
+
"processKeyPoints": [
|
|
233
|
+
"Point 1: Description of key discovery or decision",
|
|
234
|
+
"Point 2: Description of important step or conclusion",
|
|
235
|
+
"Point 3: ..."
|
|
236
|
+
],
|
|
237
|
+
"currentState": "Current state description explaining progress and status (50-100 characters)",
|
|
238
|
+
"nextSteps": [
|
|
239
|
+
"Next follow-up item 1",
|
|
240
|
+
"Next follow-up item 2"
|
|
241
|
+
],
|
|
242
|
+
"userIntents": [
|
|
243
|
+
"User intent 1: what the user wants to accomplish",
|
|
244
|
+
"User intent 2: another goal or request",
|
|
245
|
+
"User intent 3: ..."
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
\`\`\`
|
|
249
|
+
|
|
250
|
+
`;
|
|
251
|
+
prompt += `## Intent Extraction Guidelines
|
|
252
|
+
|
|
253
|
+
`;
|
|
254
|
+
prompt += `- Extract user intents from the ENTIRE conversation flow (both user and assistant messages)
|
|
255
|
+
`;
|
|
256
|
+
prompt += `- Focus on what the user WANTS to accomplish, not just what was discussed
|
|
257
|
+
`;
|
|
258
|
+
prompt += `- Include both explicit requests and inferred goals
|
|
259
|
+
`;
|
|
260
|
+
prompt += `- Aim for 2-5 intents, prioritize the most important ones
|
|
261
|
+
`;
|
|
262
|
+
prompt += `- Be concise and specific in intent descriptions
|
|
263
|
+
`;
|
|
264
|
+
prompt += `- Examples: "Fix authentication bug", "Optimize database performance", "Add unit tests for auth module"
|
|
265
|
+
|
|
266
|
+
`;
|
|
267
|
+
prompt += `Make sure the JSON output is valid and can be parsed.`;
|
|
268
|
+
return prompt;
|
|
269
|
+
}
|
|
270
|
+
formatMessages(messages) {
|
|
271
|
+
return messages.map((m, i) => `[${i}] ${m.role}: ${m.content}`).join(`
|
|
272
|
+
|
|
273
|
+
`);
|
|
274
|
+
}
|
|
275
|
+
parseJsonResponse(content) {
|
|
276
|
+
const jsonMatch = content.match(/```json\s*([\s\S]*?)\s*```/) || content.match(/```\s*([\s\S]*?)\s*```/) || [null, content];
|
|
277
|
+
const jsonStr = jsonMatch[1] || content;
|
|
278
|
+
try {
|
|
279
|
+
return JSON.parse(jsonStr.trim());
|
|
280
|
+
} catch {
|
|
281
|
+
const fixed = jsonStr.replace(/,\s*}/g, "}").replace(/,\s*]/g, "]").replace(/'/g, '"').trim();
|
|
282
|
+
try {
|
|
283
|
+
return JSON.parse(fixed);
|
|
284
|
+
} catch (e) {
|
|
285
|
+
logger.error(`[SummaryAgent] Failed to parse JSON: ${content}`);
|
|
286
|
+
throw new Error(`Failed to parse checkpoint JSON: ${e}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
parseHintResponse(content) {
|
|
291
|
+
return parseCompactHintResponse(content);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
__legacyDecorateClassTS([
|
|
295
|
+
TracedAs("summary-agent.generateCompactHint")
|
|
296
|
+
], SummaryAgent.prototype, "generateCompactHint", null);
|
|
297
|
+
__legacyDecorateClassTS([
|
|
298
|
+
TracedAs("summary-agent.run", { recordParams: true, recordResult: true })
|
|
299
|
+
], SummaryAgent.prototype, "run", null);
|
|
300
|
+
__legacyDecorateClassTS([
|
|
301
|
+
TracedAs("summary-agent.getHintGenerationSystemPrompt")
|
|
302
|
+
], SummaryAgent.prototype, "getHintGenerationSystemPrompt", null);
|
|
303
|
+
__legacyDecorateClassTS([
|
|
304
|
+
TracedAs("summary-agent.buildHintGenerationUserPrompt")
|
|
305
|
+
], SummaryAgent.prototype, "buildHintGenerationUserPrompt", null);
|
|
306
|
+
__legacyDecorateClassTS([
|
|
307
|
+
TracedAs("summary-agent.parseHintResponse")
|
|
308
|
+
], SummaryAgent.prototype, "parseHintResponse", null);
|
|
309
|
+
function parseCompactHintResponse(content) {
|
|
310
|
+
const jsonResult = extractGuidanceFromJson(content);
|
|
311
|
+
if (jsonResult !== null) {
|
|
312
|
+
const trimmed = jsonResult.trim();
|
|
313
|
+
if (!trimmed) {
|
|
314
|
+
return "[Hint extraction failed]";
|
|
315
|
+
}
|
|
316
|
+
if (trimmed.length > 500) {
|
|
317
|
+
return trimmed.substring(0, 500) + "...";
|
|
318
|
+
}
|
|
319
|
+
return trimmed;
|
|
320
|
+
}
|
|
321
|
+
let text = content.replace(/```json\s*([\s\S]*?)\s*```/g, "$1").replace(/```markdown\s*([\s\S]*?)\s*```/g, "$1").replace(/```\s*([\s\S]*?)\s*```/g, "$1").trim();
|
|
322
|
+
if (!text) {
|
|
323
|
+
return "[Hint extraction failed]";
|
|
324
|
+
}
|
|
325
|
+
if (text.length > 500) {
|
|
326
|
+
return text.substring(0, 500) + "...";
|
|
327
|
+
}
|
|
328
|
+
return text;
|
|
329
|
+
}
|
|
330
|
+
function extractGuidanceFromJson(content) {
|
|
331
|
+
const jsonBlockMatch = content.match(/```json\s*([\s\S]*?)\s*```/);
|
|
332
|
+
if (jsonBlockMatch) {
|
|
333
|
+
const parsed2 = tryParseJson(jsonBlockMatch[1]);
|
|
334
|
+
const guidancePrompt2 = parsed2?.guidance_prompt;
|
|
335
|
+
if (typeof guidancePrompt2 === "string") {
|
|
336
|
+
return guidancePrompt2;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
const plainBlockMatch = content.match(/```\s*([\s\S]*?)\s*```/);
|
|
340
|
+
if (plainBlockMatch) {
|
|
341
|
+
const parsed2 = tryParseJson(plainBlockMatch[1]);
|
|
342
|
+
const guidancePrompt2 = parsed2?.guidance_prompt;
|
|
343
|
+
if (typeof guidancePrompt2 === "string") {
|
|
344
|
+
return guidancePrompt2;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
const jsonMatch = content.match(/\{[\s\S]*"guidance_prompt"[\s\S]*\}/);
|
|
348
|
+
if (jsonMatch) {
|
|
349
|
+
const parsed2 = tryParseJson(jsonMatch[0]);
|
|
350
|
+
const guidancePrompt2 = parsed2?.guidance_prompt;
|
|
351
|
+
if (typeof guidancePrompt2 === "string") {
|
|
352
|
+
return guidancePrompt2;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const parsed = tryParseJson(content.trim());
|
|
356
|
+
const guidancePrompt = parsed?.guidance_prompt;
|
|
357
|
+
if (typeof guidancePrompt === "string") {
|
|
358
|
+
return guidancePrompt;
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
function tryParseJson(str) {
|
|
363
|
+
if (!str || !str.trim()) {
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
return JSON.parse(str.trim());
|
|
368
|
+
} catch {
|
|
369
|
+
try {
|
|
370
|
+
const fixed = str.replace(/,\s*}/g, "}").replace(/,\s*]/g, "]").trim();
|
|
371
|
+
return JSON.parse(fixed);
|
|
372
|
+
} catch {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
export { SummaryAgent };
|