@causyne/agent 1.18.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.
Files changed (69) 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 +10 -3
  6. package/src/commands.js +109 -6
  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/modelIds.d.ts +2 -0
  46. package/src/outputStore.d.ts +4 -0
  47. package/src/providers/acp.js +320 -299
  48. package/src/providers/acp.ts +360 -0
  49. package/src/providers/antigravity.js +387 -278
  50. package/src/providers/antigravity.ts +450 -0
  51. package/src/providers/base.d.ts +68 -0
  52. package/src/providers/factory.d.ts +1 -0
  53. package/src/provisioning/capabilityProvisioner.d.ts +2 -0
  54. package/src/sandbox.d.ts +1 -0
  55. package/src/skillsManager.d.ts +3 -0
  56. package/src/slopDetector.d.ts +3 -0
  57. package/src/taskBuffer.d.ts +1 -0
  58. package/src/tokenTracker.d.ts +1 -0
  59. package/src/toolPacks.d.ts +8 -0
  60. package/src/tools/registry.d.ts +4 -0
  61. package/src/tui/chatRenderer.js +62 -8
  62. package/src/tui/clipboardSync.js +36 -0
  63. package/src/tui/clipboardSync.ts +36 -0
  64. package/src/tui/dialogs.js +15 -2
  65. package/src/tui/home.js +2 -1
  66. package/src/tui/modelPicker.js +221 -0
  67. package/src/tui/modelPicker.ts +290 -0
  68. package/src/tui/prompt.js +17 -6
  69. package/src/tui/selectList.js +20 -0
@@ -0,0 +1,54 @@
1
+ // Continuum Context Compactor: protects token budgets and preserves Root Anchor Intent.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ /**
4
+ * Compact a long multi-turn peer conversation into an optimal context window
5
+ * without losing root intention or recent critical decisions.
6
+ */
7
+ export function compactContinuumMessages(messages, options = {}) {
8
+ const maxTurns = options.maxTurns ?? 30;
9
+ const recentTurns = options.recentTurns ?? 12;
10
+ if (messages.length <= maxTurns) {
11
+ return prefixHandshake(messages, options);
12
+ }
13
+ // Find root anchor (first user message)
14
+ const rootIndex = messages.findIndex(m => m.role === 'user');
15
+ const rootMessage = rootIndex !== -1
16
+ ? messages[rootIndex]
17
+ : { role: 'user', content: 'Initial user turn' };
18
+ const recentStart = messages.length - recentTurns;
19
+ const recent = messages.slice(recentStart);
20
+ // If the root intent is already within the recent window, simply return recent
21
+ if (rootIndex !== -1 && rootIndex >= recentStart) {
22
+ return prefixHandshake(recent, options);
23
+ }
24
+ // Summarize middle turns between root and recent
25
+ const middleStart = rootIndex !== -1 ? rootIndex + 1 : 0;
26
+ const middleEnd = recentStart;
27
+ const middleCount = Math.max(0, middleEnd - middleStart);
28
+ const middleSummaryText = `[Continuum Context Condensation]\n` +
29
+ `Preserved initial root intent and the last ${recent.length} active turns.\n` +
30
+ `${middleCount} intermediate turns were compressed. ` +
31
+ `Original agent: ${options.platform || 'peer agent'}, topic: "${options.sourceTitle || 'Untitled'}".`;
32
+ const condensedMiddle = {
33
+ role: 'system',
34
+ content: middleSummaryText
35
+ };
36
+ const compacted = [
37
+ rootMessage,
38
+ condensedMiddle,
39
+ ...recent
40
+ ];
41
+ return prefixHandshake(compacted, options);
42
+ }
43
+ function prefixHandshake(messages, options) {
44
+ const platformLabel = options.platform ? options.platform.toUpperCase() : 'PEER AGENT';
45
+ const header = `[Continuum Handshake · Adopted from ${platformLabel}]\n` +
46
+ `Session: "${options.sourceTitle || 'Untitled'}"\n` +
47
+ `Original workspace: ${options.originalWorkspace || '(unspecified)'}\n` +
48
+ `Status: Adopted into Causyne Agent foreground session. Seamlessly continue the user's objective.`;
49
+ const anchorMessage = {
50
+ role: 'system',
51
+ content: header
52
+ };
53
+ return [anchorMessage, ...messages];
54
+ }
@@ -0,0 +1,83 @@
1
+ // Continuum Context Compactor: protects token budgets and preserves Root Anchor Intent.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+
4
+ import type { ContinuumMessage, AgentPlatform } from './types.js';
5
+
6
+ export interface CompactionOptions {
7
+ maxTurns?: number;
8
+ recentTurns?: number;
9
+ platform?: AgentPlatform;
10
+ sourceTitle?: string;
11
+ originalWorkspace?: string;
12
+ }
13
+
14
+ /**
15
+ * Compact a long multi-turn peer conversation into an optimal context window
16
+ * without losing root intention or recent critical decisions.
17
+ */
18
+ export function compactContinuumMessages(
19
+ messages: ContinuumMessage[],
20
+ options: CompactionOptions = {}
21
+ ): ContinuumMessage[] {
22
+ const maxTurns = options.maxTurns ?? 30;
23
+ const recentTurns = options.recentTurns ?? 12;
24
+
25
+ if (messages.length <= maxTurns) {
26
+ return prefixHandshake(messages, options);
27
+ }
28
+
29
+ // Find root anchor (first user message)
30
+ const rootIndex = messages.findIndex(m => m.role === 'user');
31
+ const rootMessage: ContinuumMessage = rootIndex !== -1
32
+ ? messages[rootIndex]!
33
+ : { role: 'user', content: 'Initial user turn' };
34
+
35
+ const recentStart = messages.length - recentTurns;
36
+ const recent = messages.slice(recentStart);
37
+
38
+ // If the root intent is already within the recent window, simply return recent
39
+ if (rootIndex !== -1 && rootIndex >= recentStart) {
40
+ return prefixHandshake(recent, options);
41
+ }
42
+
43
+ // Summarize middle turns between root and recent
44
+ const middleStart = rootIndex !== -1 ? rootIndex + 1 : 0;
45
+ const middleEnd = recentStart;
46
+ const middleCount = Math.max(0, middleEnd - middleStart);
47
+
48
+ const middleSummaryText = `[Continuum Context Condensation]\n` +
49
+ `Preserved initial root intent and the last ${recent.length} active turns.\n` +
50
+ `${middleCount} intermediate turns were compressed. ` +
51
+ `Original agent: ${options.platform || 'peer agent'}, topic: "${options.sourceTitle || 'Untitled'}".`;
52
+
53
+ const condensedMiddle: ContinuumMessage = {
54
+ role: 'system',
55
+ content: middleSummaryText
56
+ };
57
+
58
+ const compacted: ContinuumMessage[] = [
59
+ rootMessage,
60
+ condensedMiddle,
61
+ ...recent
62
+ ];
63
+
64
+ return prefixHandshake(compacted, options);
65
+ }
66
+
67
+ function prefixHandshake(
68
+ messages: ContinuumMessage[],
69
+ options: CompactionOptions
70
+ ): ContinuumMessage[] {
71
+ const platformLabel = options.platform ? options.platform.toUpperCase() : 'PEER AGENT';
72
+ const header = `[Continuum Handshake · Adopted from ${platformLabel}]\n` +
73
+ `Session: "${options.sourceTitle || 'Untitled'}"\n` +
74
+ `Original workspace: ${options.originalWorkspace || '(unspecified)'}\n` +
75
+ `Status: Adopted into Causyne Agent foreground session. Seamlessly continue the user's objective.`;
76
+
77
+ const anchorMessage: ContinuumMessage = {
78
+ role: 'system',
79
+ content: header
80
+ };
81
+
82
+ return [anchorMessage, ...messages];
83
+ }
@@ -0,0 +1,8 @@
1
+ // Causyne Continuum: Universal Cross-Agent Session Extraction, Inspection & Adoption Engine.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+ export * from './types.js';
4
+ export * from './sanitizer.js';
5
+ export * from './compactor.js';
6
+ export * from './scanner.js';
7
+ export * from './ingest.js';
8
+ export * from './ui/continuumPicker.js';
@@ -0,0 +1,9 @@
1
+ // Causyne Continuum: Universal Cross-Agent Session Extraction, Inspection & Adoption Engine.
2
+ // Authorship: Strict TypeScript (Causyne Agent).
3
+
4
+ export * from './types.js';
5
+ export * from './sanitizer.js';
6
+ export * from './compactor.js';
7
+ export * from './scanner.js';
8
+ export * from './ingest.js';
9
+ export * from './ui/continuumPicker.js';
@@ -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 || detail.workspacePath || 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 || detail.workspacePath || 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
+ }