Skip to content

Commit 4898d20

Browse files
author
linyuan.yang
committed
insight
1 parent efda746 commit 4898d20

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

packages/channel.xiaoai/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/scorpio.ai/src/Insight/InsightService.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { parseSkill, isValidSkillDirectory } from "../Skills/parser";
99
import { formatSkillItems } from "../Skills/formatSkillItems";
1010
import { Skill } from "../Skills/types";
1111
import { InsightAction } from "./Extractor/IInsightExtractor";
12-
import { UsageTracker } from "../Utils/UsageTracker";
12+
import { UsageTracker, UsageState } from "../Utils/UsageTracker";
1313
import { HybridSearcher } from "../Retrieval";
1414
import { IInsightExtractor } from "./Extractor/IInsightExtractor";
1515

@@ -41,7 +41,6 @@ export class InsightService implements IInsightService {
4141

4242
@init()
4343
async initialize(): Promise<void> {
44-
this.logger?.debug(`initialize: insightDir=${this.insightDir}, limit=${this.insightLimit}, staleDays=${this.staleDays}, archiveDays=${this.archiveDays}, hasEmbeddings=${!!this.embeddings}`);
4544
this.curate();
4645
}
4746

@@ -52,13 +51,10 @@ export class InsightService implements IInsightService {
5251
}
5352

5453
async extractFromConversation(userMessage: string, assistantMessages?: string[]): Promise<void> {
55-
this.logger?.debug(`extractFromConversation: userMessage length=${userMessage.length}, assistantMessages=${assistantMessages?.length ?? 0}`);
5654
try {
5755
const insights = this.getAllInsights();
5856
const existingNames = insights.map(s => s.name);
59-
this.logger?.debug(`extractFromConversation: existing insights=[${existingNames.join(', ')}]`);
6057
const extracted = await this.extractor.extract(userMessage, assistantMessages ?? [], existingNames);
61-
this.logger?.debug(`extractFromConversation: extractor returned ${extracted.length} items`);
6258

6359
for (const item of extracted) {
6460
if (item.action === InsightAction.Delete) {
@@ -111,7 +107,6 @@ ${item.content}`;
111107
async getRelevantInsights(query: string, limit?: number): Promise<Skill[]> {
112108
const max = limit ?? this.insightLimit!;
113109
const insights = this.getAllInsights();
114-
this.logger?.debug(`getRelevantInsights: query="${query.slice(0, 80)}", total=${insights.length}, max=${max}`);
115110
if (insights.length === 0) return [];
116111

117112
let selected: Skill[];
@@ -120,15 +115,13 @@ ${item.content}`;
120115
} else {
121116
selected = (await this.searcher.search(query, insights, toSearchable, max)).map(r => r.item);
122117
}
123-
this.logger?.debug(`getRelevantInsights: selected ${selected.length} insights: [${selected.map(s => s.name).join(', ')}]`);
124118
return selected;
125119
}
126120

127121
// ── Curator ──
128122

129123
private curate(): void {
130124
const insights = this.getAllInsights();
131-
this.logger?.debug(`curate: checking ${insights.length} insights for staleness/archival`);
132125
for (const insight of insights) {
133126
const tracker = new UsageTracker(insight.path);
134127
const usage = tracker.get();
@@ -138,8 +131,8 @@ ${item.content}`;
138131

139132
if (daysSince >= this.archiveDays!) {
140133
this.archiveInsight(insight, usage);
141-
} else if (daysSince >= this.staleDays! && usage.state === 'active') {
142-
usage.state = 'stale';
134+
} else if (daysSince >= this.staleDays! && usage.state === UsageState.Active) {
135+
usage.state = UsageState.Stale;
143136
tracker.save(usage);
144137
this.logger?.info(`Insight marked stale: ${insight.name} (${Math.round(daysSince)}d inactive)`);
145138
}
@@ -154,7 +147,7 @@ ${item.content}`;
154147
const archiveDest = path.join(archiveBase, `${insight.name}_${timestamp}`);
155148
fs.renameSync(insight.path, archiveDest);
156149
if (usage) {
157-
usage.state = 'archived';
150+
usage.state = UsageState.Archived;
158151
fs.writeFileSync(path.join(archiveDest, '.usage.json'), JSON.stringify(usage, null, 2), 'utf-8');
159152
}
160153
this.logger?.info(`Insight auto-archived: ${insight.name}${archiveDest}`);
@@ -176,7 +169,7 @@ ${item.content}`;
176169
const insight = parseSkill(dir);
177170
if (!insight) continue;
178171
const usage = new UsageTracker(dir).get();
179-
if (usage?.state === 'archived') continue;
172+
if (usage?.state === UsageState.Archived) continue;
180173
insights.push(insight);
181174
}
182175
} catch (e: any) {

packages/scorpio.ai/src/Utils/UsageTracker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import fs from 'fs';
22
import path from 'path';
33

4+
export const enum UsageState {
5+
Active = 'active',
6+
Stale = 'stale',
7+
Archived = 'archived',
8+
}
9+
410
export interface UsageData {
511
useCount: number;
612
viewCount: number;
713
patchCount: number;
814
createdAt: string;
915
lastUsedAt?: string;
1016
lastViewedAt?: string;
11-
state: 'active' | 'stale' | 'archived';
17+
state: UsageState;
1218
pinned: boolean;
1319
}
1420

@@ -54,7 +60,7 @@ export class UsageTracker {
5460
viewCount: 0,
5561
patchCount: 0,
5662
createdAt: new Date().toISOString(),
57-
state: 'active',
63+
state: UsageState.Active,
5864
pinned: false,
5965
};
6066
this.save(data);

0 commit comments

Comments
 (0)