hypercore-cli 1.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 (84) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +110 -0
  3. package/dist/api-XGC7D5AW.js +162 -0
  4. package/dist/auth-DNQWYQKT.js +21 -0
  5. package/dist/background-2EGCAAQH.js +14 -0
  6. package/dist/backlog-Q2NZCLNY.js +24 -0
  7. package/dist/chunk-2CMSCWQW.js +162 -0
  8. package/dist/chunk-2LJ2DVEB.js +167 -0
  9. package/dist/chunk-3RPFCQKJ.js +288 -0
  10. package/dist/chunk-43OLRXM5.js +263 -0
  11. package/dist/chunk-4DVYJAJL.js +57 -0
  12. package/dist/chunk-6OL3GA3P.js +173 -0
  13. package/dist/chunk-AUHU7ALH.js +2023 -0
  14. package/dist/chunk-B6A2AKLN.js +139 -0
  15. package/dist/chunk-BE46C7JW.js +46 -0
  16. package/dist/chunk-CUVAUOXL.js +58 -0
  17. package/dist/chunk-GH7E2OJE.js +223 -0
  18. package/dist/chunk-GOOTEPBK.js +271 -0
  19. package/dist/chunk-GPPMJYSM.js +133 -0
  20. package/dist/chunk-GU2FZQ6A.js +69 -0
  21. package/dist/chunk-IOPKN5GD.js +190 -0
  22. package/dist/chunk-IXOIOGR5.js +1505 -0
  23. package/dist/chunk-KRPOPWGA.js +251 -0
  24. package/dist/chunk-MGLJ53QN.js +219 -0
  25. package/dist/chunk-MV4TTRYX.js +533 -0
  26. package/dist/chunk-OPZYEVYR.js +150 -0
  27. package/dist/chunk-QTSLP47C.js +166 -0
  28. package/dist/chunk-R3GPQC7I.js +393 -0
  29. package/dist/chunk-RKB2JOV2.js +43 -0
  30. package/dist/chunk-RNG3K465.js +80 -0
  31. package/dist/chunk-TGTYKBGC.js +86 -0
  32. package/dist/chunk-U5SGAIMM.js +681 -0
  33. package/dist/chunk-V5UHPPSY.js +140 -0
  34. package/dist/chunk-WHLVZCQY.js +245 -0
  35. package/dist/chunk-XDRCBMZZ.js +66 -0
  36. package/dist/chunk-XOS6HPEF.js +134 -0
  37. package/dist/chunk-ZSBHUGWR.js +262 -0
  38. package/dist/claude-NSQ442XD.js +12 -0
  39. package/dist/commands-CK3WFAGI.js +128 -0
  40. package/dist/commands-U63OEO5J.js +1044 -0
  41. package/dist/commands-ZE6GD3WC.js +232 -0
  42. package/dist/config-4EW42BSF.js +8 -0
  43. package/dist/config-loader-SXO674TF.js +24 -0
  44. package/dist/diagnose-AFW3ZTZ4.js +12 -0
  45. package/dist/display-IIUBEYWN.js +58 -0
  46. package/dist/extractor-QV53W2YJ.js +129 -0
  47. package/dist/history-WMSCHERZ.js +180 -0
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.js +406 -0
  50. package/dist/instance-registry-YSIJXSO7.js +15 -0
  51. package/dist/keybindings-JAAMLH3G.js +15 -0
  52. package/dist/loader-WHNTZTLP.js +58 -0
  53. package/dist/network-MM6YWPGO.js +279 -0
  54. package/dist/notify-HPTALZDC.js +14 -0
  55. package/dist/openai-compat-UQWJXBEK.js +12 -0
  56. package/dist/permissions-JUKXMNDH.js +10 -0
  57. package/dist/prompt-QV45TXRL.js +166 -0
  58. package/dist/quality-ST7PPNFR.js +16 -0
  59. package/dist/repl-RT3AHL7M.js +3375 -0
  60. package/dist/roadmap-5OBEKROY.js +17 -0
  61. package/dist/server-PORT7OEG.js +57 -0
  62. package/dist/session-4VUNDWLH.js +21 -0
  63. package/dist/skills-V4A35XKG.js +175 -0
  64. package/dist/store-Y4LU5QTO.js +25 -0
  65. package/dist/team-HO7Z4SIM.js +385 -0
  66. package/dist/telemetry-6R4EIE6O.js +30 -0
  67. package/dist/test-runner-ZQH5Y6OJ.js +619 -0
  68. package/dist/theme-3SYJ3UQA.js +14 -0
  69. package/dist/upgrade-7TGI3SXO.js +83 -0
  70. package/dist/verify-JUDKTPKZ.js +14 -0
  71. package/dist/web/static/app.js +562 -0
  72. package/dist/web/static/index.html +132 -0
  73. package/dist/web/static/mirror.css +1001 -0
  74. package/dist/web/static/mirror.html +184 -0
  75. package/dist/web/static/mirror.js +1125 -0
  76. package/dist/web/static/onboard.css +302 -0
  77. package/dist/web/static/onboard.html +140 -0
  78. package/dist/web/static/onboard.js +260 -0
  79. package/dist/web/static/style.css +602 -0
  80. package/dist/web/static/workspace.css +1568 -0
  81. package/dist/web/static/workspace.html +408 -0
  82. package/dist/web/static/workspace.js +1683 -0
  83. package/dist/web-Z5HSCQHW.js +39 -0
  84. package/package.json +67 -0
@@ -0,0 +1,232 @@
1
+ import {
2
+ CATEGORY_LABELS,
3
+ addMemory,
4
+ getMemoryStats,
5
+ listMemories,
6
+ removeMemory,
7
+ searchMemories
8
+ } from "./chunk-KRPOPWGA.js";
9
+ import "./chunk-V5UHPPSY.js";
10
+
11
+ // src/memory/commands.ts
12
+ import chalk from "chalk";
13
+ function createMemorySlashCommands() {
14
+ return [
15
+ // /remember <内容> — 手动保存记忆
16
+ {
17
+ name: "remember",
18
+ aliases: ["rem"],
19
+ description: "\u4FDD\u5B58\u4E00\u6761\u8BB0\u5FC6\uFF08/remember <\u5185\u5BB9>\uFF09",
20
+ category: "memory",
21
+ handler: async (args, _ctx) => {
22
+ const content = args.join(" ").trim();
23
+ if (!content) {
24
+ console.log(chalk.dim("\n \u7528\u6CD5: /remember <\u8981\u8BB0\u4F4F\u7684\u5185\u5BB9>\n"));
25
+ return;
26
+ }
27
+ if (content.length > 500) {
28
+ console.log(chalk.yellow("\n \u26A0\uFE0F \u5185\u5BB9\u8FC7\u957F\uFF08\u4E0A\u9650 500 \u5B57\u7B26\uFF09\uFF0C\u5DF2\u622A\u65AD\n"));
29
+ }
30
+ const tagMatches = content.match(/#(\w+)/g);
31
+ const tags = tagMatches ? tagMatches.map((t) => t.slice(1).toLowerCase()) : [];
32
+ const cleanContent = content.replace(/#\w+/g, "").trim().slice(0, 500);
33
+ const record = await addMemory("personal", {
34
+ layer: "personal",
35
+ category: "manual",
36
+ content: cleanContent,
37
+ tags: tags.length > 0 ? tags : extractAutoTags(cleanContent),
38
+ confidence: 1
39
+ });
40
+ console.log(chalk.green(`
41
+ \u2705 \u5DF2\u4FDD\u5B58\u8BB0\u5FC6: ${record.id}`));
42
+ console.log(chalk.dim(` ${cleanContent}`));
43
+ if (record.tags.length > 0) {
44
+ console.log(chalk.dim(` \u6807\u7B7E: ${record.tags.map((t) => `#${t}`).join(" ")}`));
45
+ }
46
+ console.log();
47
+ }
48
+ },
49
+ // /recall [主题] — 搜索记忆
50
+ {
51
+ name: "recall",
52
+ aliases: ["search-mem"],
53
+ description: "\u641C\u7D22\u8BB0\u5FC6\uFF08/recall [\u4E3B\u9898]\uFF09",
54
+ category: "memory",
55
+ handler: async (args, _ctx) => {
56
+ const query = args.join(" ").trim();
57
+ if (!query) {
58
+ const records = await listMemories("personal");
59
+ if (records.length === 0) {
60
+ console.log(chalk.dim("\n \u6682\u65E0\u8BB0\u5FC6\u3002\u4F7F\u7528 /remember <\u5185\u5BB9> \u4FDD\u5B58\n"));
61
+ return;
62
+ }
63
+ console.log(chalk.bold(`
64
+ \u{1F9E0} \u5168\u90E8\u8BB0\u5FC6 (${records.length} \u6761)
65
+ `));
66
+ for (const r of records.slice(0, 20)) {
67
+ const catLabel = CATEGORY_LABELS[r.category] || r.category;
68
+ const tags = r.tags.map((t) => chalk.dim(`#${t}`)).join(" ");
69
+ console.log(` ${chalk.dim(r.id.slice(4, 22))} [${chalk.cyan(catLabel)}] ${r.content} ${tags}`);
70
+ }
71
+ if (records.length > 20) {
72
+ console.log(chalk.dim(` ... \u8FD8\u6709 ${records.length - 20} \u6761`));
73
+ }
74
+ console.log();
75
+ return;
76
+ }
77
+ const results = await searchMemories("personal", query);
78
+ if (results.length === 0) {
79
+ console.log(chalk.dim(`
80
+ \u672A\u627E\u5230\u4E0E "${query}" \u76F8\u5173\u7684\u8BB0\u5FC6
81
+ `));
82
+ return;
83
+ }
84
+ console.log(chalk.bold(`
85
+ \u{1F50D} \u641C\u7D22\u7ED3\u679C: "${query}" (${results.length} \u6761)
86
+ `));
87
+ for (const { record: r, score } of results) {
88
+ const catLabel = CATEGORY_LABELS[r.category] || r.category;
89
+ const tags = r.tags.map((t) => chalk.dim(`#${t}`)).join(" ");
90
+ const scoreStr = chalk.dim(`${Math.round(score * 100)}%`);
91
+ console.log(` ${scoreStr} [${chalk.cyan(catLabel)}] ${r.content} ${tags}`);
92
+ }
93
+ console.log();
94
+ }
95
+ },
96
+ // /memory — 记忆统计
97
+ {
98
+ name: "memory",
99
+ aliases: ["mem"],
100
+ description: "\u663E\u793A\u8BB0\u5FC6\u7CFB\u7EDF\u72B6\u6001",
101
+ category: "memory",
102
+ handler: async (_args, _ctx) => {
103
+ const stats = await getMemoryStats("personal");
104
+ console.log(chalk.bold("\n \u{1F9E0} \u8BB0\u5FC6\u7CFB\u7EDF\u72B6\u6001\n"));
105
+ console.log(` ${chalk.dim("\u5C42\u7EA7:")} \u4E2A\u4EBA (personal)`);
106
+ console.log(` ${chalk.dim("\u603B\u6761\u6570:")} ${stats.total}`);
107
+ if (Object.keys(stats.byCategory).length > 0) {
108
+ console.log(` ${chalk.dim("\u5206\u7C7B\u5206\u5E03:")}`);
109
+ for (const [cat, count] of Object.entries(stats.byCategory)) {
110
+ const label = CATEGORY_LABELS[cat] || cat;
111
+ console.log(` ${chalk.dim(label + ":")} ${count}`);
112
+ }
113
+ }
114
+ if (stats.lastExtractionAt) {
115
+ const lastTime = new Date(stats.lastExtractionAt).toLocaleString("zh-CN");
116
+ console.log(` ${chalk.dim("\u4E0A\u6B21\u63D0\u53D6:")} ${lastTime}`);
117
+ } else {
118
+ console.log(` ${chalk.dim("\u4E0A\u6B21\u63D0\u53D6:")} \u4ECE\u672A`);
119
+ }
120
+ console.log(` ${chalk.dim("\u603B\u63D0\u53D6\u6B21\u6570:")} ${stats.totalExtractions}`);
121
+ console.log();
122
+ try {
123
+ const projectStats = await getMemoryStats("project");
124
+ if (projectStats.total > 0) {
125
+ console.log(` ${chalk.dim("\u9879\u76EE\u8BB0\u5FC6:")} ${projectStats.total} \u6761`);
126
+ console.log();
127
+ }
128
+ } catch {
129
+ }
130
+ }
131
+ },
132
+ // /forget <id> — 删除记忆
133
+ {
134
+ name: "forget",
135
+ description: "\u5220\u9664\u6307\u5B9A\u8BB0\u5FC6\uFF08/forget <id>\uFF09",
136
+ category: "memory",
137
+ handler: async (args, _ctx) => {
138
+ const idFragment = args[0]?.trim();
139
+ if (!idFragment) {
140
+ console.log(chalk.dim("\n \u7528\u6CD5: /forget <id> \uFF08\u4F7F\u7528 /recall \u67E5\u770B ID\uFF09\n"));
141
+ return;
142
+ }
143
+ const records = await listMemories("personal");
144
+ const match = records.find((r) => r.id.includes(idFragment));
145
+ if (!match) {
146
+ console.log(chalk.red(`
147
+ \u672A\u627E\u5230 ID \u5305\u542B "${idFragment}" \u7684\u8BB0\u5FC6
148
+ `));
149
+ return;
150
+ }
151
+ const removed = await removeMemory("personal", match.id);
152
+ if (removed) {
153
+ console.log(chalk.green(`
154
+ \u2705 \u5DF2\u5220\u9664: ${match.content.slice(0, 60)}
155
+ `));
156
+ } else {
157
+ console.log(chalk.red(`
158
+ \u5220\u9664\u5931\u8D25
159
+ `));
160
+ }
161
+ }
162
+ },
163
+ // /mem-extract — 手动触发提取
164
+ {
165
+ name: "mem-extract",
166
+ aliases: ["extract"],
167
+ description: "\u4ECE\u5F53\u524D\u4F1A\u8BDD\u63D0\u53D6\u8BB0\u5FC6",
168
+ category: "memory",
169
+ handler: async (_args, ctx) => {
170
+ if (ctx.chatHistory.length < 4) {
171
+ console.log(chalk.dim("\n \u5BF9\u8BDD\u592A\u77ED\uFF08\u81F3\u5C11 4 \u6761\u6D88\u606F\uFF09\uFF0C\u6682\u65E0\u6CD5\u63D0\u53D6\n"));
172
+ return;
173
+ }
174
+ console.log(chalk.dim("\n \u{1F504} \u6B63\u5728\u4ECE\u5F53\u524D\u4F1A\u8BDD\u63D0\u53D6\u8BB0\u5FC6...\n"));
175
+ try {
176
+ const { extractMemories } = await import("./extractor-QV53W2YJ.js");
177
+ const extracted = await extractMemories(
178
+ ctx.chatHistory,
179
+ ctx.getClient(),
180
+ ctx.config,
181
+ "personal"
182
+ );
183
+ if (extracted.length === 0) {
184
+ console.log(chalk.dim(" \u672A\u53D1\u73B0\u65B0\u7684\u8BB0\u5FC6\u5185\u5BB9\n"));
185
+ } else {
186
+ console.log(chalk.green(` \u2705 \u63D0\u53D6\u4E86 ${extracted.length} \u6761\u8BB0\u5FC6:
187
+ `));
188
+ for (const r of extracted) {
189
+ const catLabel = CATEGORY_LABELS[r.category] || r.category;
190
+ console.log(` [${chalk.cyan(catLabel)}] ${r.content}`);
191
+ }
192
+ console.log();
193
+ }
194
+ } catch (err) {
195
+ console.log(chalk.red(` \u63D0\u53D6\u5931\u8D25: ${err instanceof Error ? err.message : String(err)}
196
+ `));
197
+ }
198
+ }
199
+ }
200
+ ];
201
+ }
202
+ function extractAutoTags(content) {
203
+ const tags = [];
204
+ const lower = content.toLowerCase();
205
+ const techTerms = [
206
+ "typescript",
207
+ "javascript",
208
+ "python",
209
+ "react",
210
+ "vue",
211
+ "node",
212
+ "git",
213
+ "npm",
214
+ "pnpm",
215
+ "docker",
216
+ "api",
217
+ "css",
218
+ "html",
219
+ "json",
220
+ "markdown",
221
+ "bash",
222
+ "linux",
223
+ "macos"
224
+ ];
225
+ for (const term of techTerms) {
226
+ if (lower.includes(term)) tags.push(term);
227
+ }
228
+ return tags.slice(0, 3);
229
+ }
230
+ export {
231
+ createMemorySlashCommands
232
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ HYPERCORE_DIR,
3
+ loadConfig
4
+ } from "./chunk-V5UHPPSY.js";
5
+ export {
6
+ HYPERCORE_DIR,
7
+ loadConfig
8
+ };
@@ -0,0 +1,24 @@
1
+ import {
2
+ listLines,
3
+ loadAgent,
4
+ loadFile,
5
+ loadLine,
6
+ loadPWP,
7
+ loadSkill,
8
+ parseAgent,
9
+ parsePWP,
10
+ parseProductionLine,
11
+ parseSkill
12
+ } from "./chunk-WHLVZCQY.js";
13
+ export {
14
+ listLines,
15
+ loadAgent,
16
+ loadFile,
17
+ loadLine,
18
+ loadPWP,
19
+ loadSkill,
20
+ parseAgent,
21
+ parsePWP,
22
+ parseProductionLine,
23
+ parseSkill
24
+ };
@@ -0,0 +1,12 @@
1
+ import {
2
+ findingsToBacklog,
3
+ runAIDiagnosis,
4
+ runRuleDiagnosis
5
+ } from "./chunk-3RPFCQKJ.js";
6
+ import "./chunk-2CMSCWQW.js";
7
+ import "./chunk-MGLJ53QN.js";
8
+ export {
9
+ findingsToBacklog,
10
+ runAIDiagnosis,
11
+ runRuleDiagnosis
12
+ };
@@ -0,0 +1,58 @@
1
+ import {
2
+ CLI_VERSION,
3
+ estimateCost,
4
+ formatCost,
5
+ showBanner,
6
+ showCapabilityQuickGuide,
7
+ showCheckpoint,
8
+ showError,
9
+ showExitSummary,
10
+ showLineList,
11
+ showREPLHelp,
12
+ showREPLWelcome,
13
+ showResponseStats,
14
+ showRunComplete,
15
+ showSessionCost,
16
+ showSlashCommandsGrouped,
17
+ showStationComplete,
18
+ showStationRetry,
19
+ showStationSkipped,
20
+ showStationStart,
21
+ showTaskList,
22
+ showTeamBanner,
23
+ showTeamStatus,
24
+ showThinking,
25
+ showToolCall,
26
+ showToolCallDone,
27
+ showWelcome
28
+ } from "./chunk-R3GPQC7I.js";
29
+ import "./chunk-BE46C7JW.js";
30
+ import "./chunk-RNG3K465.js";
31
+ export {
32
+ CLI_VERSION,
33
+ estimateCost,
34
+ formatCost,
35
+ showBanner,
36
+ showCapabilityQuickGuide,
37
+ showCheckpoint,
38
+ showError,
39
+ showExitSummary,
40
+ showLineList,
41
+ showREPLHelp,
42
+ showREPLWelcome,
43
+ showResponseStats,
44
+ showRunComplete,
45
+ showSessionCost,
46
+ showSlashCommandsGrouped,
47
+ showStationComplete,
48
+ showStationRetry,
49
+ showStationSkipped,
50
+ showStationStart,
51
+ showTaskList,
52
+ showTeamBanner,
53
+ showTeamStatus,
54
+ showThinking,
55
+ showToolCall,
56
+ showToolCallDone,
57
+ showWelcome
58
+ };
@@ -0,0 +1,129 @@
1
+ import {
2
+ DEFAULT_EXTRACTION_CONFIG,
3
+ addMemory,
4
+ loadStore,
5
+ markExtraction
6
+ } from "./chunk-KRPOPWGA.js";
7
+ import "./chunk-V5UHPPSY.js";
8
+
9
+ // src/memory/extractor.ts
10
+ var EXTRACTION_SYSTEM = `You are a memory extraction assistant. Extract concise, durable facts from conversations.
11
+ Output valid JSON only. No prose.`;
12
+ function buildExtractionPrompt(messages, existingTopics) {
13
+ const recent = messages.slice(-8).map(
14
+ (m) => `[${m.role}]: ${m.content.slice(0, 300)}`
15
+ ).join("\n\n");
16
+ const knownStr = existingTopics.length > 0 ? `Already known (skip duplicates): ${existingTopics.join(", ")}` : "No existing memories yet.";
17
+ return `Extract up to 5 memories from this conversation.
18
+ Focus on: user preferences, named tools/projects, recurring patterns, key decisions.
19
+ ${knownStr}
20
+
21
+ Rules:
22
+ - content: \u2264100 chars, specific and durable
23
+ - category: preference|decision|entity|pattern|fact|convention
24
+ - tags: 1-3 lowercase keywords
25
+ - confidence: 0.0-1.0 (skip if < 0.6)
26
+
27
+ Conversation:
28
+ ${recent}
29
+
30
+ Respond JSON only:
31
+ {"memories": [{"content":"...","category":"...","tags":[...],"confidence":0.9}]}`;
32
+ }
33
+ async function extractMemories(history, client, config, layer, opts) {
34
+ if (history.length < 4) return [];
35
+ const store = await loadStore(layer, opts);
36
+ const existingTopics = store.records.slice(-20).map((r) => r.content.slice(0, 40));
37
+ const userPrompt = buildExtractionPrompt(history, existingTopics);
38
+ let rawOutput;
39
+ if (config.modelConfig.sdkType === "openai") {
40
+ const { streamOpenAIChat } = await import("./openai-compat-UQWJXBEK.js");
41
+ const OpenAI = (await import("openai")).default;
42
+ const openaiClient = client;
43
+ const result = await streamOpenAIChat(openaiClient, [
44
+ { role: "system", content: EXTRACTION_SYSTEM },
45
+ { role: "user", content: userPrompt }
46
+ ], {
47
+ model: config.modelConfig.model,
48
+ tools: [],
49
+ onChunk: () => {
50
+ },
51
+ onToolCall: () => {
52
+ }
53
+ });
54
+ rawOutput = result.content;
55
+ } else {
56
+ const { streamCallLLM } = await import("./claude-NSQ442XD.js");
57
+ const Anthropic = (await import("@anthropic-ai/sdk")).default;
58
+ const anthropicClient = client;
59
+ const result = await streamCallLLM(anthropicClient, {
60
+ systemPrompt: EXTRACTION_SYSTEM,
61
+ userPrompt,
62
+ history: [],
63
+ tools: [],
64
+ model: config.modelConfig.model,
65
+ onText: () => {
66
+ },
67
+ onToolCall: () => {
68
+ }
69
+ });
70
+ rawOutput = result.output;
71
+ }
72
+ const extracted = parseExtractionResult(rawOutput);
73
+ if (extracted.length === 0) return [];
74
+ const saved = [];
75
+ for (const mem of extracted) {
76
+ if (mem.confidence < DEFAULT_EXTRACTION_CONFIG.minConfidence) continue;
77
+ if (!mem.content || mem.content.length < 5) continue;
78
+ const record = await addMemory(layer, {
79
+ layer,
80
+ category: mem.category,
81
+ content: mem.content.slice(0, 500),
82
+ tags: mem.tags.slice(0, 5),
83
+ confidence: mem.confidence
84
+ }, opts);
85
+ saved.push(record);
86
+ }
87
+ await markExtraction(layer, opts);
88
+ return saved;
89
+ }
90
+ function parseExtractionResult(output) {
91
+ try {
92
+ const jsonMatch = output.match(/\{[\s\S]*"memories"[\s\S]*\}/);
93
+ if (!jsonMatch) return [];
94
+ const parsed = JSON.parse(jsonMatch[0]);
95
+ if (!Array.isArray(parsed.memories)) return [];
96
+ const validCategories = /* @__PURE__ */ new Set([
97
+ "preference",
98
+ "decision",
99
+ "entity",
100
+ "pattern",
101
+ "fact",
102
+ "convention"
103
+ ]);
104
+ return parsed.memories.filter(
105
+ (m) => typeof m.content === "string" && typeof m.confidence === "number" && validCategories.has(m.category)
106
+ ).map((m) => ({
107
+ content: String(m.content).slice(0, 500),
108
+ category: m.category,
109
+ tags: Array.isArray(m.tags) ? m.tags.map(String).slice(0, 5) : [],
110
+ confidence: Math.min(1, Math.max(0, Number(m.confidence)))
111
+ }));
112
+ } catch {
113
+ return [];
114
+ }
115
+ }
116
+ function shouldExtract(roundCount, everyN = 3) {
117
+ return roundCount > 0 && roundCount % everyN === 0;
118
+ }
119
+ function triggerAutoExtraction(history, client, config, layers) {
120
+ for (const layer of layers) {
121
+ extractMemories(history, client, config, layer).catch(() => {
122
+ });
123
+ }
124
+ }
125
+ export {
126
+ extractMemories,
127
+ shouldExtract,
128
+ triggerAutoExtraction
129
+ };
@@ -0,0 +1,180 @@
1
+ import {
2
+ estimateCost,
3
+ formatCost,
4
+ showError
5
+ } from "./chunk-R3GPQC7I.js";
6
+ import "./chunk-BE46C7JW.js";
7
+ import "./chunk-RNG3K465.js";
8
+ import {
9
+ HYPERCORE_DIR,
10
+ loadConfig
11
+ } from "./chunk-V5UHPPSY.js";
12
+
13
+ // src/commands/history.ts
14
+ import { existsSync } from "fs";
15
+ import { readdir, readFile } from "fs/promises";
16
+ import { join } from "path";
17
+ import chalk from "chalk";
18
+ async function historyCommand() {
19
+ if (!existsSync(HYPERCORE_DIR)) {
20
+ showError("\u8BF7\u5148\u8FD0\u884C hypercore init \u521D\u59CB\u5316");
21
+ process.exit(1);
22
+ }
23
+ let config;
24
+ try {
25
+ config = await loadConfig();
26
+ } catch (err) {
27
+ showError(err instanceof Error ? err.message : String(err));
28
+ process.exit(1);
29
+ }
30
+ const outputDir = config.outputDir;
31
+ if (!existsSync(outputDir)) {
32
+ console.log(chalk.dim("\n \u8FD8\u6CA1\u6709\u8FD0\u884C\u8BB0\u5F55\u3002\u8BD5\u8BD5 hyper run \u70ED\u70B9\u8FFD\u8E2A\n"));
33
+ return;
34
+ }
35
+ let files;
36
+ try {
37
+ files = await readdir(outputDir);
38
+ } catch {
39
+ console.log(chalk.dim("\n \u65E0\u6CD5\u8BFB\u53D6\u8F93\u51FA\u76EE\u5F55\n"));
40
+ return;
41
+ }
42
+ const jsonFiles = files.filter((f) => f.endsWith(".run.json")).sort().reverse().slice(0, 20);
43
+ if (jsonFiles.length === 0) {
44
+ console.log(chalk.dim("\n \u8FD8\u6CA1\u6709\u8FD0\u884C\u8BB0\u5F55\u3002\u8BD5\u8BD5 hyper run \u70ED\u70B9\u8FFD\u8E2A\n"));
45
+ return;
46
+ }
47
+ console.log(chalk.bold("\n \u{1F4CB} \u8FD0\u884C\u5386\u53F2\uFF08\u6700\u8FD1 20 \u6761\uFF09\n"));
48
+ for (const file of jsonFiles) {
49
+ try {
50
+ const content = await readFile(join(outputDir, file), "utf-8");
51
+ const meta = JSON.parse(content);
52
+ const startDate = new Date(meta.startTime);
53
+ const endDate = new Date(meta.endTime);
54
+ const durationMs = endDate.getTime() - startDate.getTime();
55
+ const durationStr = durationMs < 6e4 ? `${(durationMs / 1e3).toFixed(0)}s` : `${(durationMs / 6e4).toFixed(1)}min`;
56
+ const totalTokens = (meta.totalTokens?.inputTokens || 0) + (meta.totalTokens?.outputTokens || 0);
57
+ const cost = estimateCost(
58
+ meta.model,
59
+ meta.totalTokens?.inputTokens || 0,
60
+ meta.totalTokens?.outputTokens || 0
61
+ );
62
+ const dateStr = startDate.toLocaleDateString("zh-CN", {
63
+ month: "2-digit",
64
+ day: "2-digit",
65
+ hour: "2-digit",
66
+ minute: "2-digit"
67
+ });
68
+ const costStr = cost ? formatCost(cost) : "";
69
+ const stationCount = meta.stations?.length || 0;
70
+ const fileId = file.replace(".run.json", "");
71
+ console.log(
72
+ ` ${chalk.dim(dateStr)} ${chalk.bold(meta.lineName)} ` + chalk.dim(`${stationCount}\u5DE5\u4F4D \xB7 ${durationStr} \xB7 ${totalTokens.toLocaleString()} tokens${costStr ? ` \xB7 ${costStr}` : ""}`)
73
+ );
74
+ if (meta.userInputs && Object.keys(meta.userInputs).length > 0) {
75
+ const inputStr = Object.entries(meta.userInputs).map(([k, v]) => `${k}=${v}`).join(", ");
76
+ console.log(chalk.dim(` ${inputStr}`));
77
+ }
78
+ } catch {
79
+ }
80
+ }
81
+ console.log(chalk.dim(`
82
+ \u{1F4A1} \u67E5\u770B\u8BE6\u60C5: hyper history view <\u65E5\u671F-\u7EBF\u540D>`));
83
+ console.log(chalk.dim(` \u8F93\u51FA\u76EE\u5F55\uFF1A${outputDir}
84
+ `));
85
+ }
86
+ async function historyViewCommand(fileId) {
87
+ if (!existsSync(HYPERCORE_DIR)) {
88
+ showError("\u8BF7\u5148\u8FD0\u884C hypercore init \u521D\u59CB\u5316");
89
+ process.exit(1);
90
+ }
91
+ let config;
92
+ try {
93
+ config = await loadConfig();
94
+ } catch (err) {
95
+ showError(err instanceof Error ? err.message : String(err));
96
+ process.exit(1);
97
+ }
98
+ const outputDir = config.outputDir;
99
+ let jsonPath = join(outputDir, `${fileId}.run.json`);
100
+ if (!existsSync(jsonPath)) {
101
+ try {
102
+ const files = await readdir(outputDir);
103
+ const match = files.find((f) => f.includes(fileId) && f.endsWith(".run.json"));
104
+ if (match) {
105
+ jsonPath = join(outputDir, match);
106
+ } else {
107
+ showError(`\u672A\u627E\u5230\u8FD0\u884C\u8BB0\u5F55: ${fileId}`);
108
+ console.log(chalk.dim(" \u4F7F\u7528 hyper history \u67E5\u770B\u53EF\u7528\u8BB0\u5F55\n"));
109
+ return;
110
+ }
111
+ } catch {
112
+ showError(`\u65E0\u6CD5\u8BFB\u53D6\u8F93\u51FA\u76EE\u5F55`);
113
+ return;
114
+ }
115
+ }
116
+ let content;
117
+ try {
118
+ content = await readFile(jsonPath, "utf-8");
119
+ } catch {
120
+ showError(`\u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6: ${jsonPath}`);
121
+ return;
122
+ }
123
+ const meta = JSON.parse(content);
124
+ const startDate = new Date(meta.startTime);
125
+ const endDate = new Date(meta.endTime);
126
+ const durationMs = endDate.getTime() - startDate.getTime();
127
+ const durationStr = durationMs < 6e4 ? `${(durationMs / 1e3).toFixed(0)}s` : `${(durationMs / 6e4).toFixed(1)}min`;
128
+ const totalTokens = (meta.totalTokens?.inputTokens || 0) + (meta.totalTokens?.outputTokens || 0);
129
+ const cost = estimateCost(
130
+ meta.model,
131
+ meta.totalTokens?.inputTokens || 0,
132
+ meta.totalTokens?.outputTokens || 0
133
+ );
134
+ console.log(chalk.bold(`
135
+ \u{1F4CB} \u8FD0\u884C\u8BE6\u60C5\uFF1A${meta.lineName}
136
+ `));
137
+ console.log(chalk.dim(` \u65F6\u95F4: ${startDate.toLocaleString("zh-CN")}`));
138
+ console.log(chalk.dim(` \u8017\u65F6: ${durationStr}`));
139
+ console.log(chalk.dim(` \u6A21\u578B: ${meta.model}`));
140
+ console.log(chalk.dim(` Token: ${totalTokens.toLocaleString()} (\u8F93\u5165 ${(meta.totalTokens?.inputTokens || 0).toLocaleString()} + \u8F93\u51FA ${(meta.totalTokens?.outputTokens || 0).toLocaleString()})`));
141
+ if (cost) {
142
+ console.log(chalk.dim(` \u8D39\u7528: ${formatCost(cost)}`));
143
+ }
144
+ if (meta.userInputs && Object.keys(meta.userInputs).length > 0) {
145
+ console.log(chalk.bold("\n \u8F93\u5165\u53C2\u6570\uFF1A"));
146
+ for (const [key, val] of Object.entries(meta.userInputs)) {
147
+ console.log(chalk.dim(` ${key}: ${val}`));
148
+ }
149
+ }
150
+ if (meta.stations && meta.stations.length > 0) {
151
+ console.log(chalk.bold(`
152
+ \u5DE5\u4F4D\u6267\u884C\u8BB0\u5F55 (${meta.stations.length} \u4E2A)\uFF1A
153
+ `));
154
+ for (const station of meta.stations) {
155
+ const stationTokens = (station.tokens?.inputTokens || 0) + (station.tokens?.outputTokens || 0);
156
+ console.log(
157
+ chalk.blue(` \u{1F4CD} \u5DE5\u4F4D ${station.index}\uFF1A${station.name}`) + chalk.dim(` [${station.agent}]`) + chalk.dim(` ${stationTokens.toLocaleString()} tokens`)
158
+ );
159
+ if (station.toolCalls && station.toolCalls.length > 0) {
160
+ for (const tc of station.toolCalls) {
161
+ console.log(chalk.dim(` \u{1F527} ${tc.toolName}`));
162
+ }
163
+ }
164
+ if (station.output) {
165
+ const preview = station.output.replace(/\n/g, " ").slice(0, 200);
166
+ console.log(chalk.dim(` \u{1F4C4} ${preview}${station.output.length > 200 ? "\u2026" : ""}`));
167
+ }
168
+ console.log();
169
+ }
170
+ }
171
+ const mdPath = jsonPath.replace(".run.json", ".md");
172
+ if (existsSync(mdPath)) {
173
+ console.log(chalk.dim(` \u{1F4C4} \u6210\u54C1\u6587\u4EF6\uFF1A${mdPath}`));
174
+ }
175
+ console.log();
176
+ }
177
+ export {
178
+ historyCommand,
179
+ historyViewCommand
180
+ };
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node