@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,179 @@
|
|
|
1
|
+
// Claude Code Continuum Adapter: scans projects in ~/.claude/projects.
|
|
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 { BaseContinuumAdapter, readBoundedLines } from './base.js';
|
|
8
|
+
import type { ContinuumSessionSummary, ContinuumSessionDetail, ContinuumMessage } from '../types.js';
|
|
9
|
+
import { cleanUserText, cleanAssistantText, deriveSessionTitle } from '../sanitizer.js';
|
|
10
|
+
|
|
11
|
+
function extractClaudeText(content: unknown): string {
|
|
12
|
+
if (typeof content === 'string') return content;
|
|
13
|
+
if (Array.isArray(content)) {
|
|
14
|
+
return content
|
|
15
|
+
.map((part: unknown) => {
|
|
16
|
+
if (typeof part === 'string') return part;
|
|
17
|
+
if (part && typeof part === 'object') {
|
|
18
|
+
const block = part as Record<string, unknown>;
|
|
19
|
+
if (block.type === 'text' && typeof block.text === 'string') {
|
|
20
|
+
return block.text;
|
|
21
|
+
}
|
|
22
|
+
if (typeof block.text === 'string') {
|
|
23
|
+
return block.text;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
27
|
+
})
|
|
28
|
+
.filter(Boolean)
|
|
29
|
+
.join('\n');
|
|
30
|
+
}
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class ClaudeCodeAdapter extends BaseContinuumAdapter {
|
|
35
|
+
readonly platform = 'claude_code' as const;
|
|
36
|
+
readonly label = 'Claude Code';
|
|
37
|
+
|
|
38
|
+
private readonly projectsDir = path.join(os.homedir(), '.claude/projects');
|
|
39
|
+
|
|
40
|
+
isAvailable(): boolean {
|
|
41
|
+
return fs.existsSync(this.projectsDir);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async listSessions(limit = 100): Promise<ContinuumSessionSummary[]> {
|
|
45
|
+
if (!this.isAvailable()) return [];
|
|
46
|
+
|
|
47
|
+
const summaries: ContinuumSessionSummary[] = [];
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const projectDirs = fs.readdirSync(this.projectsDir);
|
|
51
|
+
|
|
52
|
+
for (const pdir of projectDirs) {
|
|
53
|
+
if (pdir.includes('..') || pdir.includes('/') || pdir.includes('\\')) continue;
|
|
54
|
+
const fullPdir = path.join(this.projectsDir, pdir);
|
|
55
|
+
let stat: fs.Stats;
|
|
56
|
+
try {
|
|
57
|
+
stat = fs.statSync(fullPdir);
|
|
58
|
+
} catch {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (!stat.isDirectory()) continue;
|
|
62
|
+
|
|
63
|
+
const files = fs.readdirSync(fullPdir);
|
|
64
|
+
for (const file of files) {
|
|
65
|
+
if (!file.endsWith('.jsonl') || file.includes('..')) continue;
|
|
66
|
+
const fpath = path.join(fullPdir, file);
|
|
67
|
+
try {
|
|
68
|
+
const fstat = fs.statSync(fpath);
|
|
69
|
+
const sessionId = file.replace('.jsonl', '');
|
|
70
|
+
const humanProject = pdir.replace(/^-Users-[^-]+-?/, '').replace(/-/g, ' ');
|
|
71
|
+
|
|
72
|
+
summaries.push({
|
|
73
|
+
id: `claude:${pdir}/${sessionId}`,
|
|
74
|
+
sourcePlatform: this.platform,
|
|
75
|
+
sourceLabel: this.label,
|
|
76
|
+
title: `Claude Code: ${humanProject || 'Session'}`,
|
|
77
|
+
workspacePath: pdir.replace(/^-/, '/').replace(/-/g, '/'),
|
|
78
|
+
updatedAt: fstat.mtimeMs,
|
|
79
|
+
messageCount: 1,
|
|
80
|
+
snippet: `Claude Code project session in ${humanProject}`
|
|
81
|
+
});
|
|
82
|
+
} catch {
|
|
83
|
+
// Skip unreadable file
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return summaries
|
|
92
|
+
.sort((a, b) => b.updatedAt - a.updatedAt)
|
|
93
|
+
.slice(0, limit);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async getSession(id: string): Promise<ContinuumSessionDetail | null> {
|
|
97
|
+
if (!this.isAvailable()) return null;
|
|
98
|
+
const rawPath = id.startsWith('claude:') ? id.slice('claude:'.length) : id;
|
|
99
|
+
|
|
100
|
+
// Security: reject path traversal
|
|
101
|
+
if (!rawPath || rawPath.includes('..') || rawPath.includes('\0') || path.isAbsolute(rawPath)) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const fpath = path.join(this.projectsDir, `${rawPath}.jsonl`);
|
|
106
|
+
const resolvedPath = path.resolve(fpath);
|
|
107
|
+
if (!resolvedPath.startsWith(path.resolve(this.projectsDir) + path.sep)) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!fs.existsSync(fpath)) return null;
|
|
112
|
+
|
|
113
|
+
const messages: ContinuumMessage[] = [];
|
|
114
|
+
let title = `Claude Code Session ${path.basename(rawPath).slice(0, 8)}`;
|
|
115
|
+
let workspace = '';
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const lines = readBoundedLines(fpath);
|
|
119
|
+
|
|
120
|
+
for (const line of lines) {
|
|
121
|
+
if (!line.trim()) continue;
|
|
122
|
+
try {
|
|
123
|
+
const entry = JSON.parse(line);
|
|
124
|
+
const type = entry.type;
|
|
125
|
+
|
|
126
|
+
if (type === 'user') {
|
|
127
|
+
const rawContent = entry.message?.content || entry.content;
|
|
128
|
+
const text = extractClaudeText(rawContent);
|
|
129
|
+
const cleaned = cleanUserText(text);
|
|
130
|
+
if (cleaned) {
|
|
131
|
+
if (messages.length === 0) {
|
|
132
|
+
title = deriveSessionTitle(cleaned, title);
|
|
133
|
+
}
|
|
134
|
+
messages.push({
|
|
135
|
+
role: 'user',
|
|
136
|
+
content: cleaned,
|
|
137
|
+
timestamp: entry.timestamp ? new Date(entry.timestamp).getTime() : Date.now()
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
} else if (type === 'assistant') {
|
|
141
|
+
const rawContent = entry.message?.content || entry.content;
|
|
142
|
+
const text = extractClaudeText(rawContent);
|
|
143
|
+
const cleaned = cleanAssistantText(text);
|
|
144
|
+
if (cleaned) {
|
|
145
|
+
messages.push({
|
|
146
|
+
role: 'assistant',
|
|
147
|
+
content: cleaned,
|
|
148
|
+
timestamp: entry.timestamp ? new Date(entry.timestamp).getTime() : Date.now()
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!workspace && entry.cwd) {
|
|
154
|
+
workspace = String(entry.cwd);
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
// Skip torn line
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (messages.length === 0) return null;
|
|
165
|
+
|
|
166
|
+
const stat = fs.statSync(fpath);
|
|
167
|
+
return {
|
|
168
|
+
id: `claude:${rawPath}`,
|
|
169
|
+
sourcePlatform: this.platform,
|
|
170
|
+
sourceLabel: this.label,
|
|
171
|
+
title,
|
|
172
|
+
workspacePath: workspace,
|
|
173
|
+
updatedAt: stat.mtimeMs,
|
|
174
|
+
messageCount: messages.length,
|
|
175
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
176
|
+
messages
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Codex Continuum Adapter: reads threads from ~/.codex/thread_history_1.sqlite.
|
|
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 { DatabaseSync } from 'node:sqlite';
|
|
7
|
+
import { BaseContinuumAdapter, isSafeIdentifier } from './base.js';
|
|
8
|
+
import { cleanUserText, cleanAssistantText, deriveSessionTitle } from '../sanitizer.js';
|
|
9
|
+
function extractCodexContent(content) {
|
|
10
|
+
if (typeof content === 'string')
|
|
11
|
+
return content;
|
|
12
|
+
if (Array.isArray(content)) {
|
|
13
|
+
return content
|
|
14
|
+
.map((c) => {
|
|
15
|
+
if (typeof c === 'string')
|
|
16
|
+
return c;
|
|
17
|
+
if (c && typeof c === 'object' && 'text' in c && typeof c.text === 'string') {
|
|
18
|
+
return c.text;
|
|
19
|
+
}
|
|
20
|
+
return '';
|
|
21
|
+
})
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.join('\n');
|
|
24
|
+
}
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
export class CodexAdapter extends BaseContinuumAdapter {
|
|
28
|
+
platform = 'codex';
|
|
29
|
+
label = 'Codex';
|
|
30
|
+
dbPath = path.join(os.homedir(), '.codex/thread_history_1.sqlite');
|
|
31
|
+
isAvailable() {
|
|
32
|
+
return fs.existsSync(this.dbPath);
|
|
33
|
+
}
|
|
34
|
+
async listSessions(limit = 100) {
|
|
35
|
+
if (!this.isAvailable())
|
|
36
|
+
return [];
|
|
37
|
+
let db = null;
|
|
38
|
+
try {
|
|
39
|
+
db = new DatabaseSync(this.dbPath, { readOnly: true });
|
|
40
|
+
const rows = db.prepare(`
|
|
41
|
+
SELECT thread_id,
|
|
42
|
+
MIN(created_at_ms) as first_created,
|
|
43
|
+
MAX(created_at_ms) as last_updated,
|
|
44
|
+
COUNT(*) as total_items
|
|
45
|
+
FROM thread_items
|
|
46
|
+
GROUP BY thread_id
|
|
47
|
+
ORDER BY last_updated DESC
|
|
48
|
+
LIMIT ?
|
|
49
|
+
`).all(limit);
|
|
50
|
+
const summaries = [];
|
|
51
|
+
for (const row of rows) {
|
|
52
|
+
let title = `Codex Thread ${row.thread_id.slice(0, 8)}`;
|
|
53
|
+
let snippet = '';
|
|
54
|
+
try {
|
|
55
|
+
const firstMsg = db.prepare(`
|
|
56
|
+
SELECT item_json FROM thread_items
|
|
57
|
+
WHERE thread_id = ? AND item_type = 'userMessage'
|
|
58
|
+
ORDER BY rollout_ordinal ASC
|
|
59
|
+
LIMIT 1
|
|
60
|
+
`).get(row.thread_id);
|
|
61
|
+
if (firstMsg?.item_json) {
|
|
62
|
+
const parsed = JSON.parse(firstMsg.item_json);
|
|
63
|
+
const fullText = extractCodexContent(parsed.content);
|
|
64
|
+
if (fullText) {
|
|
65
|
+
title = deriveSessionTitle(fullText, title);
|
|
66
|
+
snippet = fullText.slice(0, 100);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// Use default title
|
|
72
|
+
}
|
|
73
|
+
summaries.push({
|
|
74
|
+
id: `codex:${row.thread_id}`,
|
|
75
|
+
sourcePlatform: this.platform,
|
|
76
|
+
sourceLabel: this.label,
|
|
77
|
+
title,
|
|
78
|
+
workspacePath: '',
|
|
79
|
+
updatedAt: row.last_updated || row.first_created || Date.now(),
|
|
80
|
+
messageCount: row.total_items,
|
|
81
|
+
snippet
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return summaries;
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (db) {
|
|
91
|
+
try {
|
|
92
|
+
db.close();
|
|
93
|
+
}
|
|
94
|
+
catch { /* ignore */ }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async getSession(id) {
|
|
99
|
+
if (!this.isAvailable())
|
|
100
|
+
return null;
|
|
101
|
+
const rawId = id.startsWith('codex:') ? id.slice('codex:'.length) : id;
|
|
102
|
+
if (!isSafeIdentifier(rawId)) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
let db = null;
|
|
106
|
+
try {
|
|
107
|
+
db = new DatabaseSync(this.dbPath, { readOnly: true });
|
|
108
|
+
const items = db.prepare(`
|
|
109
|
+
SELECT item_type, created_at_ms, item_json
|
|
110
|
+
FROM thread_items
|
|
111
|
+
WHERE thread_id = ?
|
|
112
|
+
ORDER BY rollout_ordinal ASC, created_at_ms ASC
|
|
113
|
+
`).all(rawId);
|
|
114
|
+
if (items.length === 0)
|
|
115
|
+
return null;
|
|
116
|
+
const messages = [];
|
|
117
|
+
let sessionTitle = `Codex Thread ${rawId.slice(0, 8)}`;
|
|
118
|
+
for (const item of items) {
|
|
119
|
+
if (!item.item_json)
|
|
120
|
+
continue;
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(item.item_json);
|
|
123
|
+
const type = item.item_type || parsed.type;
|
|
124
|
+
const text = extractCodexContent(parsed.content);
|
|
125
|
+
if (type === 'userMessage' || type === 'user') {
|
|
126
|
+
const cleaned = cleanUserText(text);
|
|
127
|
+
if (cleaned) {
|
|
128
|
+
if (messages.length === 0) {
|
|
129
|
+
sessionTitle = deriveSessionTitle(cleaned, sessionTitle);
|
|
130
|
+
}
|
|
131
|
+
messages.push({
|
|
132
|
+
role: 'user',
|
|
133
|
+
content: cleaned,
|
|
134
|
+
timestamp: item.created_at_ms
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else if (type === 'agentMessage' || type === 'assistantMessage' || type === 'assistant') {
|
|
139
|
+
const cleaned = cleanAssistantText(text);
|
|
140
|
+
if (cleaned) {
|
|
141
|
+
messages.push({
|
|
142
|
+
role: 'assistant',
|
|
143
|
+
content: cleaned,
|
|
144
|
+
timestamp: item.created_at_ms
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
// Skip corrupt item
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (messages.length === 0)
|
|
154
|
+
return null;
|
|
155
|
+
const firstItem = items[0];
|
|
156
|
+
const lastItem = items[items.length - 1];
|
|
157
|
+
return {
|
|
158
|
+
id: `codex:${rawId}`,
|
|
159
|
+
sourcePlatform: this.platform,
|
|
160
|
+
sourceLabel: this.label,
|
|
161
|
+
title: sessionTitle,
|
|
162
|
+
workspacePath: '',
|
|
163
|
+
updatedAt: lastItem?.created_at_ms || firstItem?.created_at_ms || Date.now(),
|
|
164
|
+
messageCount: messages.length,
|
|
165
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
166
|
+
messages
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
if (db) {
|
|
174
|
+
try {
|
|
175
|
+
db.close();
|
|
176
|
+
}
|
|
177
|
+
catch { /* ignore */ }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Codex Continuum Adapter: reads threads from ~/.codex/thread_history_1.sqlite.
|
|
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 } from './base.js';
|
|
9
|
+
import type { ContinuumSessionSummary, ContinuumSessionDetail, ContinuumMessage } from '../types.js';
|
|
10
|
+
import { cleanUserText, cleanAssistantText, deriveSessionTitle } from '../sanitizer.js';
|
|
11
|
+
|
|
12
|
+
function extractCodexContent(content: unknown): string {
|
|
13
|
+
if (typeof content === 'string') return content;
|
|
14
|
+
if (Array.isArray(content)) {
|
|
15
|
+
return content
|
|
16
|
+
.map((c: unknown) => {
|
|
17
|
+
if (typeof c === 'string') return c;
|
|
18
|
+
if (c && typeof c === 'object' && 'text' in c && typeof (c as { text?: unknown }).text === 'string') {
|
|
19
|
+
return (c as { text: string }).text;
|
|
20
|
+
}
|
|
21
|
+
return '';
|
|
22
|
+
})
|
|
23
|
+
.filter(Boolean)
|
|
24
|
+
.join('\n');
|
|
25
|
+
}
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class CodexAdapter extends BaseContinuumAdapter {
|
|
30
|
+
readonly platform = 'codex' as const;
|
|
31
|
+
readonly label = 'Codex';
|
|
32
|
+
|
|
33
|
+
private readonly dbPath = path.join(os.homedir(), '.codex/thread_history_1.sqlite');
|
|
34
|
+
|
|
35
|
+
isAvailable(): boolean {
|
|
36
|
+
return fs.existsSync(this.dbPath);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async listSessions(limit = 100): Promise<ContinuumSessionSummary[]> {
|
|
40
|
+
if (!this.isAvailable()) return [];
|
|
41
|
+
|
|
42
|
+
let db: DatabaseSync | null = null;
|
|
43
|
+
try {
|
|
44
|
+
db = new DatabaseSync(this.dbPath, { readOnly: true });
|
|
45
|
+
const rows = db.prepare(`
|
|
46
|
+
SELECT thread_id,
|
|
47
|
+
MIN(created_at_ms) as first_created,
|
|
48
|
+
MAX(created_at_ms) as last_updated,
|
|
49
|
+
COUNT(*) as total_items
|
|
50
|
+
FROM thread_items
|
|
51
|
+
GROUP BY thread_id
|
|
52
|
+
ORDER BY last_updated DESC
|
|
53
|
+
LIMIT ?
|
|
54
|
+
`).all(limit) as Array<{
|
|
55
|
+
thread_id: string;
|
|
56
|
+
first_created: number;
|
|
57
|
+
last_updated: number;
|
|
58
|
+
total_items: number;
|
|
59
|
+
}>;
|
|
60
|
+
|
|
61
|
+
const summaries: ContinuumSessionSummary[] = [];
|
|
62
|
+
|
|
63
|
+
for (const row of rows) {
|
|
64
|
+
let title = `Codex Thread ${row.thread_id.slice(0, 8)}`;
|
|
65
|
+
let snippet = '';
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const firstMsg = db.prepare(`
|
|
69
|
+
SELECT item_json FROM thread_items
|
|
70
|
+
WHERE thread_id = ? AND item_type = 'userMessage'
|
|
71
|
+
ORDER BY rollout_ordinal ASC
|
|
72
|
+
LIMIT 1
|
|
73
|
+
`).get(row.thread_id) as { item_json: string } | undefined;
|
|
74
|
+
|
|
75
|
+
if (firstMsg?.item_json) {
|
|
76
|
+
const parsed = JSON.parse(firstMsg.item_json);
|
|
77
|
+
const fullText = extractCodexContent(parsed.content);
|
|
78
|
+
if (fullText) {
|
|
79
|
+
title = deriveSessionTitle(fullText, title);
|
|
80
|
+
snippet = fullText.slice(0, 100);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
} catch {
|
|
84
|
+
// Use default title
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
summaries.push({
|
|
88
|
+
id: `codex:${row.thread_id}`,
|
|
89
|
+
sourcePlatform: this.platform,
|
|
90
|
+
sourceLabel: this.label,
|
|
91
|
+
title,
|
|
92
|
+
workspacePath: '',
|
|
93
|
+
updatedAt: row.last_updated || row.first_created || Date.now(),
|
|
94
|
+
messageCount: row.total_items,
|
|
95
|
+
snippet
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return summaries;
|
|
100
|
+
} catch {
|
|
101
|
+
return [];
|
|
102
|
+
} finally {
|
|
103
|
+
if (db) {
|
|
104
|
+
try { db.close(); } catch { /* ignore */ }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async getSession(id: string): Promise<ContinuumSessionDetail | null> {
|
|
110
|
+
if (!this.isAvailable()) return null;
|
|
111
|
+
const rawId = id.startsWith('codex:') ? id.slice('codex:'.length) : id;
|
|
112
|
+
if (!isSafeIdentifier(rawId)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let db: DatabaseSync | null = null;
|
|
117
|
+
try {
|
|
118
|
+
db = new DatabaseSync(this.dbPath, { readOnly: true });
|
|
119
|
+
const items = db.prepare(`
|
|
120
|
+
SELECT item_type, created_at_ms, item_json
|
|
121
|
+
FROM thread_items
|
|
122
|
+
WHERE thread_id = ?
|
|
123
|
+
ORDER BY rollout_ordinal ASC, created_at_ms ASC
|
|
124
|
+
`).all(rawId) as Array<{
|
|
125
|
+
item_type: string;
|
|
126
|
+
created_at_ms: number;
|
|
127
|
+
item_json: string;
|
|
128
|
+
}>;
|
|
129
|
+
|
|
130
|
+
if (items.length === 0) return null;
|
|
131
|
+
|
|
132
|
+
const messages: ContinuumMessage[] = [];
|
|
133
|
+
let sessionTitle = `Codex Thread ${rawId.slice(0, 8)}`;
|
|
134
|
+
|
|
135
|
+
for (const item of items) {
|
|
136
|
+
if (!item.item_json) continue;
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(item.item_json);
|
|
139
|
+
const type = item.item_type || parsed.type;
|
|
140
|
+
const text = extractCodexContent(parsed.content);
|
|
141
|
+
|
|
142
|
+
if (type === 'userMessage' || type === 'user') {
|
|
143
|
+
const cleaned = cleanUserText(text);
|
|
144
|
+
if (cleaned) {
|
|
145
|
+
if (messages.length === 0) {
|
|
146
|
+
sessionTitle = deriveSessionTitle(cleaned, sessionTitle);
|
|
147
|
+
}
|
|
148
|
+
messages.push({
|
|
149
|
+
role: 'user',
|
|
150
|
+
content: cleaned,
|
|
151
|
+
timestamp: item.created_at_ms
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
} else if (type === 'agentMessage' || type === 'assistantMessage' || type === 'assistant') {
|
|
155
|
+
const cleaned = cleanAssistantText(text);
|
|
156
|
+
if (cleaned) {
|
|
157
|
+
messages.push({
|
|
158
|
+
role: 'assistant',
|
|
159
|
+
content: cleaned,
|
|
160
|
+
timestamp: item.created_at_ms
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} catch {
|
|
165
|
+
// Skip corrupt item
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (messages.length === 0) return null;
|
|
170
|
+
|
|
171
|
+
const firstItem = items[0];
|
|
172
|
+
const lastItem = items[items.length - 1];
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
id: `codex:${rawId}`,
|
|
176
|
+
sourcePlatform: this.platform,
|
|
177
|
+
sourceLabel: this.label,
|
|
178
|
+
title: sessionTitle,
|
|
179
|
+
workspacePath: '',
|
|
180
|
+
updatedAt: lastItem?.created_at_ms || firstItem?.created_at_ms || Date.now(),
|
|
181
|
+
messageCount: messages.length,
|
|
182
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
183
|
+
messages
|
|
184
|
+
};
|
|
185
|
+
} catch {
|
|
186
|
+
return null;
|
|
187
|
+
} finally {
|
|
188
|
+
if (db) {
|
|
189
|
+
try { db.close(); } catch { /* ignore */ }
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
// OpenCode Continuum Adapter: reads sessions from ~/.local/share/opencode/opencode.db.
|
|
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 { DatabaseSync } from 'node:sqlite';
|
|
7
|
+
import { BaseContinuumAdapter, isSafeIdentifier } from './base.js';
|
|
8
|
+
import { cleanUserText, cleanAssistantText } from '../sanitizer.js';
|
|
9
|
+
export class OpenCodeAdapter extends BaseContinuumAdapter {
|
|
10
|
+
platform = 'opencode';
|
|
11
|
+
label = 'OpenCode';
|
|
12
|
+
dbPath = path.join(os.homedir(), '.local/share/opencode/opencode.db');
|
|
13
|
+
isAvailable() {
|
|
14
|
+
return fs.existsSync(this.dbPath);
|
|
15
|
+
}
|
|
16
|
+
async listSessions(limit = 100) {
|
|
17
|
+
if (!this.isAvailable())
|
|
18
|
+
return [];
|
|
19
|
+
let db = null;
|
|
20
|
+
try {
|
|
21
|
+
db = new DatabaseSync(this.dbPath, { readOnly: true });
|
|
22
|
+
const rows = db.prepare(`
|
|
23
|
+
SELECT id, title, time_created, time_updated, directory
|
|
24
|
+
FROM session
|
|
25
|
+
ORDER BY time_updated DESC
|
|
26
|
+
LIMIT ?
|
|
27
|
+
`).all(limit);
|
|
28
|
+
return rows.map(r => ({
|
|
29
|
+
id: `opencode:${r.id}`,
|
|
30
|
+
sourcePlatform: this.platform,
|
|
31
|
+
sourceLabel: this.label,
|
|
32
|
+
title: r.title || 'Untitled Session',
|
|
33
|
+
workspacePath: r.directory || '',
|
|
34
|
+
updatedAt: r.time_updated || r.time_created || Date.now(),
|
|
35
|
+
messageCount: 1,
|
|
36
|
+
snippet: `OpenCode workspace: ${path.basename(r.directory || '')}`
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
if (db) {
|
|
44
|
+
try {
|
|
45
|
+
db.close();
|
|
46
|
+
}
|
|
47
|
+
catch { /* ignore */ }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async getSession(id) {
|
|
52
|
+
if (!this.isAvailable())
|
|
53
|
+
return null;
|
|
54
|
+
const rawId = id.startsWith('opencode:') ? id.slice('opencode:'.length) : id;
|
|
55
|
+
if (!isSafeIdentifier(rawId)) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
let db = null;
|
|
59
|
+
try {
|
|
60
|
+
db = new DatabaseSync(this.dbPath, { readOnly: true });
|
|
61
|
+
const sessionRow = db.prepare(`
|
|
62
|
+
SELECT id, title, time_created, time_updated, directory
|
|
63
|
+
FROM session
|
|
64
|
+
WHERE id = ?
|
|
65
|
+
`).get(rawId);
|
|
66
|
+
if (!sessionRow) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const messageRows = db.prepare(`
|
|
70
|
+
SELECT m.id, json_extract(m.data, '$.role') as role,
|
|
71
|
+
m.time_created,
|
|
72
|
+
json_extract(p.data, '$.type') as ptype,
|
|
73
|
+
json_extract(p.data, '$.text') as ptext
|
|
74
|
+
FROM message m
|
|
75
|
+
JOIN part p ON m.id = p.message_id
|
|
76
|
+
WHERE m.session_id = ? AND json_extract(p.data, '$.type') = 'text'
|
|
77
|
+
ORDER BY m.time_created ASC, p.id ASC
|
|
78
|
+
`).all(rawId);
|
|
79
|
+
// Group multi-part messages into unified turns
|
|
80
|
+
const grouped = new Map();
|
|
81
|
+
for (const row of messageRows) {
|
|
82
|
+
if (!row.ptext || !row.ptext.trim())
|
|
83
|
+
continue;
|
|
84
|
+
const existing = grouped.get(row.id);
|
|
85
|
+
if (existing) {
|
|
86
|
+
existing.texts.push(row.ptext);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
grouped.set(row.id, {
|
|
90
|
+
role: row.role === 'user' ? 'user' : 'assistant',
|
|
91
|
+
time: row.time_created,
|
|
92
|
+
texts: [row.ptext]
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const messages = [];
|
|
97
|
+
for (const item of grouped.values()) {
|
|
98
|
+
const joined = item.texts.join('\n');
|
|
99
|
+
const cleaned = item.role === 'user' ? cleanUserText(joined) : cleanAssistantText(joined);
|
|
100
|
+
if (cleaned) {
|
|
101
|
+
messages.push({
|
|
102
|
+
role: item.role,
|
|
103
|
+
content: cleaned,
|
|
104
|
+
timestamp: item.time
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (messages.length === 0)
|
|
109
|
+
return null;
|
|
110
|
+
return {
|
|
111
|
+
id: `opencode:${sessionRow.id}`,
|
|
112
|
+
sourcePlatform: this.platform,
|
|
113
|
+
sourceLabel: this.label,
|
|
114
|
+
title: sessionRow.title || 'Untitled Session',
|
|
115
|
+
workspacePath: sessionRow.directory || '',
|
|
116
|
+
updatedAt: sessionRow.time_updated || sessionRow.time_created,
|
|
117
|
+
messageCount: messages.length,
|
|
118
|
+
snippet: messages[0]?.content.slice(0, 100) || '',
|
|
119
|
+
messages
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
if (db) {
|
|
127
|
+
try {
|
|
128
|
+
db.close();
|
|
129
|
+
}
|
|
130
|
+
catch { /* ignore */ }
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|