@ectplsm/relic 0.5.2 → 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 (31) hide show
  1. package/README.md +27 -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/interfaces/cli/index.js +0 -0
  8. package/dist/interfaces/mcp/index.js +0 -0
  9. package/package.json +3 -2
  10. package/dist/adapters/shells/copilot-shell.d.ts +0 -14
  11. package/dist/adapters/shells/copilot-shell.js +0 -43
  12. package/dist/adapters/shells/trust-registrar.d.ts +0 -19
  13. package/dist/adapters/shells/trust-registrar.js +0 -141
  14. package/dist/core/usecases/inbox-search.d.ts +0 -20
  15. package/dist/core/usecases/inbox-search.js +0 -46
  16. package/dist/core/usecases/inbox-write.d.ts +0 -27
  17. package/dist/core/usecases/inbox-write.js +0 -72
  18. package/dist/core/usecases/memory-search.d.ts +0 -23
  19. package/dist/core/usecases/memory-search.js +0 -59
  20. package/dist/core/usecases/mikoshi-clone.d.ts +0 -29
  21. package/dist/core/usecases/mikoshi-clone.js +0 -94
  22. package/dist/interfaces/cli/commands/extract.d.ts +0 -2
  23. package/dist/interfaces/cli/commands/extract.js +0 -37
  24. package/dist/interfaces/cli/commands/inject.d.ts +0 -2
  25. package/dist/interfaces/cli/commands/inject.js +0 -34
  26. package/dist/interfaces/cli/commands/sync.d.ts +0 -2
  27. package/dist/interfaces/cli/commands/sync.js +0 -47
  28. package/dist/shared/memory-inbox.d.ts +0 -78
  29. package/dist/shared/memory-inbox.js +0 -168
  30. package/dist/shared/session-recorder.d.ts +0 -47
  31. package/dist/shared/session-recorder.js +0 -112
@@ -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
- }