@causyne/agent 1.20.0 → 1.20.7
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/README.md +13 -9
- package/SECURITY.md +1 -4
- package/package.json +1 -1
- package/src/acp/client.js +176 -26
- package/src/acp/client.ts +167 -25
- package/src/acp/protocol.js +116 -0
- package/src/acp/protocol.ts +163 -0
- package/src/acp/server.js +5 -6
- package/src/acp/server.ts +4 -6
- package/src/agentLoop.d.ts +1 -0
- package/src/agentLoop.js +681 -245
- package/src/agentLoop.ts +708 -262
- package/src/agentPolicy.js +9 -0
- package/src/agentPolicy.ts +9 -0
- package/src/approvalPolicy.js +55 -0
- package/src/approvalPolicy.ts +66 -0
- package/src/browser/browserRuntime.js +217 -14
- package/src/browser/browserRuntime.ts +255 -14
- package/src/browser/causyneBrowser.js +1215 -68
- package/src/browser/causyneBrowser.ts +1340 -72
- package/src/cliMode.js +52 -29
- package/src/commands.js +141 -17
- package/src/config.js +22 -12
- package/src/continuum/ui/continuumPicker.js +18 -1
- package/src/continuum/ui/continuumPicker.ts +19 -1
- package/src/dynamicCatalogue.js +87 -20
- package/src/dynamicCatalogue.ts +85 -15
- package/src/launchIntent.js +40 -0
- package/src/launchIntent.ts +49 -0
- package/src/memoryManager.js +26 -2
- package/src/modelCatalogue.js +2 -0
- package/src/planCache.js +320 -11
- package/src/planCache.ts +402 -13
- package/src/providers/acp.js +173 -18
- package/src/providers/acp.ts +169 -19
- package/src/providers/antigravity.d.ts +5 -1
- package/src/providers/antigravity.js +674 -34
- package/src/providers/antigravity.ts +707 -35
- package/src/providers/base.d.ts +10 -0
- package/src/providers/factory.js +2 -0
- package/src/providers/pi.js +161 -0
- package/src/providers/pi.ts +148 -0
- package/src/provisioning/capabilityProvisioner.js +17 -0
- package/src/provisioning/capabilityTools.js +1 -1
- package/src/sandbox.js +30 -39
- package/src/sessionJournal.js +53 -10
- package/src/sessionJournal.ts +64 -10
- package/src/taskShape.js +9 -9
- package/src/taskShape.ts +9 -9
- package/src/timeMachine.js +124 -0
- package/src/timeMachine.ts +141 -0
- package/src/toolPacks.js +4 -10
- package/src/tools/archive.js +196 -59
- package/src/tools/archive.ts +220 -0
- package/src/tools/browserAutomator.js +78 -9
- package/src/tools/browserAutomator.ts +90 -9
- package/src/tools/desktopOpen.js +114 -31
- package/src/tools/desktopOpen.ts +144 -0
- package/src/tools/gitExec.js +5 -3
- package/src/tools/nativeEngine.js +4 -3
- package/src/tools/nativeEngine.ts +5 -3
- package/src/tools/openSourceToolProvisioner.js +5 -4
- package/src/tools/openSourceToolProvisioner.ts +5 -4
- package/src/tools/registry.js +3 -0
- package/src/tools/screenshot.js +55 -71
- package/src/tools/screenshot.ts +70 -0
- package/src/tools/sysRun.js +284 -117
- package/src/tools/sysRun.ts +347 -0
- package/src/tools/toolSelfRepair.js +109 -2
- package/src/tools/toolSelfRepair.ts +100 -2
- package/src/tools/updatePlan.js +49 -1
- package/src/tools/updatePlan.ts +43 -1
- package/src/tools/viewImage.js +93 -78
- package/src/tools/viewImage.ts +116 -0
- package/src/tools/webFetch.js +20 -6
- package/src/tools/webFetch.ts +26 -6
- package/src/tui/activityLayout.js +9 -0
- package/src/tui/activityLayout.ts +10 -0
- package/src/tui/block.d.ts +1 -0
- package/src/tui/chatRenderer.d.ts +23 -0
- package/src/tui/chatRenderer.js +49 -49
- package/src/tui/clipboardSync.js +28 -1
- package/src/tui/clipboardSync.ts +26 -1
- package/src/tui/codeProgress.js +299 -0
- package/src/tui/codeProgress.ts +304 -0
- package/src/tui/codeStreamRenderer.js +132 -0
- package/src/tui/codeStreamRenderer.ts +141 -0
- package/src/tui/commandPresentation.js +11 -0
- package/src/tui/commandPresentation.ts +18 -0
- package/src/tui/completion.js +45 -13
- package/src/tui/composerControls.js +131 -0
- package/src/tui/composerControls.ts +184 -0
- package/src/tui/diff.d.ts +2 -0
- package/src/tui/home.js +4 -2
- package/src/tui/homeTransition.js +21 -0
- package/src/tui/homeTransition.ts +27 -0
- package/src/tui/homeView.js +62 -0
- package/src/tui/homeView.ts +91 -0
- package/src/tui/layout.js +46 -0
- package/src/tui/layout.ts +52 -0
- package/src/tui/messageActionPlacement.js +16 -0
- package/src/tui/messageActionPlacement.ts +25 -0
- package/src/tui/messageInteraction.js +221 -0
- package/src/tui/messageInteraction.ts +275 -0
- package/src/tui/modelPicker.js +4 -24
- package/src/tui/modelPicker.ts +4 -20
- package/src/tui/mouseHover.js +6 -0
- package/src/tui/mouseHover.ts +5 -0
- package/src/tui/prompt.js +175 -101
- package/src/tui/resizeRecovery.js +15 -0
- package/src/tui/resizeRecovery.ts +27 -0
- package/src/tui/scrollInteraction.js +97 -0
- package/src/tui/scrollInteraction.ts +189 -0
- package/src/tui/sessionLayout.js +12 -0
- package/src/tui/sessionLayout.ts +12 -0
- package/src/tui/sessionPicker.js +111 -16
- package/src/tui/sessionPicker.ts +121 -16
- package/src/tui/sessionSidebar.js +78 -0
- package/src/tui/sessionSidebar.ts +95 -0
- package/src/tui/setup.js +1 -1
- package/src/tui/setup.ts +1 -1
- package/src/tui/stageSurface.js +120 -58
- package/src/tui/text.d.ts +6 -0
- package/src/tui/textLayout.js +23 -0
- package/src/tui/textLayout.ts +28 -0
- package/src/tui/viewport.js +204 -279
- package/src/tui/viewport.ts +326 -0
- package/src/types/contracts.ts +54 -0
- package/src/utils/paths.js +5 -4
- package/src/utils/paths.ts +5 -5
package/src/providers/base.d.ts
CHANGED
|
@@ -27,12 +27,21 @@ export interface ChatResponseToolCall {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
export interface ChatResponseAction {
|
|
31
|
+
name: string;
|
|
32
|
+
status: 'running' | 'completed' | 'failed';
|
|
33
|
+
detail?: string | undefined;
|
|
34
|
+
parameters?: Record<string, unknown> | undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
export interface ChatResponse {
|
|
31
38
|
content: string;
|
|
32
39
|
usage: ChatResponseUsage;
|
|
33
40
|
toolCalls?: ChatResponseToolCall[] | undefined;
|
|
34
41
|
reasoningContent?: string | undefined;
|
|
35
42
|
thinkingBlocks?: any[] | undefined;
|
|
43
|
+
externalActions?: ChatResponseAction[] | undefined;
|
|
44
|
+
incompleteTurn?: boolean | undefined;
|
|
36
45
|
}
|
|
37
46
|
|
|
38
47
|
export interface ChatOptions {
|
|
@@ -42,6 +51,7 @@ export interface ChatOptions {
|
|
|
42
51
|
signal?: AbortSignal | undefined;
|
|
43
52
|
onChunk?: ((chunk: string) => void) | undefined;
|
|
44
53
|
onReasoningChunk?: ((chunk: string) => void) | undefined;
|
|
54
|
+
onNativeAction?: ((action: ChatResponseAction) => void) | undefined;
|
|
45
55
|
coreToolCount?: number | undefined;
|
|
46
56
|
[key: string]: any;
|
|
47
57
|
}
|
package/src/providers/factory.js
CHANGED
|
@@ -17,6 +17,7 @@ import { XAIProvider } from './xai.js';
|
|
|
17
17
|
import { MoonshotProvider } from './moonshot.js';
|
|
18
18
|
import { MuseProvider } from './muse.js';
|
|
19
19
|
import { AcpProvider, isAcpProvider } from './acp.js';
|
|
20
|
+
import { PiProvider, isPiProvider } from './pi.js';
|
|
20
21
|
import { AntigravityProvider, isAntigravityProvider } from './antigravity.js';
|
|
21
22
|
|
|
22
23
|
export function createProvider(config) {
|
|
@@ -35,6 +36,7 @@ export function createProvider(config) {
|
|
|
35
36
|
// model family is Muse, and users say either.
|
|
36
37
|
if (p === 'muse' || p === 'meta') return new MuseProvider(config);
|
|
37
38
|
if (isAcpProvider(p)) return new AcpProvider(config);
|
|
39
|
+
if (isPiProvider(p)) return new PiProvider(config);
|
|
38
40
|
if (isAntigravityProvider(p)) return new AntigravityProvider(config);
|
|
39
41
|
|
|
40
42
|
throw new Error("API Key Required. Causyne is a 100% Sovereign BYOK Engine. Please configure your API Provider and Key in Settings.");
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { AcpProvider } from './acp.js';
|
|
3
|
+
import { LLMProvider } from './base.js';
|
|
4
|
+
export function isPiProvider(provider) {
|
|
5
|
+
return typeof provider === 'string' && provider.toLowerCase() === 'pi';
|
|
6
|
+
}
|
|
7
|
+
export const PI_SETUP_PROVIDER = {
|
|
8
|
+
id: 'pi', label: 'Pi coding agent', hint: 'local Pi RPC · uses Causyne tools',
|
|
9
|
+
category: 'Peer Agent', model: 'default'
|
|
10
|
+
};
|
|
11
|
+
/** Pi supplies reasoning over RPC; Causyne remains the sole executor of tools. */
|
|
12
|
+
export class PiProvider extends LLMProvider {
|
|
13
|
+
command;
|
|
14
|
+
formatter;
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
super(config);
|
|
17
|
+
this.command = config.command || 'pi';
|
|
18
|
+
this.model = config.model || 'default';
|
|
19
|
+
this.formatter = new AcpProvider({ provider: 'acp/opencode' });
|
|
20
|
+
this.visionModels = [];
|
|
21
|
+
this.audioModels = [];
|
|
22
|
+
}
|
|
23
|
+
async chat(messages, options = {}) {
|
|
24
|
+
const args = ['--mode', 'rpc', '--no-session', '--no-tools', '--no-extensions',
|
|
25
|
+
'--no-mcp', '--no-context-files', '--no-skills', '--no-prompt-templates'];
|
|
26
|
+
if (this.model !== 'default')
|
|
27
|
+
args.push('--model', this.model);
|
|
28
|
+
const cwd = typeof options.workspaceRoot === 'string' && options.workspaceRoot
|
|
29
|
+
? options.workspaceRoot : process.cwd();
|
|
30
|
+
const prompt = this.formatter.formatConversation(messages, options.tools || [])
|
|
31
|
+
.replace('over ACP.', 'over Pi RPC.');
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const child = spawn(this.command, args, { cwd, stdio: ['pipe', 'pipe', 'pipe'],
|
|
34
|
+
env: process.env, shell: false });
|
|
35
|
+
let buffer = '';
|
|
36
|
+
let stderr = '';
|
|
37
|
+
let streamed = '';
|
|
38
|
+
let finalText = '';
|
|
39
|
+
let stopReason = '';
|
|
40
|
+
let acknowledged = false;
|
|
41
|
+
let settled = false;
|
|
42
|
+
let finished = false;
|
|
43
|
+
let usage = { promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0 };
|
|
44
|
+
const cleanup = () => {
|
|
45
|
+
options.signal?.removeEventListener('abort', abort);
|
|
46
|
+
child.stdin.end();
|
|
47
|
+
if (!child.killed)
|
|
48
|
+
child.kill();
|
|
49
|
+
};
|
|
50
|
+
const fail = (error) => {
|
|
51
|
+
if (finished)
|
|
52
|
+
return;
|
|
53
|
+
finished = true;
|
|
54
|
+
cleanup();
|
|
55
|
+
reject(error);
|
|
56
|
+
};
|
|
57
|
+
const complete = () => {
|
|
58
|
+
if (finished || !acknowledged || !settled)
|
|
59
|
+
return;
|
|
60
|
+
if (stopReason === 'error' || stopReason === 'aborted') {
|
|
61
|
+
fail(new Error(`Pi ended with ${stopReason}${stderr ? `: ${stderr.slice(-400)}` : ''}`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
finished = true;
|
|
65
|
+
cleanup();
|
|
66
|
+
const raw = finalText || streamed;
|
|
67
|
+
resolve({
|
|
68
|
+
content: raw.replace(/<tool_call>[\s\S]*?<\/tool_call>/g, '').trim(),
|
|
69
|
+
usage,
|
|
70
|
+
toolCalls: this.formatter.extractToolCalls(raw)
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const abort = () => {
|
|
74
|
+
const err = new Error('Pi request aborted');
|
|
75
|
+
err.name = 'AbortError';
|
|
76
|
+
fail(err);
|
|
77
|
+
};
|
|
78
|
+
if (options.signal?.aborted) {
|
|
79
|
+
abort();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
83
|
+
const handle = (record) => {
|
|
84
|
+
if (record.type === 'response' && record.id === 'causyne-state') {
|
|
85
|
+
if (!record.success || !record.data?.model
|
|
86
|
+
|| record.data.model.provider === 'unknown' || record.data.model.id === 'unknown') {
|
|
87
|
+
fail(new Error('Pi has no active model. Open Pi and configure a model login before selecting Pi in Causyne.'));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
child.stdin.write(JSON.stringify({ id: 'causyne-prompt', type: 'prompt', message: prompt }) + '\n');
|
|
91
|
+
}
|
|
92
|
+
else if (record.type === 'response' && record.id === 'causyne-prompt') {
|
|
93
|
+
if (!record.success) {
|
|
94
|
+
fail(new Error(`Pi rejected the prompt: ${String(record.error || 'unknown error')}`));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
acknowledged = true;
|
|
98
|
+
if (record.data?.disposition === 'handled')
|
|
99
|
+
settled = true;
|
|
100
|
+
complete();
|
|
101
|
+
}
|
|
102
|
+
else if (record.type === 'message_update') {
|
|
103
|
+
const update = record.assistantMessageEvent;
|
|
104
|
+
if (update?.type === 'text_delta' && typeof update.delta === 'string') {
|
|
105
|
+
streamed += update.delta;
|
|
106
|
+
options.onChunk?.(update.delta);
|
|
107
|
+
}
|
|
108
|
+
else if (update?.type === 'thinking_delta' && typeof update.delta === 'string') {
|
|
109
|
+
options.onReasoningChunk?.(update.delta);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (record.type === 'message_end' && record.message?.role === 'assistant') {
|
|
113
|
+
const message = record.message;
|
|
114
|
+
finalText = Array.isArray(message.content)
|
|
115
|
+
? message.content.filter((part) => part?.type === 'text').map((part) => String(part.text || '')).join('')
|
|
116
|
+
: String(message.content || '');
|
|
117
|
+
stopReason = String(message.stopReason || '');
|
|
118
|
+
const data = message.usage || {};
|
|
119
|
+
usage = {
|
|
120
|
+
promptTokens: Number(data.input) || 0,
|
|
121
|
+
completionTokens: Number(data.output) || 0,
|
|
122
|
+
cachedPromptTokens: Number(data.cacheRead) || 0
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
else if (record.type === 'agent_settled') {
|
|
126
|
+
if (record.aborted)
|
|
127
|
+
stopReason = 'aborted';
|
|
128
|
+
settled = true;
|
|
129
|
+
complete();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
child.stdout.setEncoding('utf8');
|
|
133
|
+
child.stdout.on('data', (chunk) => {
|
|
134
|
+
buffer += chunk;
|
|
135
|
+
let index;
|
|
136
|
+
while ((index = buffer.indexOf('\n')) >= 0) {
|
|
137
|
+
const line = buffer.slice(0, index).replace(/\r$/, '');
|
|
138
|
+
buffer = buffer.slice(index + 1);
|
|
139
|
+
if (!line)
|
|
140
|
+
continue;
|
|
141
|
+
try {
|
|
142
|
+
handle(JSON.parse(line));
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
fail(new Error(`Invalid Pi RPC record: ${String(error)}`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
child.stderr.setEncoding('utf8');
|
|
151
|
+
child.stderr.on('data', (chunk) => { stderr = (stderr + chunk).slice(-2000); });
|
|
152
|
+
child.on('error', error => fail(new Error(`Pi CLI unavailable: ${error.message}`)));
|
|
153
|
+
child.on('close', code => {
|
|
154
|
+
if (!finished)
|
|
155
|
+
fail(new Error(`Pi RPC exited before completion (${code ?? 'unknown'})${stderr ? `: ${stderr.slice(-400)}` : ''}`));
|
|
156
|
+
});
|
|
157
|
+
child.stdin.on('error', error => fail(new Error(`Pi RPC input failed: ${error.message}`)));
|
|
158
|
+
child.stdin.write(JSON.stringify({ id: 'causyne-state', type: 'get_state' }) + '\n');
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { AcpProvider } from './acp.js';
|
|
3
|
+
import { LLMProvider, type ProviderConfig, type ChatOptions, type ChatResponse } from './base.js';
|
|
4
|
+
|
|
5
|
+
export function isPiProvider(provider?: string | null): boolean {
|
|
6
|
+
return typeof provider === 'string' && provider.toLowerCase() === 'pi';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const PI_SETUP_PROVIDER = {
|
|
10
|
+
id: 'pi', label: 'Pi coding agent', hint: 'local Pi RPC · uses Causyne tools',
|
|
11
|
+
category: 'Peer Agent', model: 'default'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Pi supplies reasoning over RPC; Causyne remains the sole executor of tools. */
|
|
15
|
+
export class PiProvider extends LLMProvider {
|
|
16
|
+
private readonly command: string;
|
|
17
|
+
private readonly formatter: AcpProvider;
|
|
18
|
+
|
|
19
|
+
constructor(config: ProviderConfig = {}) {
|
|
20
|
+
super(config);
|
|
21
|
+
this.command = config.command || 'pi';
|
|
22
|
+
this.model = config.model || 'default';
|
|
23
|
+
this.formatter = new AcpProvider({ provider: 'acp/opencode' });
|
|
24
|
+
this.visionModels = [];
|
|
25
|
+
this.audioModels = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override async chat(messages: unknown[], options: ChatOptions = {}): Promise<ChatResponse> {
|
|
29
|
+
const args = ['--mode', 'rpc', '--no-session', '--no-tools', '--no-extensions',
|
|
30
|
+
'--no-mcp', '--no-context-files', '--no-skills', '--no-prompt-templates'];
|
|
31
|
+
if (this.model !== 'default') args.push('--model', this.model);
|
|
32
|
+
const cwd = typeof options.workspaceRoot === 'string' && options.workspaceRoot
|
|
33
|
+
? options.workspaceRoot : process.cwd();
|
|
34
|
+
const prompt = this.formatter.formatConversation(messages, options.tools || [])
|
|
35
|
+
.replace('over ACP.', 'over Pi RPC.');
|
|
36
|
+
|
|
37
|
+
return new Promise<ChatResponse>((resolve, reject) => {
|
|
38
|
+
const child = spawn(this.command, args, { cwd, stdio: ['pipe', 'pipe', 'pipe'],
|
|
39
|
+
env: process.env, shell: false });
|
|
40
|
+
let buffer = '';
|
|
41
|
+
let stderr = '';
|
|
42
|
+
let streamed = '';
|
|
43
|
+
let finalText = '';
|
|
44
|
+
let stopReason = '';
|
|
45
|
+
let acknowledged = false;
|
|
46
|
+
let settled = false;
|
|
47
|
+
let finished = false;
|
|
48
|
+
let usage = { promptTokens: 0, completionTokens: 0, cachedPromptTokens: 0 };
|
|
49
|
+
|
|
50
|
+
const cleanup = (): void => {
|
|
51
|
+
options.signal?.removeEventListener('abort', abort);
|
|
52
|
+
child.stdin.end();
|
|
53
|
+
if (!child.killed) child.kill();
|
|
54
|
+
};
|
|
55
|
+
const fail = (error: Error): void => {
|
|
56
|
+
if (finished) return;
|
|
57
|
+
finished = true;
|
|
58
|
+
cleanup();
|
|
59
|
+
reject(error);
|
|
60
|
+
};
|
|
61
|
+
const complete = (): void => {
|
|
62
|
+
if (finished || !acknowledged || !settled) return;
|
|
63
|
+
if (stopReason === 'error' || stopReason === 'aborted') {
|
|
64
|
+
fail(new Error(`Pi ended with ${stopReason}${stderr ? `: ${stderr.slice(-400)}` : ''}`));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
finished = true;
|
|
68
|
+
cleanup();
|
|
69
|
+
const raw = finalText || streamed;
|
|
70
|
+
resolve({
|
|
71
|
+
content: raw.replace(/<tool_call>[\s\S]*?<\/tool_call>/g, '').trim(),
|
|
72
|
+
usage,
|
|
73
|
+
toolCalls: this.formatter.extractToolCalls(raw)
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
const abort = (): void => {
|
|
77
|
+
const err = new Error('Pi request aborted');
|
|
78
|
+
err.name = 'AbortError';
|
|
79
|
+
fail(err);
|
|
80
|
+
};
|
|
81
|
+
if (options.signal?.aborted) { abort(); return; }
|
|
82
|
+
options.signal?.addEventListener('abort', abort, { once: true });
|
|
83
|
+
|
|
84
|
+
const handle = (record: Record<string, any>): void => {
|
|
85
|
+
if (record.type === 'response' && record.id === 'causyne-state') {
|
|
86
|
+
if (!record.success || !record.data?.model
|
|
87
|
+
|| record.data.model.provider === 'unknown' || record.data.model.id === 'unknown') {
|
|
88
|
+
fail(new Error('Pi has no active model. Open Pi and configure a model login before selecting Pi in Causyne.'));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
child.stdin.write(JSON.stringify({ id: 'causyne-prompt', type: 'prompt', message: prompt }) + '\n');
|
|
92
|
+
} else if (record.type === 'response' && record.id === 'causyne-prompt') {
|
|
93
|
+
if (!record.success) {
|
|
94
|
+
fail(new Error(`Pi rejected the prompt: ${String(record.error || 'unknown error')}`));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
acknowledged = true;
|
|
98
|
+
if (record.data?.disposition === 'handled') settled = true;
|
|
99
|
+
complete();
|
|
100
|
+
} else if (record.type === 'message_update') {
|
|
101
|
+
const update = record.assistantMessageEvent;
|
|
102
|
+
if (update?.type === 'text_delta' && typeof update.delta === 'string') {
|
|
103
|
+
streamed += update.delta;
|
|
104
|
+
options.onChunk?.(update.delta);
|
|
105
|
+
} else if (update?.type === 'thinking_delta' && typeof update.delta === 'string') {
|
|
106
|
+
options.onReasoningChunk?.(update.delta);
|
|
107
|
+
}
|
|
108
|
+
} else if (record.type === 'message_end' && record.message?.role === 'assistant') {
|
|
109
|
+
const message = record.message;
|
|
110
|
+
finalText = Array.isArray(message.content)
|
|
111
|
+
? message.content.filter((part: any) => part?.type === 'text').map((part: any) => String(part.text || '')).join('')
|
|
112
|
+
: String(message.content || '');
|
|
113
|
+
stopReason = String(message.stopReason || '');
|
|
114
|
+
const data = message.usage || {};
|
|
115
|
+
usage = {
|
|
116
|
+
promptTokens: Number(data.input) || 0,
|
|
117
|
+
completionTokens: Number(data.output) || 0,
|
|
118
|
+
cachedPromptTokens: Number(data.cacheRead) || 0
|
|
119
|
+
};
|
|
120
|
+
} else if (record.type === 'agent_settled') {
|
|
121
|
+
if (record.aborted) stopReason = 'aborted';
|
|
122
|
+
settled = true;
|
|
123
|
+
complete();
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
child.stdout.setEncoding('utf8');
|
|
127
|
+
child.stdout.on('data', (chunk: string) => {
|
|
128
|
+
buffer += chunk;
|
|
129
|
+
let index: number;
|
|
130
|
+
while ((index = buffer.indexOf('\n')) >= 0) {
|
|
131
|
+
const line = buffer.slice(0, index).replace(/\r$/, '');
|
|
132
|
+
buffer = buffer.slice(index + 1);
|
|
133
|
+
if (!line) continue;
|
|
134
|
+
try { handle(JSON.parse(line) as Record<string, any>); }
|
|
135
|
+
catch (error) { fail(new Error(`Invalid Pi RPC record: ${String(error)}`)); return; }
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
child.stderr.setEncoding('utf8');
|
|
139
|
+
child.stderr.on('data', (chunk: string) => { stderr = (stderr + chunk).slice(-2000); });
|
|
140
|
+
child.on('error', error => fail(new Error(`Pi CLI unavailable: ${error.message}`)));
|
|
141
|
+
child.on('close', code => {
|
|
142
|
+
if (!finished) fail(new Error(`Pi RPC exited before completion (${code ?? 'unknown'})${stderr ? `: ${stderr.slice(-400)}` : ''}`));
|
|
143
|
+
});
|
|
144
|
+
child.stdin.on('error', error => fail(new Error(`Pi RPC input failed: ${error.message}`)));
|
|
145
|
+
child.stdin.write(JSON.stringify({ id: 'causyne-state', type: 'get_state' }) + '\n');
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -8,6 +8,7 @@ import { pathToFileURL } from 'url';
|
|
|
8
8
|
import { loadConfig, saveConfig } from '../config.js';
|
|
9
9
|
import { isGroupGranted, isGroupDeclined } from './capabilityConsent.js';
|
|
10
10
|
import { causyneHome } from '../utils/paths.js';
|
|
11
|
+
import { currentToolAutonomyMode } from '../approvalPolicy.js';
|
|
11
12
|
|
|
12
13
|
const CAPABILITY_DIR = path.join(causyneHome(), 'capabilities');
|
|
13
14
|
|
|
@@ -185,11 +186,27 @@ export async function provisionCapabilities(groups = []) {
|
|
|
185
186
|
* unavailable, not that something crashed.
|
|
186
187
|
*/
|
|
187
188
|
export async function ensureCapability(group) {
|
|
189
|
+
if (isGroupDeclined(group)) {
|
|
190
|
+
return { ok: false, group, reason: `The "${group}" capability was explicitly disabled by the user.` };
|
|
191
|
+
}
|
|
188
192
|
const status = groupStatus(group);
|
|
189
193
|
if (status.state === 'ready') return { ok: true, group };
|
|
190
194
|
if (status.state === 'unknown') return { ok: false, group, reason: `Unknown capability group "${group}".` };
|
|
191
195
|
|
|
192
196
|
if (status.state === 'needs-consent') {
|
|
197
|
+
// Mode C authorizes installation needed by the in-scope tool call. This
|
|
198
|
+
// does not persist a standing capability grant across sessions. A group
|
|
199
|
+
// explicitly revoked by the user stays disabled.
|
|
200
|
+
if (currentToolAutonomyMode() === 'C' && !isGroupDeclined(group)) {
|
|
201
|
+
try {
|
|
202
|
+
await provisionCapabilities([group]);
|
|
203
|
+
} catch (e) {
|
|
204
|
+
return { ok: false, group, reason: `The "${group}" capability could not be prepared: ${e.message}` };
|
|
205
|
+
}
|
|
206
|
+
return isGroupInstalled(group)
|
|
207
|
+
? { ok: true, group }
|
|
208
|
+
: { ok: false, group, reason: `The "${group}" capability is unavailable in this environment.` };
|
|
209
|
+
}
|
|
193
210
|
return {
|
|
194
211
|
ok: false,
|
|
195
212
|
group,
|
|
@@ -15,7 +15,7 @@ export const TOOLS_BY_GROUP = {
|
|
|
15
15
|
vision: ['screenshot', 'vision_inspect_ui', 'game_canvas_audit', 'game_web_runtime_inspector'],
|
|
16
16
|
ocr: [],
|
|
17
17
|
system: ['process_list'],
|
|
18
|
-
desktop: ['clipboard'
|
|
18
|
+
desktop: ['clipboard'],
|
|
19
19
|
archive: ['archive']
|
|
20
20
|
};
|
|
21
21
|
|
package/src/sandbox.js
CHANGED
|
@@ -3,6 +3,7 @@ import os from 'os';
|
|
|
3
3
|
import { isIP } from 'node:net';
|
|
4
4
|
import { loadConfig } from './config.js';
|
|
5
5
|
import { isDevEmulator } from './devMode.js';
|
|
6
|
+
import { validateBrowserActSandbox } from './browser/causyneBrowser.js';
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
function maskQuotedSpans(text) {
|
|
@@ -99,8 +100,8 @@ const INTERPRETER_INVOCATION = /(^|\s)(sh|bash|zsh|ksh|dash|fish|eval|xargs|ssh|
|
|
|
99
100
|
*
|
|
100
101
|
* A user may deliberately select a workspace that contains credential material.
|
|
101
102
|
* These paths are not silently trusted just because they sit below that root:
|
|
102
|
-
* touching one is classified 'extreme'
|
|
103
|
-
*
|
|
103
|
+
* touching one is classified 'extreme' for supervised-mode approval and audit.
|
|
104
|
+
* Mode C still applies the selected-workspace boundary and hard safety blocks.
|
|
104
105
|
*/
|
|
105
106
|
const CREDENTIAL_PATHS = [
|
|
106
107
|
/(^|\/)\.ssh(\/|$)/,
|
|
@@ -243,9 +244,8 @@ export class Sandbox {
|
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
|
|
246
|
-
// L4:
|
|
247
|
-
//
|
|
248
|
-
// one risk level Mode C cannot auto-approve.
|
|
247
|
+
// L4: classify credential material in an explicitly selected workspace as
|
|
248
|
+
// extreme. The approval policy interprets that signal by autonomy mode.
|
|
249
249
|
for (const p of pathsToCheck) {
|
|
250
250
|
if (typeof p === 'string' && isCredentialPath(p)) {
|
|
251
251
|
return { allowed: true, risk: 'extreme', reason: `Touches credential material: ${p}` };
|
|
@@ -267,6 +267,15 @@ export class Sandbox {
|
|
|
267
267
|
return { allowed: true, risk: 'moderate' };
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
+
if (toolName === 'gitOp') {
|
|
271
|
+
const command = String(args.command || '');
|
|
272
|
+
const risk = this.classifyCommandRisk(`git ${command}`);
|
|
273
|
+
if (risk === 'forbidden') {
|
|
274
|
+
return { allowed: false, reason: 'Command is permanently blocked for safety', risk: 'forbidden' };
|
|
275
|
+
}
|
|
276
|
+
return { allowed: true, risk: /\bbranch\s+-D\b/.test(command) ? 'dangerous' : risk };
|
|
277
|
+
}
|
|
278
|
+
|
|
270
279
|
// 4. SSRF protection (for web fetch)
|
|
271
280
|
if (toolName === 'web_fetch' && args.url) {
|
|
272
281
|
if (this.isInternalUrl(args.url)) {
|
|
@@ -278,24 +287,12 @@ export class Sandbox {
|
|
|
278
287
|
}
|
|
279
288
|
|
|
280
289
|
if (toolName === 'browser_act') {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
if (action && ['download', 'screenshot'].includes(action.type)) {
|
|
288
|
-
if (!action.outputFile || !this.isPathAllowed(path.resolve(this.workspacePaths[0], action.outputFile))) {
|
|
289
|
-
return { allowed: false, reason: 'Browser downloads must stay inside the selected workspace', risk: 'forbidden' };
|
|
290
|
-
}
|
|
291
|
-
hasDownload = true;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (hasDownload) return { allowed: true, risk: 'extreme', reason: 'Writes browser content to the selected workspace' };
|
|
295
|
-
if (actions.some(action => ['click', 'clickIndex', 'type', 'typeIndex', 'selectOption', 'keyPress'].includes(action?.type))) {
|
|
296
|
-
return { allowed: true, risk: 'dangerous', reason: 'Interacts with a website through the dedicated agent browser' };
|
|
297
|
-
}
|
|
298
|
-
return { allowed: true, risk: 'safe' };
|
|
290
|
+
return validateBrowserActSandbox(
|
|
291
|
+
args,
|
|
292
|
+
this.workspacePaths[0],
|
|
293
|
+
url => this.isInternalUrl(url),
|
|
294
|
+
targetPath => this.isPathAllowed(targetPath)
|
|
295
|
+
);
|
|
299
296
|
}
|
|
300
297
|
|
|
301
298
|
if (toolName === 'creative_apps') {
|
|
@@ -317,24 +314,21 @@ export class Sandbox {
|
|
|
317
314
|
return { allowed: true, risk: 'extreme', reason: 'Downloads a third-party asset to disk' };
|
|
318
315
|
}
|
|
319
316
|
|
|
320
|
-
//
|
|
317
|
+
// Keep downloads classified as extreme for supervised modes and auditing.
|
|
318
|
+
// Mode C approval is decided separately by the TypeScript approval policy.
|
|
321
319
|
if (toolName === 'manage_local_dependencies') {
|
|
322
320
|
// grant_capability installs third-party packages into the user's home
|
|
323
|
-
// directory
|
|
324
|
-
// download actions. Routing it here is what keeps ZM-01 true: nothing is
|
|
325
|
-
// ever installed without an explicit human approval.
|
|
321
|
+
// directory. Classification remains visible even when Mode C proceeds.
|
|
326
322
|
const heavyActions = ['pipInst', 'grant_capability', 'grant_mcp_server'];
|
|
327
323
|
if (heavyActions.includes(args.action)) {
|
|
328
|
-
return { allowed: true, risk: 'extreme' };
|
|
324
|
+
return { allowed: true, risk: 'extreme' };
|
|
329
325
|
}
|
|
330
326
|
return { allowed: true, risk: 'moderate' };
|
|
331
327
|
}
|
|
332
328
|
|
|
333
|
-
// Plugins are code extensions.
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
// session-revocable even though the plugin process also runs under Node's
|
|
337
|
-
// filesystem/network/child-process permission model.
|
|
329
|
+
// Plugins are code extensions. Keep their risk classification visible to
|
|
330
|
+
// supervised modes and audit logs; Mode C still uses workspace and hard
|
|
331
|
+
// policy checks before execution.
|
|
338
332
|
if (toolName === 'plugin_manager') {
|
|
339
333
|
return ['create', 'enable'].includes(args.action)
|
|
340
334
|
? { allowed: true, risk: 'extreme', reason: 'Creates or trusts executable plugin code' }
|
|
@@ -359,12 +353,9 @@ export class Sandbox {
|
|
|
359
353
|
if (toolName === 'proc_term') {
|
|
360
354
|
return { allowed: true, risk: 'dangerous' };
|
|
361
355
|
}
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
//
|
|
365
|
-
|
|
366
|
-
// Mode C. Section 4 says gated, not walled — the capability is real, the
|
|
367
|
-
// human just says yes first.
|
|
356
|
+
// Desktop interaction reaches applications the user is signed into.
|
|
357
|
+
// Keep the extreme risk signal for supervised modes and auditing; Mode C
|
|
358
|
+
// follows the owner's autonomous approval policy after hard checks.
|
|
368
359
|
if (toolName === 'desktop_act' || toolName === 'computer_use') {
|
|
369
360
|
return { allowed: true, risk: 'extreme' };
|
|
370
361
|
}
|
package/src/sessionJournal.js
CHANGED
|
@@ -224,6 +224,20 @@ export function titleFrom(text) {
|
|
|
224
224
|
return 'Untitled';
|
|
225
225
|
return clean.length > 60 ? `${clean.slice(0, 57)}…` : clean;
|
|
226
226
|
}
|
|
227
|
+
const PLACEHOLDER_TITLE = /^(?:untitled|hi|hello|hey|halo|hai|continue|lanjut|open it(?: for me)?|new session\b.*)$/i;
|
|
228
|
+
const NON_TASK_MESSAGE = /^(?:hi|hello|hey|halo|hai|continue|lanjut|open it|open it for me|thanks|thank you)[.!?\s]*$/i;
|
|
229
|
+
/** Recover a useful title when a session began with a greeting or placeholder. */
|
|
230
|
+
function sessionTitle(title, messages, createdAt) {
|
|
231
|
+
if (title.trim() && !PLACEHOLDER_TITLE.test(title.trim()))
|
|
232
|
+
return title;
|
|
233
|
+
const prompt = messages.find((message) => {
|
|
234
|
+
if (message.role !== 'user' || typeof message.content !== 'string')
|
|
235
|
+
return false;
|
|
236
|
+
const text = message.content.trim();
|
|
237
|
+
return text.length > 12 && !NON_TASK_MESSAGE.test(text) && !text.startsWith('[decayed]');
|
|
238
|
+
});
|
|
239
|
+
return prompt ? titleFrom(prompt.content) : `New session - ${new Date(createdAt).toISOString().replace('T', ' ').slice(0, 16)} UTC`;
|
|
240
|
+
}
|
|
227
241
|
export function listSessions() {
|
|
228
242
|
try {
|
|
229
243
|
ensureDir();
|
|
@@ -239,7 +253,7 @@ export function listSessions() {
|
|
|
239
253
|
if (!session)
|
|
240
254
|
continue;
|
|
241
255
|
const { messages, ...metadata } = session;
|
|
242
|
-
rows.push({ ...metadata, messageCount: messages.length });
|
|
256
|
+
rows.push({ ...metadata, title: sessionTitle(metadata.title, messages, metadata.createdAt), messageCount: messages.length });
|
|
243
257
|
}
|
|
244
258
|
return rows.sort((left, right) => right.updatedAt - left.updatedAt);
|
|
245
259
|
}
|
|
@@ -280,8 +294,9 @@ export function createSession(workspace, title = 'Untitled', makeActive = true)
|
|
|
280
294
|
writeNewTranscript(session);
|
|
281
295
|
if (makeActive)
|
|
282
296
|
setActiveSession(session.id);
|
|
283
|
-
|
|
284
|
-
|
|
297
|
+
// Session creation must never silently delete older conversations. Retention
|
|
298
|
+
// is an explicit maintenance operation, separate from starting a chat.
|
|
299
|
+
return { ...session, title: sessionTitle(session.title, session.messages, session.createdAt) };
|
|
285
300
|
}
|
|
286
301
|
/**
|
|
287
302
|
* Read one conversation without making it the active session.
|
|
@@ -290,7 +305,8 @@ export function createSession(workspace, title = 'Untitled', makeActive = true)
|
|
|
290
305
|
* they only need the transcript that belongs to their own id.
|
|
291
306
|
*/
|
|
292
307
|
export function getSession(id) {
|
|
293
|
-
|
|
308
|
+
const session = readSession(id);
|
|
309
|
+
return session ? { ...session, title: sessionTitle(session.title, session.messages, session.createdAt) } : null;
|
|
294
310
|
}
|
|
295
311
|
export function getActiveSessionId() {
|
|
296
312
|
try {
|
|
@@ -329,7 +345,7 @@ export function resolveSession(workspace, options = {}) {
|
|
|
329
345
|
const active = readSession(targetId);
|
|
330
346
|
if (active && (!active.workspace || active.workspaceKey === key) && now - active.updatedAt < RESUME_WINDOW_MS) {
|
|
331
347
|
setActiveSession(active.id);
|
|
332
|
-
return active;
|
|
348
|
+
return { ...active, title: sessionTitle(active.title, active.messages, active.createdAt) };
|
|
333
349
|
}
|
|
334
350
|
}
|
|
335
351
|
// 2. Resume most recent workspace conversation within resume window
|
|
@@ -340,7 +356,7 @@ export function resolveSession(workspace, options = {}) {
|
|
|
340
356
|
const session = readSession(candidate.id);
|
|
341
357
|
if (session) {
|
|
342
358
|
setActiveSession(session.id);
|
|
343
|
-
return session;
|
|
359
|
+
return { ...session, title: sessionTitle(session.title, session.messages, session.createdAt) };
|
|
344
360
|
}
|
|
345
361
|
}
|
|
346
362
|
return createSession(workspaceText);
|
|
@@ -350,7 +366,35 @@ export function switchSession(id) {
|
|
|
350
366
|
if (!session)
|
|
351
367
|
return null;
|
|
352
368
|
setActiveSession(session.id);
|
|
353
|
-
return session;
|
|
369
|
+
return { ...session, title: sessionTitle(session.title, session.messages, session.createdAt) };
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Fork an existing session into a new conversation in the same workspace.
|
|
373
|
+
*
|
|
374
|
+
* CRITICAL TRUST & PERMISSION INVARIANT (Claude Code Architecture, p. 24):
|
|
375
|
+
* Forking copies conversation history up to the designated turn, creating a
|
|
376
|
+
* distinct trajectory. Permissions, standing approvals, and tool allowlists
|
|
377
|
+
* are strictly bound to the originating session lifecycle and must NEVER be
|
|
378
|
+
* inherited into a fork. The forked session starts with fresh, ungranted
|
|
379
|
+
* permissions so that user authorization and trust are freshly established.
|
|
380
|
+
*/
|
|
381
|
+
export function forkSession(sourceId, options = {}) {
|
|
382
|
+
const source = getSession(sourceId);
|
|
383
|
+
if (!source)
|
|
384
|
+
return null;
|
|
385
|
+
const targetWorkspace = options.workspace || source.workspace || process.cwd();
|
|
386
|
+
const sourceTitle = source.title && source.title !== 'Untitled' ? source.title : 'Conversation';
|
|
387
|
+
const newTitle = options.title || `Fork of ${sourceTitle}`;
|
|
388
|
+
const newSession = createSession(targetWorkspace, newTitle, options.makeActive ?? true);
|
|
389
|
+
let messagesToCopy = Array.isArray(source.messages) ? source.messages : [];
|
|
390
|
+
if (typeof options.upToMessageIndex === 'number' && options.upToMessageIndex >= 0) {
|
|
391
|
+
messagesToCopy = messagesToCopy.slice(0, options.upToMessageIndex + 1);
|
|
392
|
+
}
|
|
393
|
+
if (messagesToCopy.length > 0) {
|
|
394
|
+
const clonedMessages = JSON.parse(JSON.stringify(messagesToCopy));
|
|
395
|
+
saveSessionMessages(newSession.id, clonedMessages);
|
|
396
|
+
}
|
|
397
|
+
return readSession(newSession.id);
|
|
354
398
|
}
|
|
355
399
|
function messageEqual(left, right) {
|
|
356
400
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
@@ -379,9 +423,8 @@ export function saveSessionMessages(id, messages) {
|
|
|
379
423
|
return false;
|
|
380
424
|
const nextMessages = messages.slice();
|
|
381
425
|
const firstUser = nextMessages.find((message) => message.role === 'user' && typeof message.content === 'string');
|
|
382
|
-
const nextTitle = (
|
|
383
|
-
? titleFrom(firstUser.content)
|
|
384
|
-
: session.title;
|
|
426
|
+
const nextTitle = sessionTitle(session.title, nextMessages, session.createdAt)
|
|
427
|
+
|| (firstUser ? titleFrom(firstUser.content) : session.title);
|
|
385
428
|
const prefix = session.messages.length <= nextMessages.length
|
|
386
429
|
&& session.messages.every((message, index) => {
|
|
387
430
|
const next = nextMessages[index];
|