@causyne/agent 1.17.0 → 1.19.0
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.
- package/package.json +1 -1
- package/src/agentLoop.js +2348 -2518
- package/src/agentLoop.ts +2865 -0
- package/src/checkpoints.d.ts +4 -0
- package/src/cliMode.js +10 -3
- package/src/commands.js +274 -25
- package/src/config.js +22 -0
- package/src/contextManager.d.ts +10 -0
- package/src/continuum/adapters/antigravity.js +193 -0
- package/src/continuum/adapters/antigravity.ts +204 -0
- package/src/continuum/adapters/base.js +48 -0
- package/src/continuum/adapters/base.ts +57 -0
- package/src/continuum/adapters/causyne.js +66 -0
- package/src/continuum/adapters/causyne.ts +72 -0
- package/src/continuum/adapters/claudeCode.js +171 -0
- package/src/continuum/adapters/claudeCode.ts +179 -0
- package/src/continuum/adapters/codex.js +181 -0
- package/src/continuum/adapters/codex.ts +193 -0
- package/src/continuum/adapters/opencode.js +134 -0
- package/src/continuum/adapters/opencode.ts +153 -0
- package/src/continuum/compactor.js +54 -0
- package/src/continuum/compactor.ts +83 -0
- package/src/continuum/index.js +8 -0
- package/src/continuum/index.ts +9 -0
- package/src/continuum/ingest.js +63 -0
- package/src/continuum/ingest.ts +89 -0
- package/src/continuum/sanitizer.js +55 -0
- package/src/continuum/sanitizer.ts +59 -0
- package/src/continuum/scanner.js +86 -0
- package/src/continuum/scanner.ts +106 -0
- package/src/continuum/types.js +3 -0
- package/src/continuum/types.ts +51 -0
- package/src/continuum/ui/continuumPicker.js +111 -0
- package/src/continuum/ui/continuumPicker.ts +145 -0
- package/src/cortex/autoCondenser.d.ts +2 -0
- package/src/cortex/vectorDb.d.ts +1 -0
- package/src/designPalettes.d.ts +2 -0
- package/src/devMode.d.ts +1 -0
- package/src/dynamicCatalogue.js +140 -1
- package/src/dynamicCatalogue.ts +179 -1
- package/src/embodimentSession.d.ts +2 -0
- package/src/entrypoint.js +12 -0
- package/src/memory.d.ts +1 -0
- package/src/memoryManager.d.ts +1 -0
- package/src/modelIds.d.ts +2 -0
- package/src/outputStore.d.ts +4 -0
- package/src/providers/acp.js +321 -267
- package/src/providers/acp.ts +360 -0
- package/src/providers/antigravity.js +389 -239
- package/src/providers/antigravity.ts +450 -0
- package/src/providers/base.d.ts +68 -0
- package/src/providers/factory.d.ts +1 -0
- package/src/provisioning/capabilityProvisioner.d.ts +2 -0
- package/src/sandbox.d.ts +1 -0
- package/src/skillsManager.d.ts +3 -0
- package/src/slopDetector.d.ts +3 -0
- package/src/taskBuffer.d.ts +1 -0
- package/src/tokenTracker.d.ts +1 -0
- package/src/toolPacks.d.ts +8 -0
- package/src/tools/registry.d.ts +4 -0
- package/src/tui/chatRenderer.js +71 -12
- package/src/tui/clipboardSync.js +36 -0
- package/src/tui/clipboardSync.ts +36 -0
- package/src/tui/dialogs.js +15 -2
- package/src/tui/home.js +27 -25
- package/src/tui/modelPicker.js +221 -0
- package/src/tui/modelPicker.ts +290 -0
- package/src/tui/prompt.js +17 -6
- package/src/tui/selectList.js +20 -0
- package/src/tui/theme.js +4 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// Antigravity Continuum Adapter: scans Antigravity IDE and CLI session brains.
|
|
2
|
+
// Authorship: Strict TypeScript (Causyne Agent).
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
8
|
+
import { BaseContinuumAdapter, isSafeIdentifier, readBoundedLines } from './base.js';
|
|
9
|
+
import type { ContinuumSessionSummary, ContinuumSessionDetail, ContinuumMessage } from '../types.js';
|
|
10
|
+
import { cleanUserText, cleanAssistantText } from '../sanitizer.js';
|
|
11
|
+
|
|
12
|
+
export class AntigravityAdapter extends BaseContinuumAdapter {
|
|
13
|
+
readonly platform = 'antigravity' as const;
|
|
14
|
+
readonly label = 'Antigravity';
|
|
15
|
+
|
|
16
|
+
private readonly home = os.homedir();
|
|
17
|
+
private readonly cliSummaryDb = path.join(this.home, '.gemini/antigravity-cli/conversation_summaries.db');
|
|
18
|
+
private readonly ideBrainDir = path.join(this.home, '.gemini/antigravity-ide/brain');
|
|
19
|
+
private readonly cliBrainDir = path.join(this.home, '.gemini/antigravity-cli/brain');
|
|
20
|
+
|
|
21
|
+
isAvailable(): boolean {
|
|
22
|
+
return fs.existsSync(this.cliSummaryDb) || fs.existsSync(this.ideBrainDir) || fs.existsSync(this.cliBrainDir);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async listSessions(limit = 100): Promise<ContinuumSessionSummary[]> {
|
|
26
|
+
const map = new Map<string, ContinuumSessionSummary>();
|
|
27
|
+
|
|
28
|
+
// 1. Ingest summaries from SQLite index if present
|
|
29
|
+
if (fs.existsSync(this.cliSummaryDb)) {
|
|
30
|
+
let db: DatabaseSync | null = null;
|
|
31
|
+
try {
|
|
32
|
+
db = new DatabaseSync(this.cliSummaryDb, { readOnly: true });
|
|
33
|
+
const rows = db.prepare(`
|
|
34
|
+
SELECT conversation_id, title, preview, step_count, last_modified_time, workspace_uris
|
|
35
|
+
FROM conversation_summaries
|
|
36
|
+
ORDER BY last_modified_time DESC
|
|
37
|
+
LIMIT ?
|
|
38
|
+
`).all(limit) as Array<{
|
|
39
|
+
conversation_id: string;
|
|
40
|
+
title: string;
|
|
41
|
+
preview: string;
|
|
42
|
+
step_count: number;
|
|
43
|
+
last_modified_time: string;
|
|
44
|
+
workspace_uris: string;
|
|
45
|
+
}>;
|
|
46
|
+
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
if (!row.conversation_id) continue;
|
|
49
|
+
let ws = '';
|
|
50
|
+
try {
|
|
51
|
+
const parsed = JSON.parse(row.workspace_uris);
|
|
52
|
+
ws = Array.isArray(parsed) && parsed[0] ? String(parsed[0]).replace('file://', '') : '';
|
|
53
|
+
} catch {
|
|
54
|
+
ws = row.workspace_uris || '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
map.set(row.conversation_id, {
|
|
58
|
+
id: `antigravity:${row.conversation_id}`,
|
|
59
|
+
sourcePlatform: this.platform,
|
|
60
|
+
sourceLabel: this.label,
|
|
61
|
+
title: row.title || 'Untitled Session',
|
|
62
|
+
workspacePath: ws,
|
|
63
|
+
updatedAt: new Date(row.last_modified_time).getTime() || Date.now(),
|
|
64
|
+
messageCount: row.step_count || 1,
|
|
65
|
+
snippet: row.preview || ''
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
// Best-effort read
|
|
70
|
+
} finally {
|
|
71
|
+
if (db) {
|
|
72
|
+
try { db.close(); } catch { /* ignore */ }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// 2. Scan IDE and CLI brain transcripts for active sessions
|
|
78
|
+
const scanDirs = [
|
|
79
|
+
{ dir: this.ideBrainDir, label: 'IDE' },
|
|
80
|
+
{ dir: this.cliBrainDir, label: 'CLI' }
|
|
81
|
+
];
|
|
82
|
+
|
|
83
|
+
for (const { dir } of scanDirs) {
|
|
84
|
+
if (!fs.existsSync(dir)) continue;
|
|
85
|
+
try {
|
|
86
|
+
const entries = fs.readdirSync(dir);
|
|
87
|
+
for (const cid of entries) {
|
|
88
|
+
if (!isSafeIdentifier(cid)) continue;
|
|
89
|
+
const tpath = path.join(dir, cid, '.system_generated/logs/transcript.jsonl');
|
|
90
|
+
if (!fs.existsSync(tpath)) continue;
|
|
91
|
+
|
|
92
|
+
if (map.has(cid)) continue;
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const stat = fs.statSync(tpath);
|
|
96
|
+
map.set(cid, {
|
|
97
|
+
id: `antigravity:${cid}`,
|
|
98
|
+
sourcePlatform: this.platform,
|
|
99
|
+
sourceLabel: this.label,
|
|
100
|
+
title: `Session ${cid.slice(0, 8)}`,
|
|
101
|
+
workspacePath: '',
|
|
102
|
+
updatedAt: stat.mtimeMs,
|
|
103
|
+
messageCount: 1,
|
|
104
|
+
snippet: 'Antigravity conversation transcript'
|
|
105
|
+
});
|
|
106
|
+
} catch {
|
|
107
|
+
// Skip unreadable
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
// Skip unreadable
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return Array.from(map.values())
|
|
116
|
+
.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
117
|
+
.slice(0, limit);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async getSession(id: string): Promise<ContinuumSessionDetail | null> {
|
|
121
|
+
const rawId = id.startsWith('antigravity:') ? id.slice('antigravity:'.length) : id;
|
|
122
|
+
if (!isSafeIdentifier(rawId)) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Search for transcript in ide brain, cli brain, or legacy
|
|
127
|
+
const bases = [
|
|
128
|
+
this.ideBrainDir,
|
|
129
|
+
this.cliBrainDir,
|
|
130
|
+
path.join(this.home, '.gemini/antigravity/brain')
|
|
131
|
+
];
|
|
132
|
+
|
|
133
|
+
let tpath: string | null = null;
|
|
134
|
+
for (const base of bases) {
|
|
135
|
+
const candidate = path.join(base, rawId, '.system_generated/logs/transcript.jsonl');
|
|
136
|
+
if (path.resolve(candidate).startsWith(base) && fs.existsSync(candidate)) {
|
|
137
|
+
tpath = candidate;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!tpath) return null;
|
|
143
|
+
|
|
144
|
+
const messages: ContinuumMessage[] = [];
|
|
145
|
+
let title = `Antigravity Session ${rawId.slice(0, 8)}`;
|
|
146
|
+
const workspace = '';
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const lines = readBoundedLines(tpath);
|
|
150
|
+
|
|
151
|
+
for (const line of lines) {
|
|
152
|
+
if (!line.trim()) continue;
|
|
153
|
+
try {
|
|
154
|
+
const data = JSON.parse(line);
|
|
155
|
+
const type = data.type;
|
|
156
|
+
const text = data.content || '';
|
|
157
|
+
|
|
158
|
+
if (type === 'USER_INPUT') {
|
|
159
|
+
const cleaned = cleanUserText(text);
|
|
160
|
+
if (cleaned) {
|
|
161
|
+
if (messages.length === 0) {
|
|
162
|
+
const firstLine = cleaned.split('\n')[0] || '';
|
|
163
|
+
if (firstLine.trim()) title = firstLine.trim().slice(0, 60);
|
|
164
|
+
}
|
|
165
|
+
messages.push({
|
|
166
|
+
role: 'user',
|
|
167
|
+
content: cleaned,
|
|
168
|
+
timestamp: data.created_at ? new Date(data.created_at).getTime() : Date.now()
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
} else if (type === 'PLANNER_RESPONSE') {
|
|
172
|
+
const cleaned = cleanAssistantText(text);
|
|
173
|
+
if (cleaned) {
|
|
174
|
+
messages.push({
|
|
175
|
+
role: 'assistant',
|
|
176
|
+
content: cleaned,
|
|
177
|
+
timestamp: data.created_at ? new Date(data.created_at).getTime() : Date.now()
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
// Skip torn JSON line
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (messages.length === 0) return null;
|
|
190
|
+
|
|
191
|
+
const stat = fs.statSync(tpath);
|
|
192
|
+
return {
|
|
193
|
+
id: `antigravity:${rawId}`,
|
|
194
|
+
sourcePlatform: this.platform,
|
|
195
|
+
sourceLabel: this.label,
|
|
196
|
+
title,
|
|
197
|
+
workspacePath: workspace,
|
|
198
|
+
updatedAt: stat.mtimeMs,
|
|
199
|
+
messageCount: messages.length,
|
|
200
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
201
|
+
messages
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Base adapter contract and safe I/O utilities for peer AI agent session readers.
|
|
2
|
+
// Authorship: Strict TypeScript (Causyne Agent).
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
export function isSafeIdentifier(id) {
|
|
5
|
+
if (!id || typeof id !== 'string')
|
|
6
|
+
return false;
|
|
7
|
+
if (id.includes('..') || id.includes('/') || id.includes('\\') || id.includes('\0'))
|
|
8
|
+
return false;
|
|
9
|
+
return /^[a-zA-Z0-9_\-\.]+$/.test(id);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Read transcript lines with strict memory bounds to prevent Node process OOM on oversized logs.
|
|
13
|
+
*/
|
|
14
|
+
export function readBoundedLines(filePath, maxBytes = 25 * 1024 * 1024) {
|
|
15
|
+
try {
|
|
16
|
+
const stat = fs.statSync(filePath);
|
|
17
|
+
if (stat.size <= maxBytes) {
|
|
18
|
+
return fs.readFileSync(filePath, 'utf8').split('\n');
|
|
19
|
+
}
|
|
20
|
+
const headSize = 2 * 1024 * 1024;
|
|
21
|
+
const tailSize = 6 * 1024 * 1024;
|
|
22
|
+
const fd = fs.openSync(filePath, 'r');
|
|
23
|
+
try {
|
|
24
|
+
const headBuf = Buffer.alloc(headSize);
|
|
25
|
+
const headRead = fs.readSync(fd, headBuf, 0, headSize, 0);
|
|
26
|
+
const headText = headBuf.toString('utf8', 0, headRead);
|
|
27
|
+
const headLines = headText.split('\n');
|
|
28
|
+
if (headLines.length > 0)
|
|
29
|
+
headLines.pop();
|
|
30
|
+
const tailPos = Math.max(0, stat.size - tailSize);
|
|
31
|
+
const tailBuf = Buffer.alloc(tailSize);
|
|
32
|
+
const tailRead = fs.readSync(fd, tailBuf, 0, tailSize, tailPos);
|
|
33
|
+
const tailText = tailBuf.toString('utf8', 0, tailRead);
|
|
34
|
+
const tailLines = tailText.split('\n');
|
|
35
|
+
if (tailLines.length > 0)
|
|
36
|
+
tailLines.shift();
|
|
37
|
+
return [...headLines, ...tailLines];
|
|
38
|
+
}
|
|
39
|
+
finally {
|
|
40
|
+
fs.closeSync(fd);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export class BaseContinuumAdapter {
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Base adapter contract and safe I/O utilities for peer AI agent session readers.
|
|
2
|
+
// Authorship: Strict TypeScript (Causyne Agent).
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import type { ContinuumAdapter, ContinuumSessionSummary, ContinuumSessionDetail, AgentPlatform } from '../types.js';
|
|
6
|
+
|
|
7
|
+
export function isSafeIdentifier(id: string): boolean {
|
|
8
|
+
if (!id || typeof id !== 'string') return false;
|
|
9
|
+
if (id.includes('..') || id.includes('/') || id.includes('\\') || id.includes('\0')) return false;
|
|
10
|
+
return /^[a-zA-Z0-9_\-\.]+$/.test(id);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Read transcript lines with strict memory bounds to prevent Node process OOM on oversized logs.
|
|
15
|
+
*/
|
|
16
|
+
export function readBoundedLines(filePath: string, maxBytes = 25 * 1024 * 1024): string[] {
|
|
17
|
+
try {
|
|
18
|
+
const stat = fs.statSync(filePath);
|
|
19
|
+
if (stat.size <= maxBytes) {
|
|
20
|
+
return fs.readFileSync(filePath, 'utf8').split('\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const headSize = 2 * 1024 * 1024;
|
|
24
|
+
const tailSize = 6 * 1024 * 1024;
|
|
25
|
+
|
|
26
|
+
const fd = fs.openSync(filePath, 'r');
|
|
27
|
+
try {
|
|
28
|
+
const headBuf = Buffer.alloc(headSize);
|
|
29
|
+
const headRead = fs.readSync(fd, headBuf, 0, headSize, 0);
|
|
30
|
+
const headText = headBuf.toString('utf8', 0, headRead);
|
|
31
|
+
const headLines = headText.split('\n');
|
|
32
|
+
if (headLines.length > 0) headLines.pop();
|
|
33
|
+
|
|
34
|
+
const tailPos = Math.max(0, stat.size - tailSize);
|
|
35
|
+
const tailBuf = Buffer.alloc(tailSize);
|
|
36
|
+
const tailRead = fs.readSync(fd, tailBuf, 0, tailSize, tailPos);
|
|
37
|
+
const tailText = tailBuf.toString('utf8', 0, tailRead);
|
|
38
|
+
const tailLines = tailText.split('\n');
|
|
39
|
+
if (tailLines.length > 0) tailLines.shift();
|
|
40
|
+
|
|
41
|
+
return [...headLines, ...tailLines];
|
|
42
|
+
} finally {
|
|
43
|
+
fs.closeSync(fd);
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export abstract class BaseContinuumAdapter implements ContinuumAdapter {
|
|
51
|
+
abstract readonly platform: AgentPlatform;
|
|
52
|
+
abstract readonly label: string;
|
|
53
|
+
|
|
54
|
+
abstract isAvailable(): boolean;
|
|
55
|
+
abstract listSessions(limit?: number): Promise<ContinuumSessionSummary[]>;
|
|
56
|
+
abstract getSession(id: string): Promise<ContinuumSessionDetail | null>;
|
|
57
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Causyne Native Continuum Adapter: reads sessions through the sovereign session journal.
|
|
2
|
+
// Authorship: Strict TypeScript (Causyne Agent).
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { BaseContinuumAdapter, isSafeIdentifier } from './base.js';
|
|
6
|
+
import { listSessions, getSession, SESSION_DIR } from '../../sessionJournal.js';
|
|
7
|
+
export class CausyneAdapter extends BaseContinuumAdapter {
|
|
8
|
+
platform = 'causyne';
|
|
9
|
+
label = 'Causyne Agent';
|
|
10
|
+
isAvailable() {
|
|
11
|
+
return fs.existsSync(SESSION_DIR);
|
|
12
|
+
}
|
|
13
|
+
async listSessions(limit = 100) {
|
|
14
|
+
if (!this.isAvailable())
|
|
15
|
+
return [];
|
|
16
|
+
try {
|
|
17
|
+
const records = listSessions();
|
|
18
|
+
return records.slice(0, limit).map(r => ({
|
|
19
|
+
id: `causyne:${r.id}`,
|
|
20
|
+
sourcePlatform: this.platform,
|
|
21
|
+
sourceLabel: this.label,
|
|
22
|
+
title: r.title || 'Untitled Session',
|
|
23
|
+
workspacePath: r.workspace || '',
|
|
24
|
+
updatedAt: r.updatedAt || r.createdAt || Date.now(),
|
|
25
|
+
messageCount: r.messageCount || 1,
|
|
26
|
+
snippet: `Native Causyne session in ${path.basename(r.workspace || '~')}`
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async getSession(id) {
|
|
34
|
+
if (!this.isAvailable())
|
|
35
|
+
return null;
|
|
36
|
+
const rawId = id.startsWith('causyne:') ? id.slice('causyne:'.length) : id;
|
|
37
|
+
if (!isSafeIdentifier(rawId)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const record = getSession(rawId);
|
|
42
|
+
if (!record || !record.messages || record.messages.length === 0) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const messages = record.messages.map(m => ({
|
|
46
|
+
role: m.role === 'user' ? 'user' : (m.role === 'assistant' ? 'assistant' : 'system'),
|
|
47
|
+
content: typeof m.content === 'string' ? m.content : JSON.stringify(m.content || ''),
|
|
48
|
+
timestamp: record.updatedAt
|
|
49
|
+
}));
|
|
50
|
+
return {
|
|
51
|
+
id: `causyne:${record.id}`,
|
|
52
|
+
sourcePlatform: this.platform,
|
|
53
|
+
sourceLabel: this.label,
|
|
54
|
+
title: record.title || 'Untitled Session',
|
|
55
|
+
workspacePath: record.workspace || '',
|
|
56
|
+
updatedAt: record.updatedAt,
|
|
57
|
+
messageCount: messages.length,
|
|
58
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
59
|
+
messages
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Causyne Native Continuum Adapter: reads sessions through the sovereign session journal.
|
|
2
|
+
// Authorship: Strict TypeScript (Causyne Agent).
|
|
3
|
+
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { BaseContinuumAdapter, isSafeIdentifier } from './base.js';
|
|
7
|
+
import type { ContinuumSessionSummary, ContinuumSessionDetail, ContinuumMessage } from '../types.js';
|
|
8
|
+
import { listSessions, getSession, SESSION_DIR } from '../../sessionJournal.js';
|
|
9
|
+
|
|
10
|
+
export class CausyneAdapter extends BaseContinuumAdapter {
|
|
11
|
+
readonly platform = 'causyne' as const;
|
|
12
|
+
readonly label = 'Causyne Agent';
|
|
13
|
+
|
|
14
|
+
isAvailable(): boolean {
|
|
15
|
+
return fs.existsSync(SESSION_DIR);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async listSessions(limit = 100): Promise<ContinuumSessionSummary[]> {
|
|
19
|
+
if (!this.isAvailable()) return [];
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
const records = listSessions();
|
|
23
|
+
return records.slice(0, limit).map(r => ({
|
|
24
|
+
id: `causyne:${r.id}`,
|
|
25
|
+
sourcePlatform: this.platform,
|
|
26
|
+
sourceLabel: this.label,
|
|
27
|
+
title: r.title || 'Untitled Session',
|
|
28
|
+
workspacePath: r.workspace || '',
|
|
29
|
+
updatedAt: r.updatedAt || r.createdAt || Date.now(),
|
|
30
|
+
messageCount: r.messageCount || 1,
|
|
31
|
+
snippet: `Native Causyne session in ${path.basename(r.workspace || '~')}`
|
|
32
|
+
}));
|
|
33
|
+
} catch {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async getSession(id: string): Promise<ContinuumSessionDetail | null> {
|
|
39
|
+
if (!this.isAvailable()) return null;
|
|
40
|
+
const rawId = id.startsWith('causyne:') ? id.slice('causyne:'.length) : id;
|
|
41
|
+
if (!isSafeIdentifier(rawId)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const record = getSession(rawId);
|
|
47
|
+
if (!record || !record.messages || record.messages.length === 0) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const messages: ContinuumMessage[] = record.messages.map(m => ({
|
|
52
|
+
role: m.role === 'user' ? 'user' : (m.role === 'assistant' ? 'assistant' : 'system'),
|
|
53
|
+
content: typeof m.content === 'string' ? m.content : JSON.stringify(m.content || ''),
|
|
54
|
+
timestamp: record.updatedAt
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
id: `causyne:${record.id}`,
|
|
59
|
+
sourcePlatform: this.platform,
|
|
60
|
+
sourceLabel: this.label,
|
|
61
|
+
title: record.title || 'Untitled Session',
|
|
62
|
+
workspacePath: record.workspace || '',
|
|
63
|
+
updatedAt: record.updatedAt,
|
|
64
|
+
messageCount: messages.length,
|
|
65
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
66
|
+
messages
|
|
67
|
+
};
|
|
68
|
+
} catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// Claude Code Continuum Adapter: scans projects in ~/.claude/projects.
|
|
2
|
+
// Authorship: Strict TypeScript (Causyne Agent).
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import { BaseContinuumAdapter, readBoundedLines } from './base.js';
|
|
7
|
+
import { cleanUserText, cleanAssistantText, deriveSessionTitle } from '../sanitizer.js';
|
|
8
|
+
function extractClaudeText(content) {
|
|
9
|
+
if (typeof content === 'string')
|
|
10
|
+
return content;
|
|
11
|
+
if (Array.isArray(content)) {
|
|
12
|
+
return content
|
|
13
|
+
.map((part) => {
|
|
14
|
+
if (typeof part === 'string')
|
|
15
|
+
return part;
|
|
16
|
+
if (part && typeof part === 'object') {
|
|
17
|
+
const block = part;
|
|
18
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
19
|
+
return block.text;
|
|
20
|
+
}
|
|
21
|
+
if (typeof block.text === 'string') {
|
|
22
|
+
return block.text;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return '';
|
|
26
|
+
})
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join('\n');
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
export class ClaudeCodeAdapter extends BaseContinuumAdapter {
|
|
33
|
+
platform = 'claude_code';
|
|
34
|
+
label = 'Claude Code';
|
|
35
|
+
projectsDir = path.join(os.homedir(), '.claude/projects');
|
|
36
|
+
isAvailable() {
|
|
37
|
+
return fs.existsSync(this.projectsDir);
|
|
38
|
+
}
|
|
39
|
+
async listSessions(limit = 100) {
|
|
40
|
+
if (!this.isAvailable())
|
|
41
|
+
return [];
|
|
42
|
+
const summaries = [];
|
|
43
|
+
try {
|
|
44
|
+
const projectDirs = fs.readdirSync(this.projectsDir);
|
|
45
|
+
for (const pdir of projectDirs) {
|
|
46
|
+
if (pdir.includes('..') || pdir.includes('/') || pdir.includes('\\'))
|
|
47
|
+
continue;
|
|
48
|
+
const fullPdir = path.join(this.projectsDir, pdir);
|
|
49
|
+
let stat;
|
|
50
|
+
try {
|
|
51
|
+
stat = fs.statSync(fullPdir);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (!stat.isDirectory())
|
|
57
|
+
continue;
|
|
58
|
+
const files = fs.readdirSync(fullPdir);
|
|
59
|
+
for (const file of files) {
|
|
60
|
+
if (!file.endsWith('.jsonl') || file.includes('..'))
|
|
61
|
+
continue;
|
|
62
|
+
const fpath = path.join(fullPdir, file);
|
|
63
|
+
try {
|
|
64
|
+
const fstat = fs.statSync(fpath);
|
|
65
|
+
const sessionId = file.replace('.jsonl', '');
|
|
66
|
+
const humanProject = pdir.replace(/^-Users-[^-]+-?/, '').replace(/-/g, ' ');
|
|
67
|
+
summaries.push({
|
|
68
|
+
id: `claude:${pdir}/${sessionId}`,
|
|
69
|
+
sourcePlatform: this.platform,
|
|
70
|
+
sourceLabel: this.label,
|
|
71
|
+
title: `Claude Code: ${humanProject || 'Session'}`,
|
|
72
|
+
workspacePath: pdir.replace(/^-/, '/').replace(/-/g, '/'),
|
|
73
|
+
updatedAt: fstat.mtimeMs,
|
|
74
|
+
messageCount: 1,
|
|
75
|
+
snippet: `Claude Code project session in ${humanProject}`
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
// Skip unreadable file
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
return summaries
|
|
88
|
+
.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
89
|
+
.slice(0, limit);
|
|
90
|
+
}
|
|
91
|
+
async getSession(id) {
|
|
92
|
+
if (!this.isAvailable())
|
|
93
|
+
return null;
|
|
94
|
+
const rawPath = id.startsWith('claude:') ? id.slice('claude:'.length) : id;
|
|
95
|
+
// Security: reject path traversal
|
|
96
|
+
if (!rawPath || rawPath.includes('..') || rawPath.includes('\0') || path.isAbsolute(rawPath)) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const fpath = path.join(this.projectsDir, `${rawPath}.jsonl`);
|
|
100
|
+
const resolvedPath = path.resolve(fpath);
|
|
101
|
+
if (!resolvedPath.startsWith(path.resolve(this.projectsDir) + path.sep)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
if (!fs.existsSync(fpath))
|
|
105
|
+
return null;
|
|
106
|
+
const messages = [];
|
|
107
|
+
let title = `Claude Code Session ${path.basename(rawPath).slice(0, 8)}`;
|
|
108
|
+
let workspace = '';
|
|
109
|
+
try {
|
|
110
|
+
const lines = readBoundedLines(fpath);
|
|
111
|
+
for (const line of lines) {
|
|
112
|
+
if (!line.trim())
|
|
113
|
+
continue;
|
|
114
|
+
try {
|
|
115
|
+
const entry = JSON.parse(line);
|
|
116
|
+
const type = entry.type;
|
|
117
|
+
if (type === 'user') {
|
|
118
|
+
const rawContent = entry.message?.content || entry.content;
|
|
119
|
+
const text = extractClaudeText(rawContent);
|
|
120
|
+
const cleaned = cleanUserText(text);
|
|
121
|
+
if (cleaned) {
|
|
122
|
+
if (messages.length === 0) {
|
|
123
|
+
title = deriveSessionTitle(cleaned, title);
|
|
124
|
+
}
|
|
125
|
+
messages.push({
|
|
126
|
+
role: 'user',
|
|
127
|
+
content: cleaned,
|
|
128
|
+
timestamp: entry.timestamp ? new Date(entry.timestamp).getTime() : Date.now()
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (type === 'assistant') {
|
|
133
|
+
const rawContent = entry.message?.content || entry.content;
|
|
134
|
+
const text = extractClaudeText(rawContent);
|
|
135
|
+
const cleaned = cleanAssistantText(text);
|
|
136
|
+
if (cleaned) {
|
|
137
|
+
messages.push({
|
|
138
|
+
role: 'assistant',
|
|
139
|
+
content: cleaned,
|
|
140
|
+
timestamp: entry.timestamp ? new Date(entry.timestamp).getTime() : Date.now()
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!workspace && entry.cwd) {
|
|
145
|
+
workspace = String(entry.cwd);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
// Skip torn line
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
if (messages.length === 0)
|
|
157
|
+
return null;
|
|
158
|
+
const stat = fs.statSync(fpath);
|
|
159
|
+
return {
|
|
160
|
+
id: `claude:${rawPath}`,
|
|
161
|
+
sourcePlatform: this.platform,
|
|
162
|
+
sourceLabel: this.label,
|
|
163
|
+
title,
|
|
164
|
+
workspacePath: workspace,
|
|
165
|
+
updatedAt: stat.mtimeMs,
|
|
166
|
+
messageCount: messages.length,
|
|
167
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
168
|
+
messages
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|