@ectplsm/relic 0.5.1 → 0.5.3

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 (36) hide show
  1. package/README.md +36 -4
  2. package/dist/adapters/shells/codex-hook.d.ts +3 -3
  3. package/dist/adapters/shells/codex-hook.js +12 -11
  4. package/dist/adapters/shells/codex-paths.d.ts +11 -0
  5. package/dist/adapters/shells/codex-paths.js +23 -0
  6. package/dist/adapters/shells/codex-shell.js +7 -5
  7. package/dist/adapters/shells/gemini-shell.js +38 -38
  8. package/dist/interfaces/cli/index.js +0 -0
  9. package/dist/interfaces/mcp/index.js +0 -0
  10. package/package.json +3 -2
  11. package/templates/engrams/commander/IDENTITY.md +4 -0
  12. package/templates/engrams/commander/SOUL.md +14 -1
  13. package/templates/engrams/rebel/IDENTITY.md +3 -1
  14. package/templates/engrams/rebel/SOUL.md +12 -0
  15. package/dist/adapters/shells/copilot-shell.d.ts +0 -14
  16. package/dist/adapters/shells/copilot-shell.js +0 -43
  17. package/dist/adapters/shells/trust-registrar.d.ts +0 -19
  18. package/dist/adapters/shells/trust-registrar.js +0 -141
  19. package/dist/core/usecases/inbox-search.d.ts +0 -20
  20. package/dist/core/usecases/inbox-search.js +0 -46
  21. package/dist/core/usecases/inbox-write.d.ts +0 -27
  22. package/dist/core/usecases/inbox-write.js +0 -72
  23. package/dist/core/usecases/memory-search.d.ts +0 -23
  24. package/dist/core/usecases/memory-search.js +0 -59
  25. package/dist/core/usecases/mikoshi-clone.d.ts +0 -29
  26. package/dist/core/usecases/mikoshi-clone.js +0 -94
  27. package/dist/interfaces/cli/commands/extract.d.ts +0 -2
  28. package/dist/interfaces/cli/commands/extract.js +0 -37
  29. package/dist/interfaces/cli/commands/inject.d.ts +0 -2
  30. package/dist/interfaces/cli/commands/inject.js +0 -34
  31. package/dist/interfaces/cli/commands/sync.d.ts +0 -2
  32. package/dist/interfaces/cli/commands/sync.js +0 -47
  33. package/dist/shared/memory-inbox.d.ts +0 -78
  34. package/dist/shared/memory-inbox.js +0 -168
  35. package/dist/shared/session-recorder.d.ts +0 -47
  36. package/dist/shared/session-recorder.js +0 -112
@@ -1,78 +0,0 @@
1
- /**
2
- * MemoryInbox — ファイルベースのメモリ受付口 + セッションログ
3
- *
4
- * LLMが inbox.md に追記すると、fs.watchで検知して処理する。
5
- * inbox.md は書き溜め式で、セッションを跨いで追記され続ける。
6
- * 処理済みエントリ数は inbox.cursor に永続化され、
7
- * クラッシュ後の再起動でも正確に未処理分だけを回収できる。
8
- *
9
- * エントリの種別:
10
- * - `[memory] ...` → memory/*.md に永続化される記憶
11
- * - タグ無し → inbox.md にログとして残るだけ(会話サマリー等)
12
- *
13
- * フォーマット:
14
- * 各エントリは `---` (前後に改行) で区切る。
15
- *
16
- * 例:
17
- * Discussed improving RELIC's memory system.
18
- * ---
19
- * Implemented inbox-based approach for cross-LLM persistence.
20
- * ---
21
- * [memory] User prefers Bun over Node.js for all TypeScript projects.
22
- * ---
23
- * [memory] Project RELIC uses clean architecture with Zod for validation.
24
- */
25
- export declare class MemoryInbox {
26
- private readonly engramId;
27
- private readonly engramsPath;
28
- private watcher;
29
- private processedCount;
30
- private processing;
31
- private memorySaved;
32
- private logCount;
33
- private savedEntries;
34
- readonly inboxPath: string;
35
- private readonly cursorPath;
36
- constructor(engramId: string, engramsPath: string);
37
- /**
38
- * Inboxを起動する。
39
- *
40
- * 1. cursorファイルから前回の処理済み位置を復元
41
- * 2. inbox.md の未処理エントリを回収(クラッシュ回復)
42
- * 3. fs.watch で監視開始
43
- */
44
- start(): Promise<MemoryInboxRecoveryResult>;
45
- /**
46
- * 監視を停止し、最終掃引を行う。
47
- * inbox.md はそのまま残す(書き溜め式)。
48
- */
49
- stop(): Promise<MemoryInboxResult>;
50
- /**
51
- * ファイル全体をパースし、未処理のエントリだけを処理する。
52
- *
53
- * - `[memory]` タグ付き → MemoryWrite で永続化
54
- * - タグ無し → カウントのみ(inbox.md にログとして残る)
55
- *
56
- * 処理成功ごとにカーソルを永続化するため、
57
- * 途中でクラッシュしても処理済み分は再処理されない。
58
- */
59
- private processNewEntries;
60
- private loadCursor;
61
- private saveCursor;
62
- }
63
- export interface MemoryInboxResult {
64
- /** memory/*.md に永続化されたエントリ数 */
65
- memories: number;
66
- /** ログとして記録されたエントリ数 */
67
- logs: number;
68
- /** 永続化されたメモリの内容 */
69
- entries: string[];
70
- }
71
- export interface MemoryInboxRecoveryResult {
72
- /** 回収されたメモリ数 */
73
- recoveredMemories: number;
74
- /** 回収されたログ数 */
75
- recoveredLogs: number;
76
- /** 回収されたメモリの内容 */
77
- entries: string[];
78
- }
@@ -1,168 +0,0 @@
1
- import { watch, existsSync, writeFileSync, readFileSync } from "node:fs";
2
- import { readFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
- import { MemoryWrite } from "../core/usecases/memory-write.js";
5
- const INBOX_FILE = "inbox.md";
6
- const CURSOR_FILE = "inbox.cursor";
7
- const ENTRY_SEPARATOR = /\n---\n/;
8
- const MEMORY_TAG = /^\[memory\]\s*/i;
9
- /**
10
- * MemoryInbox — ファイルベースのメモリ受付口 + セッションログ
11
- *
12
- * LLMが inbox.md に追記すると、fs.watchで検知して処理する。
13
- * inbox.md は書き溜め式で、セッションを跨いで追記され続ける。
14
- * 処理済みエントリ数は inbox.cursor に永続化され、
15
- * クラッシュ後の再起動でも正確に未処理分だけを回収できる。
16
- *
17
- * エントリの種別:
18
- * - `[memory] ...` → memory/*.md に永続化される記憶
19
- * - タグ無し → inbox.md にログとして残るだけ(会話サマリー等)
20
- *
21
- * フォーマット:
22
- * 各エントリは `---` (前後に改行) で区切る。
23
- *
24
- * 例:
25
- * Discussed improving RELIC's memory system.
26
- * ---
27
- * Implemented inbox-based approach for cross-LLM persistence.
28
- * ---
29
- * [memory] User prefers Bun over Node.js for all TypeScript projects.
30
- * ---
31
- * [memory] Project RELIC uses clean architecture with Zod for validation.
32
- */
33
- export class MemoryInbox {
34
- engramId;
35
- engramsPath;
36
- watcher = null;
37
- processedCount = 0;
38
- processing = false;
39
- memorySaved = 0;
40
- logCount = 0;
41
- savedEntries = [];
42
- inboxPath;
43
- cursorPath;
44
- constructor(engramId, engramsPath) {
45
- this.engramId = engramId;
46
- this.engramsPath = engramsPath;
47
- const engramDir = join(engramsPath, engramId);
48
- this.inboxPath = join(engramDir, INBOX_FILE);
49
- this.cursorPath = join(engramDir, CURSOR_FILE);
50
- }
51
- /**
52
- * Inboxを起動する。
53
- *
54
- * 1. cursorファイルから前回の処理済み位置を復元
55
- * 2. inbox.md の未処理エントリを回収(クラッシュ回復)
56
- * 3. fs.watch で監視開始
57
- */
58
- async start() {
59
- if (!existsSync(this.inboxPath)) {
60
- writeFileSync(this.inboxPath, "", "utf-8");
61
- }
62
- this.processedCount = this.loadCursor();
63
- const recovered = await this.processNewEntries();
64
- this.watcher = watch(this.inboxPath, async (eventType) => {
65
- if (eventType === "change") {
66
- await this.processNewEntries();
67
- }
68
- });
69
- this.watcher.on("error", () => { });
70
- return {
71
- recoveredMemories: recovered.memories,
72
- recoveredLogs: recovered.logs,
73
- entries: recovered.savedEntries,
74
- };
75
- }
76
- /**
77
- * 監視を停止し、最終掃引を行う。
78
- * inbox.md はそのまま残す(書き溜め式)。
79
- */
80
- async stop() {
81
- if (this.watcher) {
82
- this.watcher.close();
83
- this.watcher = null;
84
- }
85
- await this.processNewEntries();
86
- return {
87
- memories: this.memorySaved,
88
- logs: this.logCount,
89
- entries: this.savedEntries,
90
- };
91
- }
92
- /**
93
- * ファイル全体をパースし、未処理のエントリだけを処理する。
94
- *
95
- * - `[memory]` タグ付き → MemoryWrite で永続化
96
- * - タグ無し → カウントのみ(inbox.md にログとして残る)
97
- *
98
- * 処理成功ごとにカーソルを永続化するため、
99
- * 途中でクラッシュしても処理済み分は再処理されない。
100
- */
101
- async processNewEntries() {
102
- if (this.processing)
103
- return { memories: 0, logs: 0, savedEntries: [] };
104
- this.processing = true;
105
- const result = { memories: 0, logs: 0, savedEntries: [] };
106
- try {
107
- if (!existsSync(this.inboxPath))
108
- return result;
109
- const fullContent = await readFile(this.inboxPath, "utf-8");
110
- if (!fullContent.trim())
111
- return result;
112
- const allEntries = fullContent
113
- .split(ENTRY_SEPARATOR)
114
- .map((e) => e.trim())
115
- .filter((e) => e.length > 0);
116
- const newEntries = allEntries.slice(this.processedCount);
117
- if (newEntries.length === 0)
118
- return result;
119
- const writer = new MemoryWrite(this.engramsPath);
120
- for (const raw of newEntries) {
121
- const isMemory = MEMORY_TAG.test(raw);
122
- if (isMemory) {
123
- const content = raw.replace(MEMORY_TAG, "").trim();
124
- try {
125
- await writer.execute(this.engramId, content);
126
- this.memorySaved++;
127
- this.savedEntries.push(content);
128
- result.memories++;
129
- result.savedEntries.push(content);
130
- }
131
- catch (err) {
132
- console.error(`[relic:inbox] Failed to save memory: ${err}`);
133
- }
134
- }
135
- else {
136
- this.logCount++;
137
- result.logs++;
138
- }
139
- this.processedCount++;
140
- this.saveCursor();
141
- }
142
- }
143
- finally {
144
- this.processing = false;
145
- }
146
- return result;
147
- }
148
- loadCursor() {
149
- if (!existsSync(this.cursorPath))
150
- return 0;
151
- try {
152
- const raw = readFileSync(this.cursorPath, "utf-8").trim();
153
- const n = parseInt(raw, 10);
154
- return Number.isNaN(n) ? 0 : n;
155
- }
156
- catch {
157
- return 0;
158
- }
159
- }
160
- saveCursor() {
161
- try {
162
- writeFileSync(this.cursorPath, String(this.processedCount), "utf-8");
163
- }
164
- catch {
165
- /* best effort */
166
- }
167
- }
168
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * SessionRecorder — PTYストリームから会話履歴とメモリを記録する
3
- *
4
- * 役割:
5
- * 1. full_history.md に全会話を蓄積(ANSI除去済みテキスト)
6
- * 2. ストリーム中の [memory] タグを検出し memory/*.md に永続化
7
- *
8
- * full_history.md は無限に蓄積され続ける。セッションごとにヘッダーが挿入される。
9
- */
10
- export declare class SessionRecorder {
11
- private readonly engramId;
12
- private readonly engramsPath;
13
- readonly historyPath: string;
14
- private memoryBuffer;
15
- private memorySaved;
16
- private savedEntries;
17
- constructor(engramId: string, engramsPath: string);
18
- /**
19
- * セッション開始。ヘッダーを full_history.md に追記する。
20
- */
21
- start(shellName: string): void;
22
- /**
23
- * PTYストリームのデータを処理する。
24
- * spawnShellWithPty の onData コールバックから呼ぶ。
25
- *
26
- * - ANSI除去してfull_history.mdに追記
27
- * - [memory] タグを検出してバッファに溜める
28
- */
29
- onData(rawData: string): void;
30
- /**
31
- * セッション終了。残りのバッファを処理する。
32
- */
33
- stop(): Promise<SessionRecorderResult>;
34
- /**
35
- * memoryBuffer から完成した行を取り出し、[memory] タグを検出して永続化する。
36
- * final=true の場合は残りのバッファも全て処理する。
37
- */
38
- private flushMemoryBuffer;
39
- }
40
- export interface SessionRecorderResult {
41
- /** memory/*.md に永続化されたメモリ数 */
42
- memories: number;
43
- /** 永続化されたメモリの内容 */
44
- entries: string[];
45
- /** full_history.md のパス */
46
- historyPath: string;
47
- }
@@ -1,112 +0,0 @@
1
- import { appendFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import { MemoryWrite } from "../core/usecases/memory-write.js";
4
- const HISTORY_FILE = "full_history.md";
5
- const MEMORY_TAG = /\[memory\]\s*/gi;
6
- /**
7
- * ANSIエスケープシーケンスを除去する
8
- */
9
- // eslint-disable-next-line no-control-regex
10
- const ANSI_REGEX = /\x1b\[[0-9;]*[a-zA-Z]|\x1b\].*?(?:\x07|\x1b\\)|\x1b[()][0-9A-B]|\x1b[>=<]|\x08/g;
11
- function stripAnsi(text) {
12
- return text.replace(ANSI_REGEX, "");
13
- }
14
- /**
15
- * SessionRecorder — PTYストリームから会話履歴とメモリを記録する
16
- *
17
- * 役割:
18
- * 1. full_history.md に全会話を蓄積(ANSI除去済みテキスト)
19
- * 2. ストリーム中の [memory] タグを検出し memory/*.md に永続化
20
- *
21
- * full_history.md は無限に蓄積され続ける。セッションごとにヘッダーが挿入される。
22
- */
23
- export class SessionRecorder {
24
- engramId;
25
- engramsPath;
26
- historyPath;
27
- memoryBuffer = "";
28
- memorySaved = 0;
29
- savedEntries = [];
30
- constructor(engramId, engramsPath) {
31
- this.engramId = engramId;
32
- this.engramsPath = engramsPath;
33
- this.historyPath = join(engramsPath, engramId, HISTORY_FILE);
34
- }
35
- /**
36
- * セッション開始。ヘッダーを full_history.md に追記する。
37
- */
38
- start(shellName) {
39
- const header = [
40
- "",
41
- "---",
42
- `## Session: ${new Date().toISOString()}`,
43
- `Shell: ${shellName}`,
44
- `Engram: ${this.engramId}`,
45
- "---",
46
- "",
47
- ].join("\n");
48
- appendFileSync(this.historyPath, header, "utf-8");
49
- }
50
- /**
51
- * PTYストリームのデータを処理する。
52
- * spawnShellWithPty の onData コールバックから呼ぶ。
53
- *
54
- * - ANSI除去してfull_history.mdに追記
55
- * - [memory] タグを検出してバッファに溜める
56
- */
57
- onData(rawData) {
58
- const clean = stripAnsi(rawData);
59
- if (clean) {
60
- appendFileSync(this.historyPath, clean, "utf-8");
61
- }
62
- // [memory] タグの検出
63
- // PTYは断片的にデータが来るので、バッファに溜めて行単位で処理
64
- this.memoryBuffer += clean;
65
- this.flushMemoryBuffer(false);
66
- }
67
- /**
68
- * セッション終了。残りのバッファを処理する。
69
- */
70
- async stop() {
71
- // 末尾の改行を追加
72
- appendFileSync(this.historyPath, "\n", "utf-8");
73
- // バッファ内の残りを処理
74
- await this.flushMemoryBuffer(true);
75
- return {
76
- memories: this.memorySaved,
77
- entries: this.savedEntries,
78
- historyPath: this.historyPath,
79
- };
80
- }
81
- /**
82
- * memoryBuffer から完成した行を取り出し、[memory] タグを検出して永続化する。
83
- * final=true の場合は残りのバッファも全て処理する。
84
- */
85
- async flushMemoryBuffer(final) {
86
- const lines = this.memoryBuffer.split("\n");
87
- // 最終行は未完成の可能性があるので、final でない限り保持
88
- if (!final && lines.length > 0) {
89
- this.memoryBuffer = lines.pop() || "";
90
- }
91
- else {
92
- this.memoryBuffer = "";
93
- }
94
- const writer = new MemoryWrite(this.engramsPath);
95
- for (const line of lines) {
96
- const trimmed = line.trim();
97
- if (MEMORY_TAG.test(trimmed)) {
98
- const content = trimmed.replace(MEMORY_TAG, "").trim();
99
- if (content) {
100
- try {
101
- await writer.execute(this.engramId, content);
102
- this.memorySaved++;
103
- this.savedEntries.push(content);
104
- }
105
- catch (err) {
106
- console.error(`[relic:session] Failed to save memory: ${err}`);
107
- }
108
- }
109
- }
110
- }
111
- }
112
- }