release: ship v1.5.0 with on-device writing suggestions
Some checks failed
deploy-site / deploy (push) Failing after 33s
portable-unsigned / portable-windows (push) Failing after 4m7s
release / release-windows (push) Failing after 3m16s

Adds next-sentence suggestions while typing, weekly input insights and a
personal phrase memory to the desktop app, and fixes custom instructions so
they process the text instead of inserting the instruction's own wording.
Local model requests are now bounded and individually cancellable.

Bumps the product version to 1.5.0 (Android/iOS build 1050000), refreshes the
landing and web download links, and records the new INPUT feature rows and the
open verification gaps in the infrastructure map.
This commit is contained in:
Yun Chan 2026-09-23 16:04:27 +09:00
parent 99f06c253c
commit 5c11ee2fde
104 changed files with 14410 additions and 174 deletions

View file

@ -0,0 +1,392 @@
// src/main/services/PersonalGraphService.ts
//
// 개인 그래프 — 사용자의 문장을 노드로, 관계를 엣지로 저장하고 제안 문맥을 끌어온다.
//
// 왜: n-gram 문자열 조회는 "같은 꼬리 뒤" 만 찾는다. 실제 글은 관계로 이어진다 —
// 어떤 문장은 늘 다른 문장 뒤에 오고(follows), 어떤 문장들은 용어를 공유한다
// (shares_terms). 그 관계를 저장하면 접두가 조금 어긋나도 관련 문맥을 쓸 수 있다.
//
// 전부 로컬 SQLite 다 (임베딩/네트워크 없음). 학습 동의(inputLearnTypedText)가 없으면
// 표본이 저장되지 않으므로 그래프도 비어 있다.
import {
SHARES_TERMS_MIN_SIMILARITY,
buildSequenceEdges,
continuationsFrom,
extractTerms,
jaccard,
rankRelated,
splitSentences,
type GraphContext,
type PersonalGraphQuery,
type PersonalGraphStats,
type PhraseSource,
type RelatedCandidate
} from '@d3ro/core/personal-graph'
import { prefixTail } from '@d3ro/core/input-intelligence'
import { and, desc, eq, gte, inArray, sql } from 'drizzle-orm'
import { getDatabase } from '../db'
import { personalPhrases, phraseEdges } from '../db/schema'
import { getLogger } from './LoggerService'
const logger = getLogger('PersonalGraphService')
/** 계약 타입은 core 정본을 따른다 (렌더러/프리로드와 공유). */
export type { PersonalGraphQuery, PersonalGraphStats }
/** 용어 공유 엣지 백필 시 한 번에 볼 노드 수. */
const MAINTENANCE_NODE_LIMIT = 300
/** 관계 조회에서 최근 노드를 훑는 수. */
const TERM_SCAN_LIMIT = 400
class PersonalGraphService {
/**
* 텍스트를 그래프에 반영한다.
*
* 문장마다 노드를 upsert 하고, 연속한 문장 쌍을 follows 엣지로, 용어를 충분히
* 공유하는 쌍을 shares_terms 엣지로 남긴다.
*/
indexText(
text: string,
meta: { source: PhraseSource; appName?: string | null; at?: number }
): void {
const sentences = splitSentences(text)
if (sentences.length === 0) return
const at = meta.at ?? Date.now()
try {
const db = getDatabase()
for (const sentence of sentences) {
const terms = extractTerms(sentence)
db.insert(personalPhrases)
.values({
id: crypto.randomUUID(),
phrase: sentence,
count: 1,
source: meta.source,
lastUsedAt: at,
createdAt: at,
terms: JSON.stringify(terms),
appName: meta.appName ?? null
})
.onConflictDoUpdate({
target: personalPhrases.phrase,
set: {
count: sql`${personalPhrases.count} + 1`,
lastUsedAt: at,
terms: JSON.stringify(terms),
appName: meta.appName ?? null
}
})
.run()
}
// follows 엣지
for (const edge of buildSequenceEdges(sentences)) {
this._upsertEdge(edge.from, edge.to, 'follows')
}
// 같은 텍스트 안에서 용어를 많이 공유하는 쌍
for (let i = 0; i < sentences.length; i += 1) {
const termsA = extractTerms(sentences[i])
for (let j = i + 1; j < sentences.length; j += 1) {
const termsB = extractTerms(sentences[j])
if (jaccard(termsA, termsB) < SHARES_TERMS_MIN_SIMILARITY) continue
this._upsertEdge(sentences[i], sentences[j], 'shares_terms')
}
}
} catch (error) {
logger.warn(`그래프 반영 실패: ${error instanceof Error ? error.message : String(error)}`)
}
}
private _upsertEdge(from: string, to: string, kind: 'follows' | 'shares_terms'): void {
const db = getDatabase()
const now = Date.now()
db.insert(phraseEdges)
.values({
id: crypto.randomUUID(),
fromPhrase: from,
toPhrase: to,
kind,
weight: 1,
updatedAt: now
})
.onConflictDoUpdate({
target: [phraseEdges.fromPhrase, phraseEdges.toPhrase, phraseEdges.kind],
set: {
weight: sql`${phraseEdges.weight} + 1`,
updatedAt: now
}
})
.run()
}
/**
* 제안 문맥을 그래프에서 끌어온다.
*
* 1) 접두 꼬리를 포함하는 노드를 찾고 그 뒤에 실제로 이어 쓴 텍스트를 뽑는다.
* 2) 그 노드들의 follows 이웃과 용어를 공유하는 노드를 순위화해 관련 문장으로 준다.
*/
retrieveContext(prefix: string, limit = 4): GraphContext {
const tail = prefixTail(prefix)
if (tail.length < 4) return { continuations: [], related: [] }
try {
const db = getDatabase()
const pattern = `%${tail.replace(/[%_\\]/gu, '')}%`
const anchorRows = db
.select()
.from(personalPhrases)
.where(sql`${personalPhrases.phrase} LIKE ${pattern}`)
.orderBy(desc(personalPhrases.lastUsedAt))
.limit(20)
.all()
if (anchorRows.length === 0) return { continuations: [], related: [] }
const anchorTexts = anchorRows.map((row) => row.phrase)
const continuations = continuationsFrom(anchorTexts, tail, 3)
const anchorTerms = new Set<string>()
for (const row of anchorRows) {
for (const term of parseTerms(row.terms)) anchorTerms.add(term)
}
const candidates: RelatedCandidate[] = []
const seen = new Set<string>(anchorTexts)
// (a) follows 이웃 — 가장 강한 관계
const edgeRows = db
.select()
.from(phraseEdges)
.where(
and(inArray(phraseEdges.fromPhrase, anchorTexts), eq(phraseEdges.kind, 'follows'))
)
.orderBy(desc(phraseEdges.weight))
.limit(40)
.all()
for (const edge of edgeRows) {
if (seen.has(edge.toPhrase)) continue
seen.add(edge.toPhrase)
candidates.push({
text: edge.toPhrase,
terms: [],
weight: edge.weight * 2,
lastUsedAt: null
})
}
// (b) 용어 공유 — 최근 노드를 훑어 유사도가 높은 것
const recentNodes = db
.select()
.from(personalPhrases)
.orderBy(desc(personalPhrases.lastUsedAt))
.limit(TERM_SCAN_LIMIT)
.all()
for (const node of recentNodes) {
if (seen.has(node.phrase)) continue
const terms = parseTerms(node.terms)
if (terms.length === 0) continue
const similarity = jaccard([...anchorTerms], terms)
if (similarity < SHARES_TERMS_MIN_SIMILARITY) continue
seen.add(node.phrase)
candidates.push({
text: node.phrase,
terms,
weight: 0,
lastUsedAt: node.lastUsedAt
})
}
const related = rankRelated([...anchorTerms], candidates, limit)
return { continuations, related }
} catch (error) {
logger.warn(
`그래프 문맥 조회 실패: ${error instanceof Error ? error.message : String(error)}`
)
return { continuations: [], related: [] }
}
}
/** 용어 공유 엣지를 백필한다 (기존 노드들 사이 관계 보강). */
runMaintenance(limit = MAINTENANCE_NODE_LIMIT): number {
try {
const db = getDatabase()
const nodes = db
.select()
.from(personalPhrases)
.orderBy(desc(personalPhrases.lastUsedAt))
.limit(limit)
.all()
let created = 0
for (let i = 0; i < nodes.length; i += 1) {
const termsA = parseTerms(nodes[i].terms)
if (termsA.length === 0) continue
for (let j = i + 1; j < nodes.length; j += 1) {
const termsB = parseTerms(nodes[j].terms)
if (termsB.length === 0) continue
if (jaccard(termsA, termsB) < SHARES_TERMS_MIN_SIMILARITY) continue
this._upsertEdge(nodes[i].phrase, nodes[j].phrase, 'shares_terms')
created += 1
if (created >= 200) return created
}
}
if (created > 0) logger.info(`그래프 유지보수: shares_terms 엣지 ${created}개 생성`)
return created
} catch (error) {
logger.warn(`그래프 유지보수 실패: ${error instanceof Error ? error.message : String(error)}`)
return 0
}
}
getStats(days = 30): PersonalGraphStats {
const empty: PersonalGraphStats = {
nodes: 0,
followsEdges: 0,
sharesTermsEdges: 0,
topEdges: [],
recentNodes: []
}
try {
const db = getDatabase()
const since = Date.now() - days * 86400000
const nodeCount = db
.select({ value: sql<number>`count(*)` })
.from(personalPhrases)
.get()
const follows = db
.select({ value: sql<number>`count(*)` })
.from(phraseEdges)
.where(eq(phraseEdges.kind, 'follows'))
.get()
const shares = db
.select({ value: sql<number>`count(*)` })
.from(phraseEdges)
.where(eq(phraseEdges.kind, 'shares_terms'))
.get()
const topEdges = db
.select({
from: phraseEdges.fromPhrase,
to: phraseEdges.toPhrase,
kind: phraseEdges.kind,
weight: phraseEdges.weight
})
.from(phraseEdges)
.orderBy(desc(phraseEdges.weight))
.limit(12)
.all()
const recentNodes = db
.select()
.from(personalPhrases)
.where(gte(personalPhrases.createdAt, since))
.orderBy(desc(personalPhrases.lastUsedAt))
.limit(20)
.all()
return {
nodes: Number(nodeCount?.value ?? 0),
followsEdges: Number(follows?.value ?? 0),
sharesTermsEdges: Number(shares?.value ?? 0),
topEdges,
recentNodes: recentNodes.map((row) => ({
text: row.phrase,
terms: parseTerms(row.terms),
count: row.count,
appName: row.appName
}))
}
} catch (error) {
logger.warn(`그래프 통계 실패: ${error instanceof Error ? error.message : String(error)}`)
return empty
}
}
/** 특정 텍스트 주변의 그래프를 조회한다 (설정/지식베이스 UI). */
query(text: string, limit = 12): PersonalGraphQuery {
try {
const db = getDatabase()
const needle = text.trim()
if (needle.length < 2) return { anchors: [], neighbors: [] }
const pattern = `%${needle.replace(/[%_\\]/gu, '')}%`
const anchors = db
.select()
.from(personalPhrases)
.where(sql`${personalPhrases.phrase} LIKE ${pattern}`)
.orderBy(desc(personalPhrases.lastUsedAt))
.limit(6)
.all()
if (anchors.length === 0) return { anchors: [], neighbors: [] }
const anchorTexts = anchors.map((row) => row.phrase)
const neighbors = db
.select({
text: phraseEdges.toPhrase,
kind: phraseEdges.kind,
weight: phraseEdges.weight
})
.from(phraseEdges)
.where(inArray(phraseEdges.fromPhrase, anchorTexts))
.orderBy(desc(phraseEdges.weight))
.limit(limit)
.all()
return {
anchors: anchors.map((row) => ({
text: row.phrase,
terms: parseTerms(row.terms),
count: row.count
})),
neighbors
}
} catch (error) {
logger.warn(`그래프 조회 실패: ${error instanceof Error ? error.message : String(error)}`)
return { anchors: [], neighbors: [] }
}
}
clearAll(): void {
try {
const db = getDatabase()
db.delete(phraseEdges).run()
logger.info('개인 그래프 엣지 전체 삭제')
} catch (error) {
logger.warn(`그래프 삭제 실패: ${error instanceof Error ? error.message : String(error)}`)
}
}
}
/** DB 의 terms 컬럼(JSON)을 안전하게 파싱한다. */
function parseTerms(raw: string | null): string[] {
if (!raw) return []
try {
const parsed = JSON.parse(raw) as unknown
if (!Array.isArray(parsed)) return []
return parsed.filter((value): value is string => typeof value === 'string')
} catch {
return []
}
}
let instance: PersonalGraphService | null = null
export function getPersonalGraphService(): PersonalGraphService {
if (!instance) instance = new PersonalGraphService()
return instance
}
export function resetPersonalGraphServiceForTests(): void {
instance = null
}