feat: v2.2.173-193 — 4인 팀 운영 슬래시 13개 + ASTRA 검증 엔진 6종
4인 팀 운영 슬래시 (v2.2.173~189):
- 일과 리듬: /morning, /evening, /weekly, /standup
- 트래커 (event-sourced .astra/*.jsonl): /runway, /customers, /hire
- 작업·결정: /task, /blocked, /onesie, /decisions
- 외부 출력: /draft, /feedback
- 분석: /cohort (MoM 추세)
ASTRA 추론·검색 엔진 (v2.2.183~192):
- v2.2.183 Conflict Surface — scoring.conflictSeverity 를 [CONFLICT WARNINGS] 블록으로
서피스 + 교차-문서 발산(Jaccard) 감지
- v2.2.184 Chain-of-Verification — [VERIFICATION CHECKLIST] 답변 작성 전 그라운딩 자기 점검
(instructional, strictMode 옵션)
- v2.2.185 Actionability Scoring — 최근 슬래시 명령 + 열린 파일 신호로 검색 결과 재가중
- v2.2.186 Temporal Markers + Distillation Loop — LongTerm/Episodic 만료 필터 +
30일+ stale episode → LongTerm 'episode-digest' 승급 (수동 /memory distill + 세션 종료 자동)
- v2.2.187 Hierarchical Context Window + LLM Semantic Re-rank — 3-level 추상도 매칭
+ 토큰 예산 통과 후 LLM 1회로 의도-부합 재정렬 (opt-in)
- v2.2.190 Intent Clarification + Citation Trace — 모호 차원 감지 시 역질문 우선
+ 답변 끝 사용 출처 한 줄 정리
- v2.2.191 Post-hoc Self-Check — 답변 완료 후 별도 LLM 호출 1회로 답함/그라운딩/모순 평가,
footer 한 줄로 표시 (opt-in, semantic re-rank 와 같은 안전 fallback 패턴)
- v2.2.192 Terminology Dictionary — .astra/glossary.md 사용자 편집 파일 + Term Check
지침 통합 + /glossary init/path/reload
- v2.2.193 /help — 카테고리별 명령 목록 + 6종 verification 블록 현재 on/off
신규 모듈:
- src/retrieval/{conflictBlock,coveBlock,actionabilityScoring,hierarchicalLevel,
semanticRerank,intentClarification,citationTrace,terminologyBlock}.ts
- src/memory/distillation.ts + types.ts 에 expiresAt/promoted/episode-digest 추가
- src/agent/postHocSelfCheck.ts
- src/features/{customers,feedback,hire,runway}/*.ts (event-sourced stores)
ASTRA 검증 5종 자동 주입 (buildAstraModeSystemPrompt, casual 모드 제외):
[INTENT CLARIFICATION GUIDANCE] (답변 시작 전) → [TERMINOLOGY DICTIONARY] +
[CONFLICT WARNINGS] + [VERIFICATION CHECKLIST] (작성 중) → [CITATION TRACE] (끝)
+ 6번째: Post-hoc Self-Check footer (답변 완료 후, opt-in)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -33,6 +33,8 @@ export {
|
||||
|
||||
export {
|
||||
createTask,
|
||||
listTasks,
|
||||
TaskInput,
|
||||
CreatedTask,
|
||||
ListedTask,
|
||||
} from './tasksApi';
|
||||
|
||||
@@ -103,3 +103,67 @@ export async function createTask(
|
||||
return { ok: false, error: e?.message || String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
export interface ListedTask {
|
||||
id: string;
|
||||
title: string;
|
||||
status: 'needsAction' | 'completed';
|
||||
/** 'YYYY-MM-DD' 형식. due 가 없는 task 는 undefined. */
|
||||
due?: string;
|
||||
/** 완료 시각 ISO timestamp. status 'completed' 일 때만 있음. */
|
||||
completed?: string;
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Google Tasks 목록 조회 — /onesie 1:1 카드 등에서 멤버별 필터링용.
|
||||
*
|
||||
* 기본 default list 의 task 들을 가져온다 (완료 포함). 호출자가 클라이언트 측에서
|
||||
* 제목 prefix `[멤버]` 나 notes 의 `@멤버` / `담당: 멤버` 패턴으로 필터하면 됨.
|
||||
*/
|
||||
export async function listTasks(
|
||||
context: vscode.ExtensionContext,
|
||||
options: { taskListId?: string; showCompleted?: boolean; maxResults?: number } = {},
|
||||
): Promise<{ ok: true; tasks: ListedTask[] } | { ok: false; error: string }> {
|
||||
const tokenResult = await getFreshAccessToken(context);
|
||||
if (!tokenResult.ok) return { ok: false, error: tokenResult.error };
|
||||
|
||||
const taskListId = (options.taskListId || '@default').trim() || '@default';
|
||||
const params = new URLSearchParams({
|
||||
maxResults: String(options.maxResults ?? 100),
|
||||
showCompleted: options.showCompleted !== false ? 'true' : 'false',
|
||||
showHidden: 'true', // 완료 후 숨김 처리된 것도 포함 — 1:1 회고에 최근 완료가 중요.
|
||||
});
|
||||
const url = `${API_BASE}/lists/${encodeURIComponent(taskListId)}/tasks?${params.toString()}`;
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: { Authorization: `Bearer ${tokenResult.accessToken}` },
|
||||
signal: AbortSignal.timeout(15000),
|
||||
});
|
||||
const json: any = await res.json().catch(() => ({}));
|
||||
if (!res.ok) {
|
||||
const msg: string = json?.error?.message || `HTTP ${res.status}`;
|
||||
if (res.status === 401 || res.status === 403 || /insufficient|scope/i.test(msg)) {
|
||||
return {
|
||||
ok: false,
|
||||
error: `Tasks API 권한 부족 — "Astra: Google Calendar OAuth 연결 (쓰기)" 명령 재실행 + Tasks 스코프 동의 필요. (원인: ${msg})`,
|
||||
};
|
||||
}
|
||||
return { ok: false, error: msg };
|
||||
}
|
||||
const items: any[] = Array.isArray(json.items) ? json.items : [];
|
||||
const tasks: ListedTask[] = items.map((item: any) => ({
|
||||
id: String(item.id || ''),
|
||||
title: String(item.title || ''),
|
||||
status: item.status === 'completed' ? 'completed' : 'needsAction',
|
||||
due: typeof item.due === 'string' ? item.due.slice(0, 10) : undefined,
|
||||
completed: typeof item.completed === 'string' ? item.completed : undefined,
|
||||
notes: typeof item.notes === 'string' ? item.notes : undefined,
|
||||
}));
|
||||
return { ok: true, tasks };
|
||||
} catch (e: any) {
|
||||
return { ok: false, error: e?.message || String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* 고객사 / MRR / 갱신 트래커.
|
||||
*
|
||||
* 4인 기업의 수입 쪽 — `/runway` 가 통장과 burn 을 본다면, 여기는 *어디서 돈이 들어오나*.
|
||||
* Salesforce / HubSpot 같은 CRM 아닌 가벼운 event-sourced 로그.
|
||||
*
|
||||
* 저장 형식: JSON Lines (.jsonl) — append-only event log. 같은 customer 의 여러 이벤트를
|
||||
* 시간 순으로 재생하면 현재 상태 (MRR, 갱신일, 위험 등급) 가 나온다.
|
||||
*
|
||||
* 위치: `<workspace>/.astra/customers.jsonl`. 사람이 직접 편집 가능, grep / 백업 친화.
|
||||
* 민감 정보(고객사 이름, 매출) 포함되므로 외부로 안 보냄 — 로컬 only.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const STORE_REL_PATH = '.astra/customers.jsonl';
|
||||
|
||||
export type CustomerEventType = 'add' | 'note' | 'risk' | 'churn' | 'renew' | 'update';
|
||||
|
||||
export interface CustomerEvent {
|
||||
/** unique id — timestamp 기반. */
|
||||
id: string;
|
||||
/** ISO timestamp. */
|
||||
timestamp: string;
|
||||
/** 고객 식별자 — 소문자·trim 한 name 의 slug. 같은 customer 의 이벤트끼리 그룹. */
|
||||
customerId: string;
|
||||
/** 표시용 원본 이름 (가장 최근 이벤트의 이름 우선). */
|
||||
customerName: string;
|
||||
/** 이벤트 종류. */
|
||||
type: CustomerEventType;
|
||||
/** 월 매출 — add/renew/update 에서 사용. */
|
||||
mrr?: number;
|
||||
/** 갱신일 (YYYY-MM-DD) — add/renew/update. */
|
||||
renewalAt?: string;
|
||||
/** 요금제명 — 'pro' / 'enterprise' / 'starter' 등. */
|
||||
plan?: string;
|
||||
/** 자유 텍스트 — note / risk / churn 의 사유. */
|
||||
memo?: string;
|
||||
}
|
||||
|
||||
export type CustomerStatus = 'active' | 'at-risk' | 'churned';
|
||||
|
||||
export interface CustomerState {
|
||||
customerId: string;
|
||||
customerName: string;
|
||||
mrr: number;
|
||||
plan?: string;
|
||||
renewalAt?: string;
|
||||
status: CustomerStatus;
|
||||
startedAt: string;
|
||||
lastEventAt: string;
|
||||
eventCount: number;
|
||||
notes: { timestamp: string; type: CustomerEventType; memo: string }[];
|
||||
}
|
||||
|
||||
export function getCustomersFilePath(): string | null {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (!folders || folders.length === 0) return null;
|
||||
return path.join(folders[0].uri.fsPath, STORE_REL_PATH);
|
||||
}
|
||||
|
||||
export function customerIdFromName(name: string): string {
|
||||
return name.toLowerCase().trim().replace(/\s+/g, '-').replace(/[^\w가-힣-]/g, '');
|
||||
}
|
||||
|
||||
export function readEvents(): CustomerEvent[] {
|
||||
const filePath = getCustomersFilePath();
|
||||
if (!filePath || !fs.existsSync(filePath)) return [];
|
||||
const out: CustomerEvent[] = [];
|
||||
let content = '';
|
||||
try { content = fs.readFileSync(filePath, 'utf-8'); } catch { return []; }
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
try {
|
||||
const e = JSON.parse(trimmed);
|
||||
if (e && typeof e.id === 'string' && typeof e.customerId === 'string' && typeof e.type === 'string') {
|
||||
out.push(e as CustomerEvent);
|
||||
}
|
||||
} catch { /* skip malformed */ }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function appendEvent(event: CustomerEvent): { ok: true; filePath: string } | { ok: false; error: string } {
|
||||
const filePath = getCustomersFilePath();
|
||||
if (!filePath) return { ok: false, error: '워크스페이스 폴더가 없어 저장 불가.' };
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.appendFileSync(filePath, JSON.stringify(event) + '\n', 'utf-8');
|
||||
return { ok: true, filePath };
|
||||
} catch (e: any) {
|
||||
return { ok: false, error: e?.message || String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 이벤트 로그를 재생해 customerId 별 현재 상태 도출.
|
||||
*
|
||||
* - add: 신규 생성 (status=active, startedAt 설정)
|
||||
* - update / renew: mrr / renewalAt / plan 갱신, status=active 로 복귀 (renew 시)
|
||||
* - risk: status=at-risk, memo 누적
|
||||
* - churn: status=churned, mrr=0
|
||||
* - note: 노트 누적만, 상태 무변경
|
||||
*/
|
||||
export function computeCustomerStates(): Map<string, CustomerState> {
|
||||
const events = readEvents().slice().sort((a, b) => (a.timestamp || '').localeCompare(b.timestamp || ''));
|
||||
const states = new Map<string, CustomerState>();
|
||||
for (const e of events) {
|
||||
let s = states.get(e.customerId);
|
||||
if (!s) {
|
||||
if (e.type !== 'add') {
|
||||
// add 이벤트 없이 다른 이벤트가 먼저 와도 묵시적 생성 — 데이터 손상 방어.
|
||||
s = {
|
||||
customerId: e.customerId,
|
||||
customerName: e.customerName,
|
||||
mrr: 0,
|
||||
status: 'active',
|
||||
startedAt: e.timestamp,
|
||||
lastEventAt: e.timestamp,
|
||||
eventCount: 0,
|
||||
notes: [],
|
||||
};
|
||||
states.set(e.customerId, s);
|
||||
} else {
|
||||
s = {
|
||||
customerId: e.customerId,
|
||||
customerName: e.customerName,
|
||||
mrr: e.mrr ?? 0,
|
||||
plan: e.plan,
|
||||
renewalAt: e.renewalAt,
|
||||
status: 'active',
|
||||
startedAt: e.timestamp,
|
||||
lastEventAt: e.timestamp,
|
||||
eventCount: 0,
|
||||
notes: [],
|
||||
};
|
||||
states.set(e.customerId, s);
|
||||
}
|
||||
}
|
||||
s.customerName = e.customerName || s.customerName;
|
||||
s.lastEventAt = e.timestamp;
|
||||
s.eventCount += 1;
|
||||
|
||||
switch (e.type) {
|
||||
case 'add':
|
||||
// 위에서 이미 처리 (첫 진입 분기) — 중복 add 면 update 처럼.
|
||||
if (e.mrr !== undefined) s.mrr = e.mrr;
|
||||
if (e.renewalAt) s.renewalAt = e.renewalAt;
|
||||
if (e.plan) s.plan = e.plan;
|
||||
break;
|
||||
case 'update':
|
||||
case 'renew':
|
||||
if (e.mrr !== undefined) s.mrr = e.mrr;
|
||||
if (e.renewalAt) s.renewalAt = e.renewalAt;
|
||||
if (e.plan) s.plan = e.plan;
|
||||
if (e.type === 'renew' && s.status !== 'churned') s.status = 'active';
|
||||
break;
|
||||
case 'risk':
|
||||
if (s.status !== 'churned') s.status = 'at-risk';
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'risk', memo: e.memo });
|
||||
break;
|
||||
case 'churn':
|
||||
s.status = 'churned';
|
||||
s.mrr = 0;
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'churn', memo: e.memo });
|
||||
break;
|
||||
case 'note':
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'note', memo: e.memo });
|
||||
break;
|
||||
}
|
||||
}
|
||||
return states;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 고객 피드백 누적 저장소.
|
||||
*
|
||||
* 단일 운영자(대표) 모드에서 슬랙·이메일·CS 채널에 흩어진 고객 피드백을
|
||||
* `/feedback <텍스트>` 한 줄로 모아 둔다. 패턴 분석은 `/feedback summary` 로
|
||||
* LLM 이 누적 데이터를 보고 카테고리 분포 + 반복 주제를 추출.
|
||||
*
|
||||
* 저장 형식: JSON Lines (.jsonl) — 한 줄 = 한 entry. 누적·append-only, 사람이
|
||||
* 직접 편집 가능, grep / 백업 친화. 위치: `<workspace>/.astra/customer-feedback.jsonl`.
|
||||
*
|
||||
* 워크스페이스 폴더가 없으면 저장 불가 (null 반환). 사용자가 `/feedback path` 로
|
||||
* 위치 확인 가능. 민감 정보 포함 가능성 있으므로 외부로 안 보냄 — 로컬 only.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const STORE_REL_PATH = '.astra/customer-feedback.jsonl';
|
||||
|
||||
export interface FeedbackEntry {
|
||||
/** unique id — timestamp 기반 (정렬·dedup 용도). */
|
||||
id: string;
|
||||
/** ISO timestamp of when this entry was captured. */
|
||||
timestamp: string;
|
||||
/** 사용자가 입력한 원본 텍스트 (그대로 보존). */
|
||||
text: string;
|
||||
/** 선택적 출처 — 'slack' / 'email' / 'cs' / 'review' 등. */
|
||||
source?: string;
|
||||
/** LLM 이 부여한 카테고리 (1~3개). */
|
||||
categories?: string[];
|
||||
/** LLM 판정 — 'positive' / 'neutral' / 'negative'. */
|
||||
sentiment?: 'positive' | 'neutral' | 'negative';
|
||||
}
|
||||
|
||||
export function getFeedbackFilePath(): string | null {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (!folders || folders.length === 0) return null;
|
||||
return path.join(folders[0].uri.fsPath, STORE_REL_PATH);
|
||||
}
|
||||
|
||||
export function readFeedback(): FeedbackEntry[] {
|
||||
const filePath = getFeedbackFilePath();
|
||||
if (!filePath || !fs.existsSync(filePath)) return [];
|
||||
const out: FeedbackEntry[] = [];
|
||||
let content = '';
|
||||
try { content = fs.readFileSync(filePath, 'utf-8'); } catch { return []; }
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
try {
|
||||
const entry = JSON.parse(trimmed);
|
||||
if (entry && typeof entry.id === 'string' && typeof entry.text === 'string') {
|
||||
out.push(entry as FeedbackEntry);
|
||||
}
|
||||
} catch { /* skip malformed line — append-only 라 손상 1줄이 전체 무력화하면 안 됨 */ }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function appendFeedback(entry: FeedbackEntry): { ok: true; filePath: string } | { ok: false; error: string } {
|
||||
const filePath = getFeedbackFilePath();
|
||||
if (!filePath) return { ok: false, error: '워크스페이스 폴더가 없어 저장 불가. VS Code 에서 폴더를 열어 주세요.' };
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.appendFileSync(filePath, JSON.stringify(entry) + '\n', 'utf-8');
|
||||
return { ok: true, filePath };
|
||||
} catch (e: any) {
|
||||
return { ok: false, error: e?.message || String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
/** 누적 항목 수 — 빠른 확인용. */
|
||||
export function countFeedback(): number {
|
||||
const filePath = getFeedbackFilePath();
|
||||
if (!filePath || !fs.existsSync(filePath)) return 0;
|
||||
try {
|
||||
const content = fs.readFileSync(filePath, 'utf-8');
|
||||
return content.split('\n').filter((l) => l.trim()).length;
|
||||
} catch { return 0; }
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/**
|
||||
* 채용 파이프라인 트래커.
|
||||
*
|
||||
* 4인 → 5인 이상 확장 시점에 후보자가 여러 명, 여러 역할(개발/기획/디자인) 로
|
||||
* 들어오기 시작 — 노션·스프레드시트·이메일에 흩어진 정보를 한 명령으로 본다.
|
||||
*
|
||||
* Event-sourced (customersStore 와 동일 패턴) — append-only 이벤트 로그를
|
||||
* 재생해 후보자별 현재 단계 + 노트 누적 도출.
|
||||
*
|
||||
* 위치: `<workspace>/.astra/hire.jsonl`. 사람 직접 편집 가능.
|
||||
* 민감 정보(이름, 연봉, 거절 사유) 포함 — 로컬 only.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const STORE_REL_PATH = '.astra/hire.jsonl';
|
||||
|
||||
export type HireEventType = 'add' | 'stage' | 'note' | 'offer' | 'reject' | 'decline' | 'hire';
|
||||
|
||||
/**
|
||||
* 기본 파이프라인 단계. 사용자가 다른 단계명 지정 가능 — 그냥 문자열로 저장.
|
||||
* 표시 순서·정렬용으로 알려진 단계는 가중치 부여.
|
||||
*/
|
||||
export const KNOWN_STAGES = ['inbox', 'screened', 'interview', 'final', 'offer', 'accepted', 'hired', 'rejected', 'declined'] as const;
|
||||
export type KnownStage = typeof KNOWN_STAGES[number];
|
||||
|
||||
export interface HireEvent {
|
||||
id: string;
|
||||
timestamp: string;
|
||||
candidateId: string;
|
||||
candidateName: string;
|
||||
role: string;
|
||||
type: HireEventType;
|
||||
/** stage 전환 시 새 단계. add 시 시작 단계 (기본 'inbox'). */
|
||||
stage?: string;
|
||||
/** offer 의 연봉 — KRW. */
|
||||
salary?: number;
|
||||
/** 입사 예정일 / 거절·이탈 사유. */
|
||||
memo?: string;
|
||||
}
|
||||
|
||||
export interface CandidateState {
|
||||
candidateId: string;
|
||||
candidateName: string;
|
||||
role: string;
|
||||
stage: string;
|
||||
salary?: number;
|
||||
addedAt: string;
|
||||
lastEventAt: string;
|
||||
eventCount: number;
|
||||
notes: { timestamp: string; type: HireEventType; memo: string }[];
|
||||
}
|
||||
|
||||
export function getHireFilePath(): string | null {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (!folders || folders.length === 0) return null;
|
||||
return path.join(folders[0].uri.fsPath, STORE_REL_PATH);
|
||||
}
|
||||
|
||||
export function candidateIdFromName(name: string): string {
|
||||
return name.toLowerCase().trim().replace(/\s+/g, '-').replace(/[^\w가-힣-]/g, '');
|
||||
}
|
||||
|
||||
export function readHireEvents(): HireEvent[] {
|
||||
const filePath = getHireFilePath();
|
||||
if (!filePath || !fs.existsSync(filePath)) return [];
|
||||
const out: HireEvent[] = [];
|
||||
let content = '';
|
||||
try { content = fs.readFileSync(filePath, 'utf-8'); } catch { return []; }
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
try {
|
||||
const e = JSON.parse(trimmed);
|
||||
if (e && typeof e.id === 'string' && typeof e.candidateId === 'string' && typeof e.type === 'string') {
|
||||
out.push(e as HireEvent);
|
||||
}
|
||||
} catch { /* skip malformed */ }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function appendHireEvent(event: HireEvent): { ok: true; filePath: string } | { ok: false; error: string } {
|
||||
const filePath = getHireFilePath();
|
||||
if (!filePath) return { ok: false, error: '워크스페이스 폴더가 없어 저장 불가.' };
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.appendFileSync(filePath, JSON.stringify(event) + '\n', 'utf-8');
|
||||
return { ok: true, filePath };
|
||||
} catch (e: any) {
|
||||
return { ok: false, error: e?.message || String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
export function computeCandidateStates(): Map<string, CandidateState> {
|
||||
const events = readHireEvents().slice().sort((a, b) => (a.timestamp || '').localeCompare(b.timestamp || ''));
|
||||
const states = new Map<string, CandidateState>();
|
||||
for (const e of events) {
|
||||
let s = states.get(e.candidateId);
|
||||
if (!s) {
|
||||
s = {
|
||||
candidateId: e.candidateId,
|
||||
candidateName: e.candidateName,
|
||||
role: e.role || '',
|
||||
stage: e.stage || 'inbox',
|
||||
addedAt: e.timestamp,
|
||||
lastEventAt: e.timestamp,
|
||||
eventCount: 0,
|
||||
notes: [],
|
||||
};
|
||||
states.set(e.candidateId, s);
|
||||
}
|
||||
s.candidateName = e.candidateName || s.candidateName;
|
||||
s.role = e.role || s.role;
|
||||
s.lastEventAt = e.timestamp;
|
||||
s.eventCount += 1;
|
||||
|
||||
switch (e.type) {
|
||||
case 'add':
|
||||
s.stage = e.stage || s.stage || 'inbox';
|
||||
break;
|
||||
case 'stage':
|
||||
if (e.stage) s.stage = e.stage;
|
||||
break;
|
||||
case 'offer':
|
||||
s.stage = 'offer';
|
||||
if (e.salary !== undefined) s.salary = e.salary;
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'offer', memo: e.memo });
|
||||
break;
|
||||
case 'hire':
|
||||
s.stage = 'hired';
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'hire', memo: e.memo });
|
||||
break;
|
||||
case 'reject':
|
||||
s.stage = 'rejected';
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'reject', memo: e.memo });
|
||||
break;
|
||||
case 'decline':
|
||||
s.stage = 'declined';
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'decline', memo: e.memo });
|
||||
break;
|
||||
case 'note':
|
||||
if (e.memo) s.notes.push({ timestamp: e.timestamp, type: 'note', memo: e.memo });
|
||||
break;
|
||||
}
|
||||
}
|
||||
return states;
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* Runway / Cash 누적 저장소.
|
||||
*
|
||||
* 4인 기업 운영의 가장 중요한 숫자 — 현금 잔고 / 월 소진율 / 남은 개월수 — 를
|
||||
* 한 명령 (`/runway`) 로 본다. 회계 시스템은 아니고, 대표가 머리에 가지고 있는
|
||||
* "지금 통장에 얼마, 한 달에 얼마 나감" 을 코드 옆에서 잡는 가벼운 트래커.
|
||||
*
|
||||
* 저장 형식: JSON Lines (.jsonl) — 한 줄 = 한 entry. 외부 회계 SaaS 연동 안 함.
|
||||
* 위치: `<workspace>/.astra/runway.jsonl`. 사람이 직접 편집 가능, grep / 백업 친화.
|
||||
*
|
||||
* 민감 정보(현금 잔고) 포함되므로 외부로 안 보냄 — 로컬 only.
|
||||
*/
|
||||
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
const STORE_REL_PATH = '.astra/runway.jsonl';
|
||||
|
||||
export type RunwayEntryType = 'snapshot' | 'expense' | 'revenue' | 'burn';
|
||||
|
||||
export interface RunwayEntry {
|
||||
/** unique id — timestamp 기반. */
|
||||
id: string;
|
||||
/** ISO timestamp. */
|
||||
timestamp: string;
|
||||
/** 항목 종류 — snapshot(잔고) / expense(지출) / revenue(수입) / burn(월 소진율 수동 설정). */
|
||||
type: RunwayEntryType;
|
||||
/** 금액 — KRW 기본 단위, 소수점 허용. */
|
||||
amount: number;
|
||||
/** 통화 — 기본 'KRW'. 추후 'USD' 등 확장 가능. */
|
||||
currency?: string;
|
||||
/** 카테고리 — expense 의 경우 'salary' / 'rent' / 'saas' / 'misc' 등. */
|
||||
category?: string;
|
||||
/** 자유 메모. */
|
||||
memo?: string;
|
||||
}
|
||||
|
||||
export function getRunwayFilePath(): string | null {
|
||||
const folders = vscode.workspace.workspaceFolders;
|
||||
if (!folders || folders.length === 0) return null;
|
||||
return path.join(folders[0].uri.fsPath, STORE_REL_PATH);
|
||||
}
|
||||
|
||||
export function readRunway(): RunwayEntry[] {
|
||||
const filePath = getRunwayFilePath();
|
||||
if (!filePath || !fs.existsSync(filePath)) return [];
|
||||
const out: RunwayEntry[] = [];
|
||||
let content = '';
|
||||
try { content = fs.readFileSync(filePath, 'utf-8'); } catch { return []; }
|
||||
for (const line of content.split('\n')) {
|
||||
const trimmed = line.trim();
|
||||
if (!trimmed) continue;
|
||||
try {
|
||||
const entry = JSON.parse(trimmed);
|
||||
if (entry && typeof entry.id === 'string' && typeof entry.amount === 'number' && typeof entry.type === 'string') {
|
||||
out.push(entry as RunwayEntry);
|
||||
}
|
||||
} catch { /* skip malformed line */ }
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
export function appendRunway(entry: RunwayEntry): { ok: true; filePath: string } | { ok: false; error: string } {
|
||||
const filePath = getRunwayFilePath();
|
||||
if (!filePath) return { ok: false, error: '워크스페이스 폴더가 없어 저장 불가. VS Code 에서 폴더를 열어 주세요.' };
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.appendFileSync(filePath, JSON.stringify(entry) + '\n', 'utf-8');
|
||||
return { ok: true, filePath };
|
||||
} catch (e: any) {
|
||||
return { ok: false, error: e?.message || String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 상태 계산 — 최신 snapshot, 최근 30일 net burn, 명시적 burn 설정 중 우선순위.
|
||||
*
|
||||
* - latestCash: 가장 최근 'snapshot' entry 의 amount (없으면 null).
|
||||
* - explicitBurn: 가장 최근 'burn' entry — 사용자가 수동 설정한 월 소진율.
|
||||
* - computedBurn: 최근 30일 expense - revenue, 30일 미만이면 일 평균 × 30 으로 보정.
|
||||
* - effectiveBurn: explicitBurn 우선, 없으면 computedBurn.
|
||||
* - runwayMonths: latestCash / effectiveBurn — burn 이 0 이하면 Infinity.
|
||||
*/
|
||||
export interface RunwayStatus {
|
||||
latestCash: number | null;
|
||||
latestCashAt: string | null;
|
||||
explicitBurn: number | null;
|
||||
computedBurn: number | null;
|
||||
effectiveBurn: number | null;
|
||||
runwayMonths: number | null;
|
||||
last30Expense: number;
|
||||
last30Revenue: number;
|
||||
last30Days: number;
|
||||
totalEntries: number;
|
||||
}
|
||||
|
||||
export function computeRunwayStatus(now: Date = new Date()): RunwayStatus {
|
||||
const entries = readRunway();
|
||||
const nowMs = now.getTime();
|
||||
const thirtyDaysMs = 30 * 24 * 60 * 60 * 1000;
|
||||
|
||||
let latestCash: number | null = null;
|
||||
let latestCashAt: string | null = null;
|
||||
let explicitBurn: number | null = null;
|
||||
let last30Expense = 0;
|
||||
let last30Revenue = 0;
|
||||
let oldestRecentMs = nowMs;
|
||||
let hasRecent = false;
|
||||
|
||||
for (const e of entries) {
|
||||
const t = Date.parse(e.timestamp);
|
||||
if (e.type === 'snapshot') {
|
||||
if (!latestCashAt || (Date.parse(e.timestamp) >= Date.parse(latestCashAt))) {
|
||||
latestCash = e.amount;
|
||||
latestCashAt = e.timestamp;
|
||||
}
|
||||
} else if (e.type === 'burn') {
|
||||
if (!explicitBurn || t >= (entries.find(x => x.type === 'burn' && x.amount === explicitBurn)?.timestamp ? Date.parse(e.timestamp) : 0)) {
|
||||
explicitBurn = e.amount;
|
||||
}
|
||||
} else if (e.type === 'expense' && nowMs - t <= thirtyDaysMs) {
|
||||
last30Expense += e.amount;
|
||||
if (t < oldestRecentMs) oldestRecentMs = t;
|
||||
hasRecent = true;
|
||||
} else if (e.type === 'revenue' && nowMs - t <= thirtyDaysMs) {
|
||||
last30Revenue += e.amount;
|
||||
if (t < oldestRecentMs) oldestRecentMs = t;
|
||||
hasRecent = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 최신 burn 정확히 다시 — 위 로직이 꼬여서 단순화.
|
||||
explicitBurn = null;
|
||||
let burnAt = 0;
|
||||
for (const e of entries) {
|
||||
if (e.type !== 'burn') continue;
|
||||
const t = Date.parse(e.timestamp);
|
||||
if (t >= burnAt) { explicitBurn = e.amount; burnAt = t; }
|
||||
}
|
||||
|
||||
const netBurn30 = last30Expense - last30Revenue;
|
||||
let computedBurn: number | null = null;
|
||||
let last30Days = 0;
|
||||
if (hasRecent) {
|
||||
const span = Math.max(1, Math.ceil((nowMs - oldestRecentMs) / (24 * 60 * 60 * 1000)));
|
||||
last30Days = Math.min(30, span);
|
||||
// 30일 미만이면 일 평균 × 30 으로 환산.
|
||||
if (last30Days < 30) computedBurn = (netBurn30 / last30Days) * 30;
|
||||
else computedBurn = netBurn30;
|
||||
}
|
||||
|
||||
const effectiveBurn = explicitBurn ?? computedBurn;
|
||||
let runwayMonths: number | null = null;
|
||||
if (latestCash !== null && effectiveBurn !== null && effectiveBurn > 0) {
|
||||
runwayMonths = latestCash / effectiveBurn;
|
||||
} else if (latestCash !== null && effectiveBurn !== null && effectiveBurn <= 0) {
|
||||
runwayMonths = Infinity;
|
||||
}
|
||||
|
||||
return {
|
||||
latestCash,
|
||||
latestCashAt,
|
||||
explicitBurn,
|
||||
computedBurn,
|
||||
effectiveBurn,
|
||||
runwayMonths,
|
||||
last30Expense,
|
||||
last30Revenue,
|
||||
last30Days,
|
||||
totalEntries: entries.length,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user