@causyne/agent 1.18.0 → 1.20.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.
Files changed (76) hide show
  1. package/package.json +1 -1
  2. package/src/agentLoop.js +2348 -2531
  3. package/src/agentLoop.ts +2865 -0
  4. package/src/checkpoints.d.ts +4 -0
  5. package/src/cliMode.js +30 -17
  6. package/src/commands.js +307 -57
  7. package/src/config.js +22 -0
  8. package/src/contextManager.d.ts +10 -0
  9. package/src/continuum/adapters/antigravity.js +193 -0
  10. package/src/continuum/adapters/antigravity.ts +204 -0
  11. package/src/continuum/adapters/base.js +48 -0
  12. package/src/continuum/adapters/base.ts +57 -0
  13. package/src/continuum/adapters/causyne.js +66 -0
  14. package/src/continuum/adapters/causyne.ts +72 -0
  15. package/src/continuum/adapters/claudeCode.js +171 -0
  16. package/src/continuum/adapters/claudeCode.ts +179 -0
  17. package/src/continuum/adapters/codex.js +181 -0
  18. package/src/continuum/adapters/codex.ts +193 -0
  19. package/src/continuum/adapters/opencode.js +134 -0
  20. package/src/continuum/adapters/opencode.ts +153 -0
  21. package/src/continuum/compactor.js +54 -0
  22. package/src/continuum/compactor.ts +83 -0
  23. package/src/continuum/index.js +8 -0
  24. package/src/continuum/index.ts +9 -0
  25. package/src/continuum/ingest.js +63 -0
  26. package/src/continuum/ingest.ts +89 -0
  27. package/src/continuum/sanitizer.js +55 -0
  28. package/src/continuum/sanitizer.ts +59 -0
  29. package/src/continuum/scanner.js +86 -0
  30. package/src/continuum/scanner.ts +106 -0
  31. package/src/continuum/types.js +3 -0
  32. package/src/continuum/types.ts +51 -0
  33. package/src/continuum/ui/continuumPicker.js +111 -0
  34. package/src/continuum/ui/continuumPicker.ts +145 -0
  35. package/src/cortex/autoCondenser.d.ts +2 -0
  36. package/src/cortex/vectorDb.d.ts +1 -0
  37. package/src/designPalettes.d.ts +2 -0
  38. package/src/devMode.d.ts +1 -0
  39. package/src/dynamicCatalogue.js +5 -3
  40. package/src/dynamicCatalogue.ts +7 -4
  41. package/src/embodimentSession.d.ts +2 -0
  42. package/src/entrypoint.js +12 -0
  43. package/src/memory.d.ts +1 -0
  44. package/src/memoryManager.d.ts +1 -0
  45. package/src/memoryManager.js +10 -6
  46. package/src/modelIds.d.ts +2 -0
  47. package/src/outputStore.d.ts +4 -0
  48. package/src/providers/acp.js +320 -299
  49. package/src/providers/acp.ts +360 -0
  50. package/src/providers/antigravity.js +387 -278
  51. package/src/providers/antigravity.ts +450 -0
  52. package/src/providers/base.d.ts +68 -0
  53. package/src/providers/factory.d.ts +1 -0
  54. package/src/provisioning/capabilityProvisioner.d.ts +2 -0
  55. package/src/sandbox.d.ts +1 -0
  56. package/src/sessionJournal.js +14 -1
  57. package/src/sessionJournal.ts +21 -1
  58. package/src/skillsManager.d.ts +3 -0
  59. package/src/slopDetector.d.ts +3 -0
  60. package/src/taskBuffer.d.ts +1 -0
  61. package/src/tokenTracker.d.ts +1 -0
  62. package/src/toolPacks.d.ts +8 -0
  63. package/src/tools/registry.d.ts +4 -0
  64. package/src/tui/chatRenderer.js +148 -8
  65. package/src/tui/clipboardSync.js +36 -0
  66. package/src/tui/clipboardSync.ts +36 -0
  67. package/src/tui/dialogs.js +15 -2
  68. package/src/tui/home.js +2 -1
  69. package/src/tui/modelPicker.js +254 -0
  70. package/src/tui/modelPicker.ts +318 -0
  71. package/src/tui/prompt.js +90 -8
  72. package/src/tui/selectList.js +20 -0
  73. package/src/tui/sessionPicker.js +185 -0
  74. package/src/tui/sessionPicker.ts +259 -0
  75. package/src/tui/stageSurface.js +9 -0
  76. package/src/tui/statusLine.js +5 -5
@@ -0,0 +1,63 @@
1
+ // Continuum Ingestion Engine: adopts peer agent sessions into Causyne's native journal.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ import { ContinuumScanner } from './scanner.js';
4
+ import { compactContinuumMessages } from './compactor.js';
5
+ import { createSession, saveSessionMessages, getActiveSessionId, getSession, setActiveSession } from '../sessionJournal.js';
6
+ /**
7
+ * Safely adopt an external agent's session into Causyne's active session journal.
8
+ * Automatically saves and checkpoints any existing active session so no data is ever lost.
9
+ */
10
+ export async function adoptContinuumSession(target, options = {}) {
11
+ let detail = null;
12
+ let targetId = typeof target === 'string' ? target : target.id;
13
+ if (typeof target === 'string') {
14
+ const scanner = options.scanner || new ContinuumScanner();
15
+ detail = await scanner.fetchSession(target);
16
+ }
17
+ else {
18
+ detail = target;
19
+ }
20
+ if (!detail || !detail.messages || detail.messages.length === 0) {
21
+ return {
22
+ ok: false,
23
+ sessionId: targetId,
24
+ title: 'Unknown',
25
+ sourcePlatform: 'antigravity',
26
+ messageCount: 0,
27
+ error: `Could not load session "${targetId}". It may have been moved or removed.`
28
+ };
29
+ }
30
+ // 1. Checkpoint current active session if it holds unsaved messages
31
+ const currentActiveId = getActiveSessionId();
32
+ if (currentActiveId && options.currentLoopMessages && options.currentLoopMessages.length > 0) {
33
+ const existing = getSession(currentActiveId);
34
+ if (existing) {
35
+ saveSessionMessages(currentActiveId, options.currentLoopMessages);
36
+ }
37
+ }
38
+ // 2. Compact messages & inject Continuum handshake anchor
39
+ const compacted = compactContinuumMessages(detail.messages, {
40
+ platform: detail.sourcePlatform,
41
+ sourceTitle: detail.title,
42
+ originalWorkspace: detail.workspacePath
43
+ });
44
+ // 3. Create a new sovereign Causyne session
45
+ const targetWorkspace = options.workspace || process.cwd();
46
+ const title = `[Adopted] ${detail.title}`;
47
+ const newSession = createSession(targetWorkspace, title, true);
48
+ // 4. Ingest compacted messages into journal
49
+ const sessionMessages = compacted.map(m => ({
50
+ role: m.role,
51
+ content: m.content
52
+ }));
53
+ saveSessionMessages(newSession.id, sessionMessages);
54
+ setActiveSession(newSession.id);
55
+ return {
56
+ ok: true,
57
+ sessionId: newSession.id,
58
+ title: newSession.title,
59
+ sourcePlatform: detail.sourcePlatform,
60
+ messageCount: sessionMessages.length,
61
+ preservedActiveSessionId: currentActiveId
62
+ };
63
+ }
@@ -0,0 +1,89 @@
1
+ // Continuum Ingestion Engine: adopts peer agent sessions into Causyne's native journal.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+
4
+ import type { ContinuumAdoptResult, ContinuumSessionDetail } from './types.js';
5
+ import { ContinuumScanner } from './scanner.js';
6
+ import { compactContinuumMessages } from './compactor.js';
7
+ import {
8
+ createSession,
9
+ saveSessionMessages,
10
+ getActiveSessionId,
11
+ getSession,
12
+ setActiveSession,
13
+ type SessionMessage
14
+ } from '../sessionJournal.js';
15
+
16
+ export interface IngestOptions {
17
+ workspace?: string | undefined;
18
+ scanner?: ContinuumScanner | undefined;
19
+ currentLoopMessages?: Array<{ role: string; content?: unknown }> | undefined;
20
+ }
21
+
22
+ /**
23
+ * Safely adopt an external agent's session into Causyne's active session journal.
24
+ * Automatically saves and checkpoints any existing active session so no data is ever lost.
25
+ */
26
+ export async function adoptContinuumSession(
27
+ target: string | ContinuumSessionDetail,
28
+ options: IngestOptions = {}
29
+ ): Promise<ContinuumAdoptResult> {
30
+ let detail: ContinuumSessionDetail | null = null;
31
+ let targetId = typeof target === 'string' ? target : target.id;
32
+
33
+ if (typeof target === 'string') {
34
+ const scanner = options.scanner || new ContinuumScanner();
35
+ detail = await scanner.fetchSession(target);
36
+ } else {
37
+ detail = target;
38
+ }
39
+
40
+ if (!detail || !detail.messages || detail.messages.length === 0) {
41
+ return {
42
+ ok: false,
43
+ sessionId: targetId,
44
+ title: 'Unknown',
45
+ sourcePlatform: 'antigravity',
46
+ messageCount: 0,
47
+ error: `Could not load session "${targetId}". It may have been moved or removed.`
48
+ };
49
+ }
50
+
51
+ // 1. Checkpoint current active session if it holds unsaved messages
52
+ const currentActiveId = getActiveSessionId();
53
+ if (currentActiveId && options.currentLoopMessages && options.currentLoopMessages.length > 0) {
54
+ const existing = getSession(currentActiveId);
55
+ if (existing) {
56
+ saveSessionMessages(currentActiveId, options.currentLoopMessages as SessionMessage[]);
57
+ }
58
+ }
59
+
60
+ // 2. Compact messages & inject Continuum handshake anchor
61
+ const compacted = compactContinuumMessages(detail.messages, {
62
+ platform: detail.sourcePlatform,
63
+ sourceTitle: detail.title,
64
+ originalWorkspace: detail.workspacePath
65
+ });
66
+
67
+ // 3. Create a new sovereign Causyne session
68
+ const targetWorkspace = options.workspace || process.cwd();
69
+ const title = `[Adopted] ${detail.title}`;
70
+ const newSession = createSession(targetWorkspace, title, true);
71
+
72
+ // 4. Ingest compacted messages into journal
73
+ const sessionMessages: SessionMessage[] = compacted.map(m => ({
74
+ role: m.role,
75
+ content: m.content
76
+ }));
77
+
78
+ saveSessionMessages(newSession.id, sessionMessages);
79
+ setActiveSession(newSession.id);
80
+
81
+ return {
82
+ ok: true,
83
+ sessionId: newSession.id,
84
+ title: newSession.title,
85
+ sourcePlatform: detail.sourcePlatform,
86
+ messageCount: sessionMessages.length,
87
+ preservedActiveSessionId: currentActiveId
88
+ };
89
+ }
@@ -0,0 +1,55 @@
1
+ // Sanitizer for cross-agent prompt wrappers and verbose tool dumps.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ /** Strip bulky system wrapper tags and metadata blocks from user prompt. */
4
+ export function cleanUserText(text) {
5
+ if (!text)
6
+ return '';
7
+ let str = String(text);
8
+ str = str.replace(/<\/?USER_REQUEST>/gi, '');
9
+ if (str.includes('<ADDITIONAL_METADATA>')) {
10
+ str = str.split(/<ADDITIONAL_METADATA>/i)[0] || '';
11
+ }
12
+ if (str.includes('<environment_context>')) {
13
+ const parts = str.split(/<\/environment_context>/i);
14
+ if (parts.length > 1) {
15
+ str = parts.slice(1).join('\n');
16
+ }
17
+ }
18
+ if (str.includes('<causyne_universal_skills>')) {
19
+ const parts = str.split(/<\/causyne_universal_skills>/i);
20
+ if (parts.length > 1) {
21
+ str = parts.slice(1).join('\n');
22
+ }
23
+ }
24
+ if (str.includes('## My request:')) {
25
+ const parts = str.split('## My request:');
26
+ if (parts.length > 1) {
27
+ str = parts.slice(1).join('\n');
28
+ }
29
+ }
30
+ // Remove common internal system instruction blocks if embedded inside user turn
31
+ str = str.replace(/\[System Instructions\][\s\S]*?(?=\[User\]|\n\n[a-zA-Z0-9]|$)/gi, '');
32
+ const lines = str
33
+ .split(/\r?\n/)
34
+ .map(line => line.trim())
35
+ .filter(line => line.length > 0);
36
+ return lines.join('\n').trim();
37
+ }
38
+ /** Summarize and truncate excessive tool dump text while preserving answer & rationale. */
39
+ export function cleanAssistantText(text, maxChars = 2000) {
40
+ if (!text)
41
+ return '';
42
+ const str = String(text).trim();
43
+ if (str.length <= maxChars) {
44
+ return str;
45
+ }
46
+ const half = Math.floor(maxChars / 2);
47
+ return `${str.slice(0, half)}\n\n... [output condensed for context efficiency] ...\n\n${str.slice(-half)}`;
48
+ }
49
+ /** Extract a clean, meaningful title from the first user request. */
50
+ export function deriveSessionTitle(firstPrompt, fallback = 'Untitled Session') {
51
+ const clean = cleanUserText(firstPrompt).replace(/\s+/g, ' ').trim();
52
+ if (!clean)
53
+ return fallback;
54
+ return clean.length > 60 ? `${clean.slice(0, 57)}…` : clean;
55
+ }
@@ -0,0 +1,59 @@
1
+ // Sanitizer for cross-agent prompt wrappers and verbose tool dumps.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+
4
+ /** Strip bulky system wrapper tags and metadata blocks from user prompt. */
5
+ export function cleanUserText(text: unknown): string {
6
+ if (!text) return '';
7
+ let str = String(text);
8
+
9
+ str = str.replace(/<\/?USER_REQUEST>/gi, '');
10
+ if (str.includes('<ADDITIONAL_METADATA>')) {
11
+ str = str.split(/<ADDITIONAL_METADATA>/i)[0] || '';
12
+ }
13
+ if (str.includes('<environment_context>')) {
14
+ const parts = str.split(/<\/environment_context>/i);
15
+ if (parts.length > 1) {
16
+ str = parts.slice(1).join('\n');
17
+ }
18
+ }
19
+ if (str.includes('<causyne_universal_skills>')) {
20
+ const parts = str.split(/<\/causyne_universal_skills>/i);
21
+ if (parts.length > 1) {
22
+ str = parts.slice(1).join('\n');
23
+ }
24
+ }
25
+ if (str.includes('## My request:')) {
26
+ const parts = str.split('## My request:');
27
+ if (parts.length > 1) {
28
+ str = parts.slice(1).join('\n');
29
+ }
30
+ }
31
+
32
+ // Remove common internal system instruction blocks if embedded inside user turn
33
+ str = str.replace(/\[System Instructions\][\s\S]*?(?=\[User\]|\n\n[a-zA-Z0-9]|$)/gi, '');
34
+
35
+ const lines = str
36
+ .split(/\r?\n/)
37
+ .map(line => line.trim())
38
+ .filter(line => line.length > 0);
39
+
40
+ return lines.join('\n').trim();
41
+ }
42
+
43
+ /** Summarize and truncate excessive tool dump text while preserving answer & rationale. */
44
+ export function cleanAssistantText(text: unknown, maxChars = 2000): string {
45
+ if (!text) return '';
46
+ const str = String(text).trim();
47
+ if (str.length <= maxChars) {
48
+ return str;
49
+ }
50
+ const half = Math.floor(maxChars / 2);
51
+ return `${str.slice(0, half)}\n\n... [output condensed for context efficiency] ...\n\n${str.slice(-half)}`;
52
+ }
53
+
54
+ /** Extract a clean, meaningful title from the first user request. */
55
+ export function deriveSessionTitle(firstPrompt: string, fallback = 'Untitled Session'): string {
56
+ const clean = cleanUserText(firstPrompt).replace(/\s+/g, ' ').trim();
57
+ if (!clean) return fallback;
58
+ return clean.length > 60 ? `${clean.slice(0, 57)}…` : clean;
59
+ }
@@ -0,0 +1,86 @@
1
+ // Continuum Scanner: orchestrates dynamic discovery across all peer agent adapters.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ import { AntigravityAdapter } from './adapters/antigravity.js';
4
+ import { OpenCodeAdapter } from './adapters/opencode.js';
5
+ import { CodexAdapter } from './adapters/codex.js';
6
+ import { ClaudeCodeAdapter } from './adapters/claudeCode.js';
7
+ import { CausyneAdapter } from './adapters/causyne.js';
8
+ export class ContinuumScanner {
9
+ adapters;
10
+ constructor(customAdapters) {
11
+ this.adapters = customAdapters || [
12
+ new AntigravityAdapter(),
13
+ new OpenCodeAdapter(),
14
+ new CodexAdapter(),
15
+ new ClaudeCodeAdapter(),
16
+ new CausyneAdapter()
17
+ ];
18
+ }
19
+ getAllAdapters() {
20
+ return this.adapters;
21
+ }
22
+ getAvailableAdapters() {
23
+ return this.adapters.filter(a => a.isAvailable());
24
+ }
25
+ async scanAll(options = {}) {
26
+ return this.scanAllSessions(options);
27
+ }
28
+ async scanAllSessions(options = {}) {
29
+ const activeAdapters = this.getAvailableAdapters().filter(a => {
30
+ if (!options.platform || options.platform === 'all')
31
+ return true;
32
+ return a.platform === options.platform;
33
+ });
34
+ const results = await Promise.allSettled(activeAdapters.map(adapter => adapter.listSessions(options.limit ?? 50)));
35
+ let all = [];
36
+ for (const res of results) {
37
+ if (res.status === 'fulfilled' && Array.isArray(res.value)) {
38
+ all.push(...res.value);
39
+ }
40
+ }
41
+ // Filter by text query if provided
42
+ if (options.query && options.query.trim()) {
43
+ const q = options.query.toLowerCase().trim();
44
+ all = all.filter(s => s.title.toLowerCase().includes(q) ||
45
+ s.snippet.toLowerCase().includes(q) ||
46
+ s.workspacePath.toLowerCase().includes(q) ||
47
+ s.sourceLabel.toLowerCase().includes(q));
48
+ }
49
+ // Filter by workspace if specified
50
+ if (options.workspaceFilter && options.workspaceFilter.trim()) {
51
+ const wf = options.workspaceFilter.toLowerCase().trim();
52
+ all = all.filter(s => s.workspacePath.toLowerCase().includes(wf));
53
+ }
54
+ // Sort by most recently updated
55
+ all.sort((a, b) => b.updatedAt - a.updatedAt);
56
+ if (options.limit && options.limit > 0) {
57
+ return all.slice(0, options.limit);
58
+ }
59
+ return all;
60
+ }
61
+ async fetchSession(id) {
62
+ const colonIndex = id.indexOf(':');
63
+ if (colonIndex === -1) {
64
+ // Try all adapters sequentially
65
+ for (const adapter of this.getAvailableAdapters()) {
66
+ const detail = await adapter.getSession(id);
67
+ if (detail)
68
+ return detail;
69
+ }
70
+ return null;
71
+ }
72
+ const platformPrefix = id.slice(0, colonIndex).toLowerCase();
73
+ const adapter = this.adapters.find(a => a.platform === platformPrefix ||
74
+ (platformPrefix === 'claude' && a.platform === 'claude_code') ||
75
+ (platformPrefix === 'agy' && a.platform === 'antigravity'));
76
+ if (adapter) {
77
+ return adapter.getSession(id);
78
+ }
79
+ for (const a of this.getAvailableAdapters()) {
80
+ const detail = await a.getSession(id);
81
+ if (detail)
82
+ return detail;
83
+ }
84
+ return null;
85
+ }
86
+ }
@@ -0,0 +1,106 @@
1
+ // Continuum Scanner: orchestrates dynamic discovery across all peer agent adapters.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+
4
+ import type { ContinuumAdapter, ContinuumSessionSummary, ContinuumSessionDetail, ContinuumFilterOptions } from './types.js';
5
+ import { AntigravityAdapter } from './adapters/antigravity.js';
6
+ import { OpenCodeAdapter } from './adapters/opencode.js';
7
+ import { CodexAdapter } from './adapters/codex.js';
8
+ import { ClaudeCodeAdapter } from './adapters/claudeCode.js';
9
+ import { CausyneAdapter } from './adapters/causyne.js';
10
+
11
+ export class ContinuumScanner {
12
+ private readonly adapters: ContinuumAdapter[];
13
+
14
+ constructor(customAdapters?: ContinuumAdapter[]) {
15
+ this.adapters = customAdapters || [
16
+ new AntigravityAdapter(),
17
+ new OpenCodeAdapter(),
18
+ new CodexAdapter(),
19
+ new ClaudeCodeAdapter(),
20
+ new CausyneAdapter()
21
+ ];
22
+ }
23
+
24
+ getAllAdapters(): readonly ContinuumAdapter[] {
25
+ return this.adapters;
26
+ }
27
+
28
+ getAvailableAdapters(): ContinuumAdapter[] {
29
+ return this.adapters.filter(a => a.isAvailable());
30
+ }
31
+
32
+ async scanAll(options: ContinuumFilterOptions = {}): Promise<ContinuumSessionSummary[]> {
33
+ return this.scanAllSessions(options);
34
+ }
35
+
36
+ async scanAllSessions(options: ContinuumFilterOptions = {}): Promise<ContinuumSessionSummary[]> {
37
+ const activeAdapters = this.getAvailableAdapters().filter(a => {
38
+ if (!options.platform || options.platform === 'all') return true;
39
+ return a.platform === options.platform;
40
+ });
41
+
42
+ const results = await Promise.allSettled(
43
+ activeAdapters.map(adapter => adapter.listSessions(options.limit ?? 50))
44
+ );
45
+
46
+ let all: ContinuumSessionSummary[] = [];
47
+ for (const res of results) {
48
+ if (res.status === 'fulfilled' && Array.isArray(res.value)) {
49
+ all.push(...res.value);
50
+ }
51
+ }
52
+
53
+ // Filter by text query if provided
54
+ if (options.query && options.query.trim()) {
55
+ const q = options.query.toLowerCase().trim();
56
+ all = all.filter(s =>
57
+ s.title.toLowerCase().includes(q) ||
58
+ s.snippet.toLowerCase().includes(q) ||
59
+ s.workspacePath.toLowerCase().includes(q) ||
60
+ s.sourceLabel.toLowerCase().includes(q)
61
+ );
62
+ }
63
+
64
+ // Filter by workspace if specified
65
+ if (options.workspaceFilter && options.workspaceFilter.trim()) {
66
+ const wf = options.workspaceFilter.toLowerCase().trim();
67
+ all = all.filter(s => s.workspacePath.toLowerCase().includes(wf));
68
+ }
69
+
70
+ // Sort by most recently updated
71
+ all.sort((a, b) => b.updatedAt - a.updatedAt);
72
+
73
+ if (options.limit && options.limit > 0) {
74
+ return all.slice(0, options.limit);
75
+ }
76
+ return all;
77
+ }
78
+
79
+ async fetchSession(id: string): Promise<ContinuumSessionDetail | null> {
80
+ const colonIndex = id.indexOf(':');
81
+ if (colonIndex === -1) {
82
+ // Try all adapters sequentially
83
+ for (const adapter of this.getAvailableAdapters()) {
84
+ const detail = await adapter.getSession(id);
85
+ if (detail) return detail;
86
+ }
87
+ return null;
88
+ }
89
+
90
+ const platformPrefix = id.slice(0, colonIndex).toLowerCase();
91
+ const adapter = this.adapters.find(a =>
92
+ a.platform === platformPrefix ||
93
+ (platformPrefix === 'claude' && a.platform === 'claude_code') ||
94
+ (platformPrefix === 'agy' && a.platform === 'antigravity')
95
+ );
96
+ if (adapter) {
97
+ return adapter.getSession(id);
98
+ }
99
+
100
+ for (const a of this.getAvailableAdapters()) {
101
+ const detail = await a.getSession(id);
102
+ if (detail) return detail;
103
+ }
104
+ return null;
105
+ }
106
+ }
@@ -0,0 +1,3 @@
1
+ // Sovereign Cross-Agent Continuum Engine: Unified Session Types & Contracts.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ export {};
@@ -0,0 +1,51 @@
1
+ // Sovereign Cross-Agent Continuum Engine: Unified Session Types & Contracts.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+
4
+ export type AgentPlatform = 'antigravity' | 'opencode' | 'codex' | 'claude_code' | 'causyne' | 'cursor';
5
+
6
+ export interface ContinuumMessage {
7
+ role: 'user' | 'assistant' | 'system';
8
+ content: string;
9
+ timestamp?: number;
10
+ metadata?: Record<string, unknown>;
11
+ }
12
+
13
+ export interface ContinuumSessionSummary {
14
+ id: string;
15
+ sourcePlatform: AgentPlatform;
16
+ sourceLabel: string;
17
+ title: string;
18
+ workspacePath: string;
19
+ updatedAt: number;
20
+ messageCount: number;
21
+ snippet: string;
22
+ }
23
+
24
+ export interface ContinuumSessionDetail extends ContinuumSessionSummary {
25
+ messages: ContinuumMessage[];
26
+ }
27
+
28
+ export interface ContinuumAdapter {
29
+ readonly platform: AgentPlatform;
30
+ readonly label: string;
31
+ isAvailable(): boolean;
32
+ listSessions(limit?: number): Promise<ContinuumSessionSummary[]>;
33
+ getSession(id: string): Promise<ContinuumSessionDetail | null>;
34
+ }
35
+
36
+ export interface ContinuumFilterOptions {
37
+ platform?: AgentPlatform | 'all';
38
+ query?: string;
39
+ limit?: number;
40
+ workspaceFilter?: string;
41
+ }
42
+
43
+ export interface ContinuumAdoptResult {
44
+ ok: boolean;
45
+ sessionId: string;
46
+ title: string;
47
+ sourcePlatform: AgentPlatform;
48
+ messageCount: number;
49
+ preservedActiveSessionId?: string | null;
50
+ error?: string;
51
+ }
@@ -0,0 +1,111 @@
1
+ // Continuum TUI Picker: interactive modal dialog for browsing and adopting peer agent sessions.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ // @ts-expect-error untyped local TUI dialogs
4
+ import { SelectLayer, TextLayer } from '../../tui/dialogs.js';
5
+ // @ts-expect-error untyped local TUI theme
6
+ import { GLYPHS } from '../../tui/theme.js';
7
+ import { ContinuumScanner } from '../scanner.js';
8
+ import { adoptContinuumSession } from '../ingest.js';
9
+ function formatTimeAgo(timestamp) {
10
+ const diffMs = Date.now() - timestamp;
11
+ const minutes = Math.floor(diffMs / (60 * 1000));
12
+ if (minutes < 60)
13
+ return `${Math.max(1, minutes)}m ago`;
14
+ const hours = Math.floor(minutes / 60);
15
+ if (hours < 24)
16
+ return `${hours}h ago`;
17
+ const days = Math.floor(hours / 24);
18
+ return `${days}d ago`;
19
+ }
20
+ export function buildContinuumItems(sessions) {
21
+ return sessions.map(s => {
22
+ const timeAgo = formatTimeAgo(s.updatedAt);
23
+ const ws = s.workspacePath ? s.workspacePath.split('/').pop() || s.workspacePath : '';
24
+ const desc = `${s.messageCount} msg${s.messageCount === 1 ? '' : 's'} ${GLYPHS.dot} ${timeAgo}${ws ? ` ${GLYPHS.dot} ${ws}` : ''}`;
25
+ return {
26
+ label: s.title,
27
+ description: desc,
28
+ category: s.sourceLabel,
29
+ hint: s.sourceLabel,
30
+ searchText: `${s.sourceLabel} ${s.title} ${s.workspacePath} ${s.snippet}`,
31
+ value: s
32
+ };
33
+ });
34
+ }
35
+ /**
36
+ * Launch the interactive Continuum session picker.
37
+ */
38
+ export async function runInteractiveContinuum(prompt, options = {}) {
39
+ const scanner = options.scanner || new ContinuumScanner();
40
+ const sessions = await scanner.scanAllSessions({ limit: 80 });
41
+ if (sessions.length === 0) {
42
+ return 'No peer agent sessions found across Antigravity, OpenCode, Codex, or Claude Code on this machine.';
43
+ }
44
+ const items = buildContinuumItems(sessions);
45
+ const pickedSession = await new Promise((resolve) => {
46
+ const layer = new SelectLayer({
47
+ title: `Continuum · Cross-Agent Sessions (${sessions.length})`,
48
+ placeholder: 'search past agent conversations (antigravity, opencode, codex, claude)...',
49
+ emptyText: 'no matching sessions found',
50
+ width: 78,
51
+ height: 20,
52
+ footer: `enter adopt session ${GLYPHS.dot} esc cancel`,
53
+ items,
54
+ onPick: (item) => {
55
+ resolve(item ? item.value : null);
56
+ }
57
+ });
58
+ prompt.openLayer(layer);
59
+ });
60
+ if (!pickedSession) {
61
+ return 'Cancelled. Session was not changed.';
62
+ }
63
+ // Ingest the chosen session
64
+ const adoptRes = await adoptContinuumSession(pickedSession.id, {
65
+ scanner,
66
+ currentLoopMessages: options.loop?.messages
67
+ });
68
+ if (!adoptRes.ok) {
69
+ return `Failed to adopt session: ${adoptRes.error}`;
70
+ }
71
+ if (options.loop) {
72
+ if (options.loop.memoryManager) {
73
+ options.loop.memoryManager.useSession(adoptRes.sessionId);
74
+ if (typeof options.loop.memoryManager.loadHistory === 'function') {
75
+ options.loop.messages = options.loop.memoryManager.loadHistory();
76
+ }
77
+ }
78
+ }
79
+ return `✓ Successfully adopted session "${adoptRes.title}" from ${adoptRes.sourcePlatform.toUpperCase()} (${adoptRes.messageCount} messages compacted).\n New active Causyne session: ${adoptRes.sessionId}. Continue working seamlessly.`;
80
+ }
81
+ /**
82
+ * Open a preview text modal showing the full conversation transcript for a session.
83
+ */
84
+ export async function openContinuumPreview(sessionId, prompt, scanner) {
85
+ const sc = scanner || new ContinuumScanner();
86
+ const detail = await sc.fetchSession(sessionId);
87
+ if (!detail || !detail.messages) {
88
+ return false;
89
+ }
90
+ const lines = [
91
+ `Source: ${detail.sourceLabel} · Messages: ${detail.messages.length} · Workspace: ${detail.workspacePath || '(default)'}`,
92
+ '─'.repeat(70),
93
+ ''
94
+ ];
95
+ for (const msg of detail.messages) {
96
+ const rolePrefix = msg.role === 'user' ? '👤 USER' : '🤖 ASSISTANT';
97
+ lines.push(`${rolePrefix}:`);
98
+ for (const textLine of msg.content.split('\n')) {
99
+ lines.push(` ${textLine}`);
100
+ }
101
+ lines.push('');
102
+ }
103
+ const layer = new TextLayer({
104
+ title: `Preview: ${detail.title}`,
105
+ lines,
106
+ width: 76,
107
+ height: 22
108
+ });
109
+ prompt.openLayer(layer);
110
+ return true;
111
+ }