@causyne/agent 1.10.21 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/THIRD_PARTY_NOTICES.md +12 -0
- package/native-skills/media/professional-document-publishing/SKILL.md +44 -0
- package/native-skills/media/screenplay-and-shotlist-forge/SKILL.md +42 -0
- package/package.json +1 -1
- package/src/acp/client.js +235 -0
- package/src/acp/client.ts +282 -0
- package/src/acp/peerProfiles.js +122 -0
- package/src/acp/peerProfiles.ts +128 -0
- package/src/acp/protocol.js +55 -0
- package/src/acp/protocol.ts +456 -0
- package/src/acp/server.js +746 -0
- package/src/acp/server.ts +822 -0
- package/src/agentLoop.d.ts +64 -0
- package/src/agentLoop.js +156 -12
- package/src/approvalGrants.js +33 -0
- package/src/approvalGrants.ts +50 -0
- package/src/commands.js +203 -0
- package/src/compiledSkills.js +10 -0
- package/src/decisionPolicy.js +2 -0
- package/src/decisionPolicy.ts +1 -0
- package/src/documentEngine/antiSlopAuditor.js +156 -0
- package/src/documentEngine/antiSlopAuditor.ts +221 -0
- package/src/documentEngine/documentForge.js +443 -0
- package/src/documentEngine/documentForge.ts +519 -0
- package/src/documentEngine/screenplayFormatter.js +336 -0
- package/src/documentEngine/screenplayFormatter.ts +407 -0
- package/src/engines/cad.js +113 -0
- package/src/engines/cad.ts +128 -0
- package/src/engines/film.js +108 -0
- package/src/engines/film.ts +104 -0
- package/src/engines/installer.js +226 -0
- package/src/engines/installer.ts +248 -0
- package/src/engines/photo.js +126 -0
- package/src/engines/photo.ts +137 -0
- package/src/engines/registry.js +186 -0
- package/src/engines/registry.ts +185 -0
- package/src/engines/sound.js +117 -0
- package/src/engines/sound.ts +130 -0
- package/src/engines/types.js +1 -0
- package/src/engines/types.ts +73 -0
- package/src/entrypoint.js +13 -0
- package/src/execSafe.js +10 -13
- package/src/execSafe.ts +25 -0
- package/src/memoryManager.js +9 -3
- package/src/modelRouter.js +56 -123
- package/src/modelRouter.ts +134 -0
- package/src/observer/advisory.js +164 -0
- package/src/observer/advisory.ts +171 -0
- package/src/observer/coldObserver.js +462 -0
- package/src/observer/coldObserver.ts +540 -0
- package/src/observer/evidence.js +435 -0
- package/src/observer/evidence.ts +499 -0
- package/src/perception.js +303 -118
- package/src/perception.ts +387 -0
- package/src/procSignal.js +15 -16
- package/src/procSignal.ts +31 -0
- package/src/promptMentions.js +170 -0
- package/src/promptMentions.ts +212 -0
- package/src/sandbox.js +9 -1
- package/src/sessionJournal.js +12 -2
- package/src/sessionJournal.ts +12 -2
- package/src/textDiff.js +117 -109
- package/src/textDiff.ts +169 -0
- package/src/toolPacks.js +19 -8
- package/src/tools/documentForge.js +215 -0
- package/src/tools/documentForge.ts +265 -0
- package/src/tools/generateMediaViaApi.js +1 -1
- package/src/tools/nativeEngine.js +464 -0
- package/src/tools/nativeEngine.ts +433 -0
- package/src/tools/openSourceToolProvisioner.js +510 -0
- package/src/tools/openSourceToolProvisioner.ts +590 -0
- package/src/tools/peerAgent.js +102 -0
- package/src/tools/peerAgent.ts +116 -0
- package/src/tools/registry.js +6 -1
- package/src/tui/completion.js +98 -42
- package/src/tui/prompt.js +17 -17
- package/src/uncertainty.js +93 -205
- package/src/uncertainty.ts +255 -0
- package/src/utils/paths.js +15 -18
- package/src/utils/paths.ts +36 -0
- package/src/vfeTracker.js +122 -181
- package/src/vfeTracker.ts +242 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
// Audio engine for Causyne Agent (headless multi-track audio workstation, bounce, and conversion).
|
|
3
|
+
// Operates deterministically via clean CLI subcommands.
|
|
4
|
+
const TIMEOUTS = {
|
|
5
|
+
status: 10_000,
|
|
6
|
+
catalog: 30_000,
|
|
7
|
+
describe: 30_000,
|
|
8
|
+
inspect: 60_000,
|
|
9
|
+
execute: 180_000,
|
|
10
|
+
batch: 600_000,
|
|
11
|
+
export: 300_000,
|
|
12
|
+
render: 300_000,
|
|
13
|
+
probe: 60_000,
|
|
14
|
+
install: 600_000
|
|
15
|
+
};
|
|
16
|
+
function positional(value) {
|
|
17
|
+
return value.startsWith('-') ? `.${path.sep}${value}` : value;
|
|
18
|
+
}
|
|
19
|
+
function requireProject(context, action) {
|
|
20
|
+
if (!context.project)
|
|
21
|
+
throw new Error(`${action} requires project`);
|
|
22
|
+
return positional(context.project);
|
|
23
|
+
}
|
|
24
|
+
function commandArgs(steps) {
|
|
25
|
+
const args = [];
|
|
26
|
+
for (const step of steps) {
|
|
27
|
+
if (step.params && Object.keys(step.params).length > 0) {
|
|
28
|
+
args.push('--cmd', `${step.id}=${JSON.stringify(step.params)}`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
args.push('--cmd', step.id);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return args;
|
|
35
|
+
}
|
|
36
|
+
export const soundEngine = {
|
|
37
|
+
id: 'sound',
|
|
38
|
+
label: 'Causyne Sound Engine',
|
|
39
|
+
envVar: 'CAUSYNE_ENGINE_SOUND',
|
|
40
|
+
binaryName: 'causyne-engine-sound',
|
|
41
|
+
actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
|
|
42
|
+
invoke(request, context) {
|
|
43
|
+
let args;
|
|
44
|
+
let artifacts = [];
|
|
45
|
+
switch (request.action) {
|
|
46
|
+
case 'status':
|
|
47
|
+
args = ['--version'];
|
|
48
|
+
break;
|
|
49
|
+
case 'catalog':
|
|
50
|
+
args = ['commands', ...(request.query ? [request.query] : [])];
|
|
51
|
+
break;
|
|
52
|
+
case 'describe':
|
|
53
|
+
args = ['describe', request.command ?? ''];
|
|
54
|
+
break;
|
|
55
|
+
case 'inspect':
|
|
56
|
+
args = ['info', requireProject(context, 'inspect')];
|
|
57
|
+
break;
|
|
58
|
+
case 'probe':
|
|
59
|
+
args = ['info', positional(request.query ?? '')];
|
|
60
|
+
break;
|
|
61
|
+
case 'execute':
|
|
62
|
+
case 'batch': {
|
|
63
|
+
const steps = request.action === 'execute'
|
|
64
|
+
? [{ id: request.command ?? '', ...(request.params ? { params: request.params } : {}) }]
|
|
65
|
+
: (request.steps ?? []);
|
|
66
|
+
args = ['run'];
|
|
67
|
+
if (context.project) {
|
|
68
|
+
args.push('--in', positional(context.project));
|
|
69
|
+
}
|
|
70
|
+
else if (context.demo) {
|
|
71
|
+
args.push('--demo');
|
|
72
|
+
}
|
|
73
|
+
args.push(...commandArgs(steps));
|
|
74
|
+
if (context.saveAs) {
|
|
75
|
+
args.push('--save', context.saveAs);
|
|
76
|
+
artifacts.push(context.saveAs);
|
|
77
|
+
}
|
|
78
|
+
else if (context.save && context.project) {
|
|
79
|
+
args.push('--save', context.project);
|
|
80
|
+
artifacts.push(context.project);
|
|
81
|
+
}
|
|
82
|
+
if (request.output) {
|
|
83
|
+
args.push('--bounce', request.output);
|
|
84
|
+
artifacts.push(request.output);
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case 'export': {
|
|
89
|
+
const output = request.output ?? '';
|
|
90
|
+
args = ['convert', requireProject(context, 'export'), positional(output)];
|
|
91
|
+
artifacts = [output];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case 'render': {
|
|
95
|
+
// Bounce session mix to output audio file
|
|
96
|
+
const output = request.output ?? '';
|
|
97
|
+
args = ['run'];
|
|
98
|
+
if (context.project) {
|
|
99
|
+
args.push('--in', positional(context.project));
|
|
100
|
+
}
|
|
101
|
+
else if (context.demo) {
|
|
102
|
+
args.push('--demo');
|
|
103
|
+
}
|
|
104
|
+
args.push('--bounce', positional(output));
|
|
105
|
+
if (request.start !== undefined)
|
|
106
|
+
args.push('--start', String(request.start));
|
|
107
|
+
if (request.end !== undefined)
|
|
108
|
+
args.push('--end', String(request.end));
|
|
109
|
+
artifacts = [output];
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
default:
|
|
113
|
+
throw new Error(`Unsupported sound engine action: ${request.action}`);
|
|
114
|
+
}
|
|
115
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type {
|
|
3
|
+
NativeEngineAction,
|
|
4
|
+
NativeEngineAdapter,
|
|
5
|
+
NativeEngineContext,
|
|
6
|
+
NativeEngineInvocation,
|
|
7
|
+
NativeEngineRequest,
|
|
8
|
+
NativeEngineStep
|
|
9
|
+
} from './types.js';
|
|
10
|
+
|
|
11
|
+
// Audio engine for Causyne Agent (headless multi-track audio workstation, bounce, and conversion).
|
|
12
|
+
// Operates deterministically via clean CLI subcommands.
|
|
13
|
+
|
|
14
|
+
const TIMEOUTS: Record<NativeEngineAction, number> = {
|
|
15
|
+
status: 10_000,
|
|
16
|
+
catalog: 30_000,
|
|
17
|
+
describe: 30_000,
|
|
18
|
+
inspect: 60_000,
|
|
19
|
+
execute: 180_000,
|
|
20
|
+
batch: 600_000,
|
|
21
|
+
export: 300_000,
|
|
22
|
+
render: 300_000,
|
|
23
|
+
probe: 60_000,
|
|
24
|
+
install: 600_000
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
function positional(value: string): string {
|
|
28
|
+
return value.startsWith('-') ? `.${path.sep}${value}` : value;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function requireProject(context: NativeEngineContext, action: string): string {
|
|
32
|
+
if (!context.project) throw new Error(`${action} requires project`);
|
|
33
|
+
return positional(context.project);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function commandArgs(steps: NativeEngineStep[]): string[] {
|
|
37
|
+
const args: string[] = [];
|
|
38
|
+
for (const step of steps) {
|
|
39
|
+
if (step.params && Object.keys(step.params).length > 0) {
|
|
40
|
+
args.push('--cmd', `${step.id}=${JSON.stringify(step.params)}`);
|
|
41
|
+
} else {
|
|
42
|
+
args.push('--cmd', step.id);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return args;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const soundEngine: NativeEngineAdapter = {
|
|
49
|
+
id: 'sound',
|
|
50
|
+
label: 'Causyne Sound Engine',
|
|
51
|
+
envVar: 'CAUSYNE_ENGINE_SOUND',
|
|
52
|
+
binaryName: 'causyne-engine-sound',
|
|
53
|
+
actions: ['catalog', 'describe', 'inspect', 'execute', 'batch', 'export', 'render', 'probe'],
|
|
54
|
+
invoke(request: NativeEngineRequest, context: NativeEngineContext): NativeEngineInvocation {
|
|
55
|
+
let args: string[];
|
|
56
|
+
let artifacts: string[] = [];
|
|
57
|
+
|
|
58
|
+
switch (request.action) {
|
|
59
|
+
case 'status':
|
|
60
|
+
args = ['--version'];
|
|
61
|
+
break;
|
|
62
|
+
case 'catalog':
|
|
63
|
+
args = ['commands', ...(request.query ? [request.query] : [])];
|
|
64
|
+
break;
|
|
65
|
+
case 'describe':
|
|
66
|
+
args = ['describe', request.command ?? ''];
|
|
67
|
+
break;
|
|
68
|
+
case 'inspect':
|
|
69
|
+
args = ['info', requireProject(context, 'inspect')];
|
|
70
|
+
break;
|
|
71
|
+
case 'probe':
|
|
72
|
+
args = ['info', positional(request.query ?? '')];
|
|
73
|
+
break;
|
|
74
|
+
case 'execute':
|
|
75
|
+
case 'batch': {
|
|
76
|
+
const steps: NativeEngineStep[] = request.action === 'execute'
|
|
77
|
+
? [{ id: request.command ?? '', ...(request.params ? { params: request.params } : {}) }]
|
|
78
|
+
: (request.steps ?? []);
|
|
79
|
+
|
|
80
|
+
args = ['run'];
|
|
81
|
+
if (context.project) {
|
|
82
|
+
args.push('--in', positional(context.project));
|
|
83
|
+
} else if (context.demo) {
|
|
84
|
+
args.push('--demo');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
args.push(...commandArgs(steps));
|
|
88
|
+
|
|
89
|
+
if (context.saveAs) {
|
|
90
|
+
args.push('--save', context.saveAs);
|
|
91
|
+
artifacts.push(context.saveAs);
|
|
92
|
+
} else if (context.save && context.project) {
|
|
93
|
+
args.push('--save', context.project);
|
|
94
|
+
artifacts.push(context.project);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (request.output) {
|
|
98
|
+
args.push('--bounce', request.output);
|
|
99
|
+
artifacts.push(request.output);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
case 'export': {
|
|
104
|
+
const output = request.output ?? '';
|
|
105
|
+
args = ['convert', requireProject(context, 'export'), positional(output)];
|
|
106
|
+
artifacts = [output];
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
case 'render': {
|
|
110
|
+
// Bounce session mix to output audio file
|
|
111
|
+
const output = request.output ?? '';
|
|
112
|
+
args = ['run'];
|
|
113
|
+
if (context.project) {
|
|
114
|
+
args.push('--in', positional(context.project));
|
|
115
|
+
} else if (context.demo) {
|
|
116
|
+
args.push('--demo');
|
|
117
|
+
}
|
|
118
|
+
args.push('--bounce', positional(output));
|
|
119
|
+
if (request.start !== undefined) args.push('--start', String(request.start));
|
|
120
|
+
if (request.end !== undefined) args.push('--end', String(request.end));
|
|
121
|
+
artifacts = [output];
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
throw new Error(`Unsupported sound engine action: ${request.action}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return { args, artifacts: artifacts.filter(Boolean), timeoutMs: TIMEOUTS[request.action] };
|
|
129
|
+
}
|
|
130
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export type NativeEngineAction =
|
|
2
|
+
| 'status'
|
|
3
|
+
| 'catalog'
|
|
4
|
+
| 'describe'
|
|
5
|
+
| 'inspect'
|
|
6
|
+
| 'execute'
|
|
7
|
+
| 'batch'
|
|
8
|
+
| 'export'
|
|
9
|
+
| 'render'
|
|
10
|
+
| 'probe'
|
|
11
|
+
| 'install';
|
|
12
|
+
|
|
13
|
+
export interface NativeEngineStep {
|
|
14
|
+
id: string;
|
|
15
|
+
params?: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface NativeEngineRequest {
|
|
19
|
+
engine: string;
|
|
20
|
+
action: NativeEngineAction;
|
|
21
|
+
command?: string;
|
|
22
|
+
params?: Record<string, unknown>;
|
|
23
|
+
steps?: NativeEngineStep[];
|
|
24
|
+
project?: string;
|
|
25
|
+
saveAs?: string;
|
|
26
|
+
save?: boolean;
|
|
27
|
+
demo?: boolean;
|
|
28
|
+
output?: string;
|
|
29
|
+
preset?: string;
|
|
30
|
+
format?: string;
|
|
31
|
+
seconds?: number;
|
|
32
|
+
scale?: number;
|
|
33
|
+
quality?: number;
|
|
34
|
+
range?: string;
|
|
35
|
+
start?: number;
|
|
36
|
+
end?: number;
|
|
37
|
+
allowOffline?: boolean;
|
|
38
|
+
keepGoing?: boolean;
|
|
39
|
+
query?: string;
|
|
40
|
+
open?: boolean;
|
|
41
|
+
confirm?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface NativeEngineContext {
|
|
45
|
+
workspace: string;
|
|
46
|
+
project?: string;
|
|
47
|
+
saveAs?: string;
|
|
48
|
+
save: boolean;
|
|
49
|
+
demo: boolean;
|
|
50
|
+
keepGoing: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface NativeEngineInvocation {
|
|
54
|
+
args: string[];
|
|
55
|
+
stdin?: string;
|
|
56
|
+
artifacts: string[];
|
|
57
|
+
timeoutMs: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface NativeEngineAdapter {
|
|
61
|
+
id: string;
|
|
62
|
+
label: string;
|
|
63
|
+
envVar: string;
|
|
64
|
+
binaryName: string;
|
|
65
|
+
actions: readonly NativeEngineAction[];
|
|
66
|
+
invoke(request: NativeEngineRequest, context: NativeEngineContext): NativeEngineInvocation;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface NativeEngineRun {
|
|
70
|
+
exitCode: number;
|
|
71
|
+
stdout: string;
|
|
72
|
+
stderr: string;
|
|
73
|
+
}
|
package/src/entrypoint.js
CHANGED
|
@@ -194,6 +194,19 @@ program
|
|
|
194
194
|
await execCommand(command);
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
+
program
|
|
198
|
+
.command('acp')
|
|
199
|
+
.description('Start Causyne as an Agent Client Protocol (ACP) server over stdio')
|
|
200
|
+
.action(async () => {
|
|
201
|
+
const { AcpServer } = await import('./acp/server.js');
|
|
202
|
+
const server = new AcpServer({
|
|
203
|
+
input: process.stdin,
|
|
204
|
+
output: process.stdout,
|
|
205
|
+
agentVersion: getPackageVersion()
|
|
206
|
+
});
|
|
207
|
+
server.start();
|
|
208
|
+
});
|
|
209
|
+
|
|
197
210
|
// Setup fallback for missing commands
|
|
198
211
|
program.on('command:*', function () {
|
|
199
212
|
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
|
package/src/execSafe.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import { exec, execSync as nodeExecSync } from 'node:child_process';
|
|
2
|
-
|
|
3
2
|
// Compatibility wrapper, NOT a security boundary. These APIs invoke a shell.
|
|
4
3
|
// Callers must enforce approval and validate input; prefer execFile with argv.
|
|
5
4
|
export function execSync(command, options) {
|
|
6
|
-
|
|
5
|
+
return nodeExecSync(command, options);
|
|
7
6
|
}
|
|
8
|
-
|
|
9
7
|
export function execAsync(command, options = {}) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
exec(command, options, (error, stdout, stderr) => {
|
|
10
|
+
if (error) {
|
|
11
|
+
Object.assign(error, { stdout, stderr });
|
|
12
|
+
reject(error);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
resolve(typeof stdout === 'string' ? stdout : String(stdout ?? ''));
|
|
16
|
+
});
|
|
19
17
|
});
|
|
20
|
-
});
|
|
21
18
|
}
|
package/src/execSafe.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exec,
|
|
3
|
+
execSync as nodeExecSync,
|
|
4
|
+
type ExecOptions,
|
|
5
|
+
type ExecSyncOptions
|
|
6
|
+
} from 'node:child_process';
|
|
7
|
+
|
|
8
|
+
// Compatibility wrapper, NOT a security boundary. These APIs invoke a shell.
|
|
9
|
+
// Callers must enforce approval and validate input; prefer execFile with argv.
|
|
10
|
+
export function execSync(command: string, options?: ExecSyncOptions): Buffer | string {
|
|
11
|
+
return nodeExecSync(command, options);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function execAsync(command: string, options: ExecOptions = {}): Promise<string> {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
exec(command, options, (error, stdout, stderr) => {
|
|
17
|
+
if (error) {
|
|
18
|
+
Object.assign(error, { stdout, stderr });
|
|
19
|
+
reject(error);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
resolve(typeof stdout === 'string' ? stdout : String(stdout ?? ''));
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/memoryManager.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { resolveSession, createSession, switchSession, saveSessionMessages } from './sessionStore.js';
|
|
3
|
+
import { resolveSession, createSession, getSession, switchSession, saveSessionMessages } from './sessionStore.js';
|
|
4
4
|
import os from 'os';
|
|
5
5
|
import { causyneHome } from './utils/paths.js';
|
|
6
6
|
|
|
@@ -30,10 +30,16 @@ export class MemoryManager {
|
|
|
30
30
|
* directory — so typing continue in a new project resumed a conversation
|
|
31
31
|
* from a different one, months old. See src/sessionStore.js.
|
|
32
32
|
*/
|
|
33
|
-
constructor(workspace = process.cwd()) {
|
|
33
|
+
constructor(workspace = process.cwd(), sessionId = null) {
|
|
34
34
|
this.ensureMemoryDir();
|
|
35
35
|
this.workspace = workspace;
|
|
36
|
-
|
|
36
|
+
if (sessionId) {
|
|
37
|
+
// A server-owned conversation is pinned by id. It must never fall back to
|
|
38
|
+
// resolveSession(), which could silently attach it to a different chat.
|
|
39
|
+
this.session = getSession(sessionId) || createSession(workspace, 'Untitled', false);
|
|
40
|
+
} else {
|
|
41
|
+
this.session = resolveSession(workspace);
|
|
42
|
+
}
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
/** The active session's id, for the status line and /sessions. */
|
package/src/modelRouter.js
CHANGED
|
@@ -1,145 +1,78 @@
|
|
|
1
1
|
import { UTILITY_MODEL_BY_PROVIDER } from './modelCatalogue.js';
|
|
2
|
-
|
|
3
|
-
// Hybrid model routing.
|
|
4
|
-
//
|
|
5
|
-
// Not every call an agent makes is reasoning. Condensing a dropped transcript,
|
|
6
|
-
// classifying an intent, filtering a log, extracting keywords — these are
|
|
7
|
-
// utility work, and paying a flagship rate for them is pure waste. The research
|
|
8
|
-
// spec puts the saving at the difference between the two rate cards, which for
|
|
9
|
-
// OpenAI is $5/$30 against $0.75/$4.50: roughly 6x on work that never needed
|
|
10
|
-
// the better model.
|
|
11
|
-
//
|
|
12
|
-
// THREE RULES THIS MODULE EXISTS TO ENFORCE, all of them things a naive router
|
|
13
|
-
// gets wrong:
|
|
14
|
-
//
|
|
15
|
-
// 1. NEVER CHANGE PROVIDER. Causyne is BYOK. The user holds one key. A router
|
|
16
|
-
// that sends utility work to "whatever is cheapest on the market" calls an
|
|
17
|
-
// endpoint there is no credential for and the task fails — having spent
|
|
18
|
-
// the tokens that got it there.
|
|
19
|
-
//
|
|
20
|
-
// 2. NEVER CHANGE THE PRIVACY POSTURE. Muse's cheap tier is `-contributor`,
|
|
21
|
-
// discounted because the vendor trains on the content. Routing into it to
|
|
22
|
-
// save money would opt the user into training silently. Cost is not a
|
|
23
|
-
// reason to make that choice for someone.
|
|
24
|
-
//
|
|
25
|
-
// 3. NEVER GUESS. A provider with no published second tier routes to nothing
|
|
26
|
-
// and pays full rate. An invented model id becomes a 404 mid-task, or
|
|
27
|
-
// worse, a real model at a price nobody predicted.
|
|
28
|
-
//
|
|
29
|
-
// The router returns a DESCRIPTION of where a call should go. It never
|
|
30
|
-
// constructs a provider and never performs a call, so it stays trivially
|
|
31
|
-
// testable and cannot become a second place where credentials are handled.
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* What a call is for.
|
|
35
|
-
*
|
|
36
|
-
* `reasoning` — planning, code, architecture, tool selection, anything the
|
|
37
|
-
* user's result quality depends on. Always the configured model.
|
|
38
|
-
* `utility` — mechanical text work whose output is consumed by the machine
|
|
39
|
-
* rather than by the user's judgement.
|
|
40
|
-
*
|
|
41
|
-
* @typedef {'reasoning' | 'utility'} RouteClass
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {Object} Route
|
|
46
|
-
* @property {string} provider The provider to call. Always the configured one.
|
|
47
|
-
* @property {string} model The model id to request.
|
|
48
|
-
* @property {boolean} routed True when this differs from the configured model.
|
|
49
|
-
* @property {string} reason Why, in one line. Written to the audit trail.
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
2
|
/**
|
|
53
3
|
* Utility work that is cheap to get wrong and expensive to run on a flagship.
|
|
54
4
|
* Anything not listed is treated as reasoning — the safe default is to spend
|
|
55
5
|
* more, never to silently downgrade work the user is judging.
|
|
56
|
-
*
|
|
57
|
-
* @type {ReadonlySet<string>}
|
|
58
6
|
*/
|
|
59
7
|
export const UTILITY_KINDS = new Set([
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
8
|
+
'condense', // cortex/autoCondenser semantic pass
|
|
9
|
+
'keywords', // plan-cache intent extraction
|
|
10
|
+
'classify', // intent / archetype disambiguation
|
|
11
|
+
'filter', // log and output filtering
|
|
12
|
+
'summarise' // non-decision summaries
|
|
65
13
|
]);
|
|
66
|
-
|
|
67
14
|
/**
|
|
68
15
|
* Decide where a call of a given kind should go.
|
|
69
16
|
*
|
|
70
|
-
* @param
|
|
71
|
-
*
|
|
72
|
-
* @
|
|
73
|
-
* Either a RouteClass or one of UTILITY_KINDS.
|
|
74
|
-
* @returns {Route}
|
|
17
|
+
* @param config The live agent config, as loaded from `~/.causyne/config.json`.
|
|
18
|
+
* @param kind Either a RouteClass or one of UTILITY_KINDS.
|
|
19
|
+
* @returns The resolved route description.
|
|
75
20
|
*/
|
|
76
21
|
export function resolveRoute(config, kind) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
22
|
+
const provider = String(config?.provider || '').toLowerCase();
|
|
23
|
+
const configured = String(config?.model || '');
|
|
24
|
+
const stay = {
|
|
25
|
+
provider,
|
|
26
|
+
model: configured,
|
|
27
|
+
routed: false,
|
|
28
|
+
reason: 'reasoning work runs on the configured model'
|
|
29
|
+
};
|
|
30
|
+
if (!provider || !configured) {
|
|
31
|
+
return { ...stay, reason: 'no provider or model configured' };
|
|
32
|
+
}
|
|
33
|
+
const isUtility = kind === 'utility' || UTILITY_KINDS.has(String(kind));
|
|
34
|
+
if (!isUtility)
|
|
35
|
+
return stay;
|
|
36
|
+
if (config?.disableModelRouting === true) {
|
|
37
|
+
return { ...stay, reason: 'model routing disabled by config' };
|
|
38
|
+
}
|
|
39
|
+
// An explicit choice by the user outranks the table, including a deliberate
|
|
40
|
+
// choice of a training tier — they made it, we did not make it for them.
|
|
41
|
+
const override = config?.modelRouting?.['utility'];
|
|
42
|
+
if (override) {
|
|
43
|
+
return {
|
|
44
|
+
provider,
|
|
45
|
+
model: String(override),
|
|
46
|
+
routed: String(override) !== configured,
|
|
47
|
+
reason: 'utility route set explicitly in config'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const cheap = UTILITY_MODEL_BY_PROVIDER[provider];
|
|
51
|
+
if (!cheap) {
|
|
52
|
+
return { ...stay, reason: `no published utility tier for ${provider}; paying full rate` };
|
|
53
|
+
}
|
|
54
|
+
if (cheap === configured) {
|
|
55
|
+
return { ...stay, reason: 'already on this provider\'s utility tier' };
|
|
56
|
+
}
|
|
57
|
+
// Rule 2. The configured model already carries a privacy posture; a route may
|
|
58
|
+
// not alter it in either direction.
|
|
59
|
+
if (/-contributor$/.test(configured) !== /-contributor$/.test(cheap)) {
|
|
60
|
+
return { ...stay, reason: 'a route may not change the training-data posture' };
|
|
61
|
+
}
|
|
103
62
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
63
|
+
provider,
|
|
64
|
+
model: cheap,
|
|
65
|
+
routed: true,
|
|
66
|
+
reason: `utility work routed to ${provider}'s cheaper tier`
|
|
108
67
|
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const cheap = UTILITY_MODEL_BY_PROVIDER[provider];
|
|
112
|
-
if (!cheap) {
|
|
113
|
-
return { ...stay, reason: `no published utility tier for ${provider}; paying full rate` };
|
|
114
|
-
}
|
|
115
|
-
if (cheap === configured) {
|
|
116
|
-
return { ...stay, reason: 'already on this provider\'s utility tier' };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Rule 2. The configured model already carries a privacy posture; a route may
|
|
120
|
-
// not alter it in either direction.
|
|
121
|
-
if (/-contributor$/.test(configured) !== /-contributor$/.test(cheap)) {
|
|
122
|
-
return { ...stay, reason: 'a route may not change the training-data posture' };
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return {
|
|
126
|
-
provider,
|
|
127
|
-
model: cheap,
|
|
128
|
-
routed: true,
|
|
129
|
-
reason: `utility work routed to ${provider}'s cheaper tier`
|
|
130
|
-
};
|
|
131
68
|
}
|
|
132
|
-
|
|
133
69
|
/**
|
|
134
70
|
* A config object for the routed call, leaving everything except the model
|
|
135
71
|
* untouched — same provider, same key, same base URL.
|
|
136
|
-
*
|
|
137
|
-
* @param {Record<string, any>} config
|
|
138
|
-
* @param {RouteClass|string} kind
|
|
139
|
-
* @returns {{config: Record<string, any>, route: Route}}
|
|
140
72
|
*/
|
|
141
73
|
export function routedConfig(config, kind) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
74
|
+
const route = resolveRoute(config, kind);
|
|
75
|
+
if (!route.routed)
|
|
76
|
+
return { config, route };
|
|
77
|
+
return { config: { ...config, model: route.model }, route };
|
|
145
78
|
}
|