@causyne/agent 1.20.112 → 1.20.116
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/ARCHITECTURE.md +29 -0
- package/package.json +1 -1
- package/src/agentLoop.js +72 -37
- package/src/agentLoop.ts +70 -38
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +7 -2
- package/src/browser/causyneBrowser.ts +8 -2
- package/src/browser/searchProviders.js +18 -7
- package/src/browser/searchProviders.ts +17 -5
- package/src/browser/snapshotWindow.js +1 -1
- package/src/browser/snapshotWindow.ts +1 -1
- package/src/browser/urlPolicy.js +21 -10
- package/src/browser/urlPolicy.ts +19 -10
- package/src/browser/workspacePreview.js +13 -1
- package/src/browser/workspacePreview.ts +11 -1
- package/src/computerUse/visionGrounding.js +31 -27
- package/src/computerUse/visionGrounding.ts +27 -27
- package/src/continuum/ui/continuumPicker.js +14 -6
- package/src/continuum/ui/continuumPicker.ts +13 -6
- package/src/continuum/ui/continuumPickerView.js +24 -15
- package/src/continuum/ui/continuumPickerView.ts +24 -16
- package/src/observer/advisory.js +32 -22
- package/src/observer/advisory.ts +30 -18
- package/src/observer/coldObserver.js +21 -33
- package/src/observer/coldObserver.ts +20 -33
- package/src/observer/evidence.js +20 -13
- package/src/observer/evidence.ts +21 -13
- package/src/observer.js +47 -12
- package/src/observer.ts +50 -18
- package/src/pluginsFactory/discovery.js +28 -16
- package/src/pluginsFactory/discovery.ts +29 -16
- package/src/pluginsFactory/pluginsFactory.js +213 -38
- package/src/pluginsFactory/pluginsFactory.ts +218 -39
- package/src/pluginsFactory/strategy.js +26 -16
- package/src/pluginsFactory/strategy.ts +34 -19
- package/src/pluginsFactory/templates.js +183 -62
- package/src/pluginsFactory/templates.ts +174 -54
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/pluginsFactory.js +108 -5
- package/src/tools/pluginsFactory.ts +115 -5
- package/src/tui/CausyneRotor.js +24 -10
- package/src/tui/CausyneRotor.ts +25 -10
- package/src/tui/activityLayout.js +9 -5
- package/src/tui/activityLayout.ts +9 -5
- package/src/tui/ask.js +34 -14
- package/src/tui/banner.js +55 -18
- package/src/tui/banner.ts +52 -17
- package/src/tui/block.js +47 -20
- package/src/tui/block.ts +54 -27
- package/src/tui/chatRenderer.js +135 -83
- package/src/tui/chatboxClipboard.js +12 -5
- package/src/tui/chatboxClipboard.ts +10 -4
- package/src/tui/clipboardImage.js +52 -42
- package/src/tui/clipboardImage.ts +50 -39
- package/src/tui/clipboardSync.js +12 -1
- package/src/tui/clipboardSync.ts +9 -1
- package/src/tui/codeProgress.js +57 -26
- package/src/tui/codeProgress.ts +57 -25
- package/src/tui/codeStreamRenderer.js +59 -14
- package/src/tui/codeStreamRenderer.ts +58 -14
- package/src/tui/commandPresentation.js +9 -2
- package/src/tui/commandPresentation.ts +9 -2
- package/src/tui/completion.js +45 -23
- package/src/tui/composerControls.js +21 -10
- package/src/tui/composerControls.ts +18 -10
- package/src/tui/composerGeometry.js +6 -4
- package/src/tui/composerGeometry.ts +6 -4
- package/src/tui/consoleGuard.js +29 -7
- package/src/tui/consoleGuard.ts +28 -7
- package/src/tui/dialogs.js +134 -71
- package/src/tui/diff.js +8 -4
- package/src/tui/history.js +6 -5
- package/src/tui/home.js +25 -13
- package/src/tui/homeView.js +37 -18
- package/src/tui/homeView.ts +38 -18
- package/src/tui/inlineSlash.js +6 -5
- package/src/tui/inlineSlash.ts +6 -5
- package/src/tui/keys.js +33 -17
- package/src/tui/layout.js +27 -9
- package/src/tui/layout.ts +26 -9
- package/src/tui/lineEditor.js +49 -23
- package/src/tui/markdownMath.js +64 -14
- package/src/tui/markdownMath.ts +69 -13
- package/src/tui/messageActionPlacement.js +28 -13
- package/src/tui/messageActionPlacement.ts +28 -13
- package/src/tui/messageInteraction.js +111 -46
- package/src/tui/messageInteraction.ts +115 -47
- package/src/tui/modelPicker.js +44 -15
- package/src/tui/modelPicker.ts +48 -15
- package/src/tui/observerPicker.js +56 -13
- package/src/tui/observerPicker.ts +73 -30
- package/src/tui/overlay.js +79 -35
- package/src/tui/overlay.ts +81 -34
- package/src/tui/prompt.js +162 -94
- package/src/tui/runningLight.js +1 -1
- package/src/tui/runningLight.ts +1 -1
- package/src/tui/scrollInteraction.js +64 -36
- package/src/tui/scrollInteraction.ts +70 -37
- package/src/tui/selectList.js +60 -32
- package/src/tui/sessionLayout.js +11 -3
- package/src/tui/sessionLayout.ts +10 -3
- package/src/tui/sessionPicker.js +74 -46
- package/src/tui/sessionPicker.ts +73 -48
- package/src/tui/sessionPickerView.js +32 -19
- package/src/tui/sessionPickerView.ts +31 -18
- package/src/tui/sessionSidebar.js +87 -57
- package/src/tui/sessionSidebar.ts +90 -54
- package/src/tui/setup.js +28 -3
- package/src/tui/setup.ts +27 -3
- package/src/tui/skillAuthoring.js +11 -5
- package/src/tui/skillAuthoring.ts +11 -5
- package/src/tui/smartLinkClick.js +75 -23
- package/src/tui/smartLinkClick.ts +86 -26
- package/src/tui/stage.js +47 -16
- package/src/tui/stage.ts +53 -18
- package/src/tui/stageSurface.js +120 -49
- package/src/tui/statusLine.js +85 -53
- package/src/tui/statusLine.ts +82 -46
- package/src/tui/terminalInputFramer.js +5 -2
- package/src/tui/text.js +117 -46
- package/src/tui/text.ts +113 -43
- package/src/tui/textLayout.js +6 -4
- package/src/tui/textLayout.ts +11 -5
- package/src/tui/theme.js +17 -8
- package/src/tui/thinkingBox.js +95 -95
- package/src/tui/thinkingBox.ts +105 -80
- package/src/tui/toolActivityPolicy.js +8 -1
- package/src/tui/toolActivityPolicy.ts +7 -1
- package/src/tui/toolDisplay.js +15 -6
- package/src/tui/toolDisplay.ts +16 -6
- package/src/tui/toolOutputNormalizer.js +16 -3
- package/src/tui/toolOutputNormalizer.ts +13 -3
- package/src/tui/transcript.js +15 -9
- package/src/tui/turnRail.js +156 -67
- package/src/tui/turnRail.ts +155 -58
- package/src/tui/usageCard.js +80 -45
- package/src/tui/usageCard.ts +81 -46
- package/src/tui/viewport.js +48 -23
- package/src/tui/viewport.ts +48 -27
- package/src/tui/viewportAnchor.js +2 -2
- package/src/tui/viewportAnchor.ts +2 -2
- package/src/tui/workspaceFileIndex.js +8 -6
- package/src/tui/workspaceFileIndex.ts +8 -6
- package/src/tui/workspaceSwitch.js +13 -10
- package/src/tui/workspaceSwitch.ts +11 -7
|
@@ -15,23 +15,106 @@ export interface ScaffoldingPayload {
|
|
|
15
15
|
entryPoint: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Words that cannot be used as a generated export binding. Modules are always
|
|
20
|
+
* strict, so `delete`, `default`, `eval`, `arguments`, and friends would make
|
|
21
|
+
* the generated module fail to parse.
|
|
22
|
+
*/
|
|
23
|
+
const RESERVED_IDENTIFIERS = new Set([
|
|
24
|
+
'arguments', 'await', 'break', 'case', 'catch', 'class', 'const', 'continue',
|
|
25
|
+
'debugger', 'default', 'delete', 'do', 'else', 'enum', 'eval', 'export',
|
|
26
|
+
'extends', 'false', 'finally', 'for', 'function', 'if', 'implements',
|
|
27
|
+
'import', 'in', 'instanceof', 'interface', 'let', 'new', 'null', 'package',
|
|
28
|
+
'private', 'protected', 'public', 'return', 'static', 'super', 'switch',
|
|
29
|
+
'this', 'throw', 'true', 'try', 'typeof', 'var', 'void', 'while', 'with',
|
|
30
|
+
'yield'
|
|
31
|
+
]);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Quotes a value for safe display inside a POSIX shell command line.
|
|
35
|
+
*/
|
|
36
|
+
export function shellQuote(value: string): string {
|
|
37
|
+
return `'${value.replace(/'/g, "'\\''")}'`;
|
|
38
|
+
}
|
|
39
|
+
|
|
18
40
|
/**
|
|
19
41
|
* Sanitizes an arbitrary tool or parameter name into a valid JavaScript identifier.
|
|
20
42
|
* Prevents syntax errors when tools contain hyphens (e.g. "get-weather" -> "get_weather").
|
|
21
43
|
*/
|
|
22
44
|
export function sanitizeIdentifier(name: string): string {
|
|
23
45
|
const cleaned = name.replace(/[^a-zA-Z0-9_]/g, '_');
|
|
24
|
-
|
|
46
|
+
const identifier = /^[0-9]/.test(cleaned) ? `_${cleaned}` : (cleaned || 'fn');
|
|
47
|
+
return RESERVED_IDENTIFIERS.has(identifier) ? `${identifier}_` : identifier;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Keeps user-supplied text inside a generated comment. A description that
|
|
52
|
+
* contains a comment terminator would otherwise escape the docblock and run
|
|
53
|
+
* as generated JavaScript.
|
|
54
|
+
*/
|
|
55
|
+
export function sanitizeComment(text: string): string {
|
|
56
|
+
return String(text ?? '')
|
|
57
|
+
.replace(/\*\//g, '*\\/')
|
|
58
|
+
.replace(/[\u0000-\u001f\u007f]/g, ' ')
|
|
59
|
+
.trim();
|
|
25
60
|
}
|
|
26
61
|
|
|
27
62
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
63
|
+
* Keeps user-supplied text inert inside generated Python comments and
|
|
64
|
+
* docstrings. Newlines would start a new statement, a triple quote would end
|
|
65
|
+
* the docstring early, and a trailing backslash would escape its delimiter.
|
|
31
66
|
*/
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
export function sanitizePythonText(text: string): string {
|
|
68
|
+
return String(text ?? '')
|
|
69
|
+
.replace(/\\/g, '\\\\')
|
|
70
|
+
.replace(/"""/g, "'''")
|
|
71
|
+
.replace(/[\u0000-\u001f\u007f]/g, ' ')
|
|
72
|
+
.trim();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Computes canonical export names for every tool in a module.
|
|
77
|
+
* The primary tool is always exported as "execute" (the default runner
|
|
78
|
+
* contract). Additional tools receive sanitized identifiers, disambiguated
|
|
79
|
+
* when two tool names collapse to the same binding (e.g. "get-user" and
|
|
80
|
+
* "get_user").
|
|
81
|
+
*/
|
|
82
|
+
function buildExportNames(tools: ServiceToolDescriptor[]): string[] {
|
|
83
|
+
const used = new Set<string>(['execute']);
|
|
84
|
+
return tools.map((tool, index) => {
|
|
85
|
+
if (index === 0) return 'execute';
|
|
86
|
+
const base = sanitizeIdentifier(tool.name);
|
|
87
|
+
let name = base;
|
|
88
|
+
let suffix = 2;
|
|
89
|
+
while (used.has(name)) name = `${base}_${suffix++}`;
|
|
90
|
+
used.add(name);
|
|
91
|
+
return name;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Builds the generated auth setup. The env var keeps the secret out of the
|
|
97
|
+
* manifest while authType selects the header shape the API expects.
|
|
98
|
+
*/
|
|
99
|
+
function buildAuthSetup(service: ServiceDescriptor): string {
|
|
100
|
+
if (!service.authEnvVar || service.authType === 'none') {
|
|
101
|
+
return 'const authHeader = undefined;';
|
|
102
|
+
}
|
|
103
|
+
const envAccess = `process.env[${JSON.stringify(service.authEnvVar)}]`;
|
|
104
|
+
const authType = service.authType || 'bearer';
|
|
105
|
+
let headerName = 'Authorization';
|
|
106
|
+
let valueExpression: string;
|
|
107
|
+
if (authType === 'basic') {
|
|
108
|
+
valueExpression = `\`Basic \${Buffer.from(${envAccess}).toString('base64')}\``;
|
|
109
|
+
} else if (authType === 'apiKey') {
|
|
110
|
+
headerName = 'X-API-Key';
|
|
111
|
+
valueExpression = envAccess;
|
|
112
|
+
} else if (authType === 'env') {
|
|
113
|
+
valueExpression = envAccess;
|
|
114
|
+
} else {
|
|
115
|
+
valueExpression = `\`Bearer \${${envAccess}}\``;
|
|
116
|
+
}
|
|
117
|
+
return `const authHeader = ${envAccess} ? { name: ${JSON.stringify(headerName)}, value: ${valueExpression} } : undefined;`;
|
|
35
118
|
}
|
|
36
119
|
|
|
37
120
|
/**
|
|
@@ -39,11 +122,12 @@ function getExportName(tool: ServiceToolDescriptor, index: number): string {
|
|
|
39
122
|
*/
|
|
40
123
|
export function generateHttpPluginScaffold(service: ServiceDescriptor): ScaffoldingPayload {
|
|
41
124
|
const capabilities = Array.from(new Set(['network', ...(service.capabilities || [])]));
|
|
42
|
-
const
|
|
125
|
+
const effectiveTools: ServiceToolDescriptor[] = service.tools.length > 0 ? service.tools : [{
|
|
43
126
|
name: 'query',
|
|
44
127
|
description: `Execute request against ${service.name}`,
|
|
45
128
|
parameters: { type: 'object', properties: {} }
|
|
46
|
-
};
|
|
129
|
+
}];
|
|
130
|
+
const exportNames = buildExportNames(effectiveTools);
|
|
47
131
|
|
|
48
132
|
const manifest = {
|
|
49
133
|
schemaVersion: 1,
|
|
@@ -51,53 +135,69 @@ export function generateHttpPluginScaffold(service: ServiceDescriptor): Scaffold
|
|
|
51
135
|
version: '1.0.0',
|
|
52
136
|
description: service.description || `Native HTTP plugin for ${service.name}`,
|
|
53
137
|
capabilities,
|
|
54
|
-
tools:
|
|
138
|
+
tools: effectiveTools.map((tool, idx) => ({
|
|
55
139
|
name: tool.name,
|
|
56
140
|
description: tool.description,
|
|
57
141
|
parameters: tool.parameters,
|
|
58
142
|
entry: 'index.js',
|
|
59
|
-
export:
|
|
143
|
+
export: exportNames[idx],
|
|
60
144
|
timeoutMs: 30000
|
|
61
145
|
}))
|
|
62
146
|
};
|
|
63
147
|
|
|
64
|
-
const toolExecutors =
|
|
65
|
-
const fnName =
|
|
148
|
+
const toolExecutors = effectiveTools.map((tool, idx) => {
|
|
149
|
+
const fnName = exportNames[idx];
|
|
66
150
|
const httpMethod = tool.httpMethod || 'POST';
|
|
67
151
|
const httpPath = tool.httpPath || '/';
|
|
68
152
|
return `
|
|
69
153
|
/**
|
|
70
|
-
* ${tool.description}
|
|
154
|
+
* ${sanitizeComment(tool.description)}
|
|
71
155
|
*/
|
|
72
156
|
export async function ${fnName}(args = {}, context = {}) {
|
|
73
157
|
const endpoint = ${JSON.stringify(service.endpoint || 'https://api.example.com')};
|
|
74
158
|
const base = endpoint.endsWith('/') ? endpoint : endpoint + '/';
|
|
75
|
-
const
|
|
76
|
-
const
|
|
159
|
+
const rawPath = ${JSON.stringify(httpPath)};
|
|
160
|
+
const pathParamNames = Array.from(rawPath.matchAll(/\\{([^}]+)\\}/g), match => match[1]);
|
|
161
|
+
const requestArgs = args && typeof args === 'object' ? { ...args } : {};
|
|
162
|
+
const missingPathParams = pathParamNames.filter(key => requestArgs[key] === undefined || requestArgs[key] === null);
|
|
163
|
+
if (missingPathParams.length > 0) {
|
|
164
|
+
return { success: false, error: \`Missing path parameter(s): \${missingPathParams.join(', ')}\` };
|
|
165
|
+
}
|
|
166
|
+
let url;
|
|
167
|
+
try {
|
|
168
|
+
const rel = rawPath.replace(/\\{([^}]+)\\}/g, (_match, key) => encodeURIComponent(String(requestArgs[key])));
|
|
169
|
+
for (const key of pathParamNames) delete requestArgs[key];
|
|
170
|
+
const targetPath = rel.startsWith('/') ? rel.slice(1) : rel;
|
|
171
|
+
url = new URL(targetPath, base);
|
|
172
|
+
} catch (err) {
|
|
173
|
+
return { success: false, error: \`Invalid request URL: \${err instanceof Error ? err.message : String(err)}\` };
|
|
174
|
+
}
|
|
77
175
|
|
|
78
|
-
if (${JSON.stringify(httpMethod)} === 'GET' &&
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
|
|
176
|
+
if (${JSON.stringify(httpMethod)} === 'GET' && requestArgs && typeof requestArgs === 'object') {
|
|
177
|
+
const appendQuery = (key, value) => {
|
|
178
|
+
if (value === undefined || value === null) return;
|
|
179
|
+
if (Array.isArray(value)) {
|
|
180
|
+
for (const item of value) appendQuery(key, item);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
url.searchParams.append(key, typeof value === 'object' ? JSON.stringify(value) : String(value));
|
|
184
|
+
};
|
|
185
|
+
for (const [k, v] of Object.entries(requestArgs)) appendQuery(k, v);
|
|
82
186
|
}
|
|
83
187
|
|
|
84
|
-
|
|
85
|
-
service.authEnvVar
|
|
86
|
-
? `process.env[${JSON.stringify(service.authEnvVar)}] ? \`Bearer \${process.env[${JSON.stringify(service.authEnvVar)}]}\` : undefined`
|
|
87
|
-
: 'undefined'
|
|
88
|
-
};
|
|
188
|
+
${buildAuthSetup(service)}
|
|
89
189
|
|
|
90
190
|
const headers = {
|
|
91
191
|
'Accept': 'application/json',
|
|
92
192
|
'Content-Type': 'application/json'
|
|
93
193
|
};
|
|
94
|
-
if (authHeader) headers[
|
|
194
|
+
if (authHeader) headers[authHeader.name] = authHeader.value;
|
|
95
195
|
|
|
96
196
|
try {
|
|
97
197
|
const response = await fetch(url.toString(), {
|
|
98
198
|
method: ${JSON.stringify(httpMethod)},
|
|
99
199
|
headers,
|
|
100
|
-
body: ${httpMethod !== 'GET' ? 'JSON.stringify(
|
|
200
|
+
body: ${httpMethod !== 'GET' ? 'JSON.stringify(requestArgs)' : 'undefined'}
|
|
101
201
|
});
|
|
102
202
|
|
|
103
203
|
if (!response.ok) {
|
|
@@ -143,7 +243,7 @@ ${service.authEnvVar ? `- **Environment Variable**: Set \`${service.authEnvVar}\
|
|
|
143
243
|
By default, this plugin is created in a **disabled** state to allow code review.
|
|
144
244
|
To activate after reviewing the code:
|
|
145
245
|
\`\`\`bash
|
|
146
|
-
|
|
246
|
+
/plugins enable ${service.name}
|
|
147
247
|
\`\`\`
|
|
148
248
|
`;
|
|
149
249
|
|
|
@@ -162,11 +262,12 @@ causyne plugins enable ${service.name}
|
|
|
162
262
|
*/
|
|
163
263
|
export function generateCliPluginScaffold(service: ServiceDescriptor): ScaffoldingPayload {
|
|
164
264
|
const capabilities = Array.from(new Set(['subprocess', ...(service.capabilities || [])]));
|
|
165
|
-
const
|
|
265
|
+
const effectiveTools: ServiceToolDescriptor[] = service.tools.length > 0 ? service.tools : [{
|
|
166
266
|
name: 'run',
|
|
167
267
|
description: `Execute command for ${service.name}`,
|
|
168
268
|
parameters: { type: 'object', properties: {} }
|
|
169
|
-
};
|
|
269
|
+
}];
|
|
270
|
+
const exportNames = buildExportNames(effectiveTools);
|
|
170
271
|
|
|
171
272
|
const manifest = {
|
|
172
273
|
schemaVersion: 1,
|
|
@@ -174,22 +275,22 @@ export function generateCliPluginScaffold(service: ServiceDescriptor): Scaffoldi
|
|
|
174
275
|
version: '1.0.0',
|
|
175
276
|
description: service.description || `Native CLI plugin for ${service.name}`,
|
|
176
277
|
capabilities,
|
|
177
|
-
tools:
|
|
278
|
+
tools: effectiveTools.map((tool, idx) => ({
|
|
178
279
|
name: tool.name,
|
|
179
280
|
description: tool.description,
|
|
180
281
|
parameters: tool.parameters,
|
|
181
282
|
entry: 'index.js',
|
|
182
|
-
export:
|
|
283
|
+
export: exportNames[idx],
|
|
183
284
|
timeoutMs: 45000
|
|
184
285
|
}))
|
|
185
286
|
};
|
|
186
287
|
|
|
187
|
-
const toolExecutors =
|
|
188
|
-
const fnName =
|
|
288
|
+
const toolExecutors = effectiveTools.map((tool, idx) => {
|
|
289
|
+
const fnName = exportNames[idx];
|
|
189
290
|
const binary = service.cliBinary || service.name;
|
|
190
291
|
return `
|
|
191
292
|
/**
|
|
192
|
-
* ${tool.description}
|
|
293
|
+
* ${sanitizeComment(tool.description)}
|
|
193
294
|
*/
|
|
194
295
|
export async function ${fnName}(args = {}, context = {}) {
|
|
195
296
|
const { execFile } = await import('node:child_process');
|
|
@@ -198,7 +299,7 @@ export async function ${fnName}(args = {}, context = {}) {
|
|
|
198
299
|
|
|
199
300
|
const bin = ${JSON.stringify(binary)};
|
|
200
301
|
const cliArgs = [];
|
|
201
|
-
${tool.cliSubcommand ? `cliArgs.push(
|
|
302
|
+
${tool.cliSubcommand ? `cliArgs.push(...${JSON.stringify(tool.cliSubcommand)}.split(/\\s+/).filter(Boolean));` : ''}
|
|
202
303
|
|
|
203
304
|
for (const [key, val] of Object.entries(args || {})) {
|
|
204
305
|
if (val === true) cliArgs.push(\`--\${key}\`);
|
|
@@ -250,7 +351,7 @@ ${service.description}
|
|
|
250
351
|
## Security & Activation
|
|
251
352
|
This plugin is created disabled. After verifying the source code:
|
|
252
353
|
\`\`\`bash
|
|
253
|
-
|
|
354
|
+
/plugins enable ${service.name}
|
|
254
355
|
\`\`\`
|
|
255
356
|
`;
|
|
256
357
|
|
|
@@ -270,11 +371,12 @@ causyne plugins enable ${service.name}
|
|
|
270
371
|
*/
|
|
271
372
|
export function generatePythonBridgeScaffold(service: ServiceDescriptor): ScaffoldingPayload {
|
|
272
373
|
const capabilities = Array.from(new Set(['subprocess', ...(service.capabilities || [])]));
|
|
273
|
-
const
|
|
374
|
+
const effectiveTools: ServiceToolDescriptor[] = service.tools.length > 0 ? service.tools : [{
|
|
274
375
|
name: 'run_python',
|
|
275
376
|
description: `Execute Python workflow for ${service.name}`,
|
|
276
377
|
parameters: { type: 'object', properties: {} }
|
|
277
|
-
};
|
|
378
|
+
}];
|
|
379
|
+
const exportNames = buildExportNames(effectiveTools);
|
|
278
380
|
|
|
279
381
|
const manifest = {
|
|
280
382
|
schemaVersion: 1,
|
|
@@ -282,22 +384,22 @@ export function generatePythonBridgeScaffold(service: ServiceDescriptor): Scaffo
|
|
|
282
384
|
version: '1.0.0',
|
|
283
385
|
description: service.description || `Python bridge plugin for ${service.name}`,
|
|
284
386
|
capabilities,
|
|
285
|
-
tools:
|
|
387
|
+
tools: effectiveTools.map((tool, idx) => ({
|
|
286
388
|
name: tool.name,
|
|
287
389
|
description: tool.description,
|
|
288
390
|
parameters: tool.parameters,
|
|
289
391
|
entry: 'index.js',
|
|
290
|
-
export:
|
|
392
|
+
export: exportNames[idx],
|
|
291
393
|
timeoutMs: 60000
|
|
292
394
|
}))
|
|
293
395
|
};
|
|
294
396
|
|
|
295
|
-
const toolExecutors =
|
|
296
|
-
const fnName =
|
|
397
|
+
const toolExecutors = effectiveTools.map((tool, idx) => {
|
|
398
|
+
const fnName = exportNames[idx];
|
|
297
399
|
const pythonMethod = tool.pythonMethod || tool.name;
|
|
298
400
|
return `
|
|
299
401
|
/**
|
|
300
|
-
* ${tool.description}
|
|
402
|
+
* ${sanitizeComment(tool.description)}
|
|
301
403
|
*/
|
|
302
404
|
export async function ${fnName}(args = {}, context = {}) {
|
|
303
405
|
return invokePythonBridge(${JSON.stringify(pythonMethod)}, args, context);
|
|
@@ -314,6 +416,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
314
416
|
|
|
315
417
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
316
418
|
const BRIDGE_SCRIPT = path.join(__dirname, 'bridge.py');
|
|
419
|
+
const PYTHON_BIN = process.env.CAUSYNE_PYTHON || (process.platform === 'win32' ? 'python' : 'python3');
|
|
317
420
|
|
|
318
421
|
async function invokePythonBridge(action, args, context) {
|
|
319
422
|
const payload = JSON.stringify({
|
|
@@ -325,7 +428,7 @@ async function invokePythonBridge(action, args, context) {
|
|
|
325
428
|
});
|
|
326
429
|
|
|
327
430
|
return new Promise((resolve) => {
|
|
328
|
-
const child = spawn(
|
|
431
|
+
const child = spawn(PYTHON_BIN, [BRIDGE_SCRIPT], {
|
|
329
432
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
330
433
|
env: { ...process.env, PYTHONUNBUFFERED: '1' }
|
|
331
434
|
});
|
|
@@ -352,16 +455,23 @@ async function invokePythonBridge(action, args, context) {
|
|
|
352
455
|
child.on('error', (err) => {
|
|
353
456
|
finish({
|
|
354
457
|
success: false,
|
|
355
|
-
error: \`Failed to spawn
|
|
458
|
+
error: \`Failed to spawn \${PYTHON_BIN}: \${err.message}. Ensure Python 3 is installed and in PATH.\`
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
child.stdin.on('error', (err) => {
|
|
463
|
+
finish({
|
|
464
|
+
success: false,
|
|
465
|
+
error: \`Python bridge stdin error: \${err.message}\`
|
|
356
466
|
});
|
|
357
467
|
});
|
|
358
468
|
|
|
359
469
|
child.on('close', (code) => {
|
|
360
|
-
if (
|
|
470
|
+
if (!stdout.trim()) {
|
|
361
471
|
finish({
|
|
362
472
|
success: false,
|
|
363
473
|
exitCode: code,
|
|
364
|
-
error: stderr.trim() || \`Python bridge
|
|
474
|
+
error: stderr.trim() || \`Python bridge returned no output (exit code \${code})\`
|
|
365
475
|
});
|
|
366
476
|
return;
|
|
367
477
|
}
|
|
@@ -388,14 +498,16 @@ ${toolExecutors}
|
|
|
388
498
|
`;
|
|
389
499
|
|
|
390
500
|
const pythonModule = service.pythonModule || service.name;
|
|
501
|
+
const safeServiceName = sanitizePythonText(service.name);
|
|
502
|
+
const safePythonModule = sanitizePythonText(pythonModule);
|
|
391
503
|
const bridgePy = `#!/usr/bin/env python3
|
|
392
504
|
# -*- coding: utf-8 -*-
|
|
393
505
|
"""
|
|
394
|
-
Python Bridge for ${
|
|
506
|
+
Python Bridge for ${safeServiceName}
|
|
395
507
|
Auto-generated by Causyne PluginsFactory
|
|
396
508
|
|
|
397
509
|
Communicates with Causyne Agent via JSON on stdin/stdout.
|
|
398
|
-
Provides on-demand buffer for ${
|
|
510
|
+
Provides on-demand buffer for ${safePythonModule}.
|
|
399
511
|
"""
|
|
400
512
|
|
|
401
513
|
import sys
|
|
@@ -409,7 +521,7 @@ def handle_request(payload):
|
|
|
409
521
|
|
|
410
522
|
try:
|
|
411
523
|
# Dynamically reference target python module
|
|
412
|
-
# import ${
|
|
524
|
+
# import ${safePythonModule}
|
|
413
525
|
|
|
414
526
|
result = {
|
|
415
527
|
"action": action,
|
|
@@ -467,7 +579,7 @@ python3 --version
|
|
|
467
579
|
## Security & Activation
|
|
468
580
|
This plugin is created disabled. Review the code in \`bridge.py\` and \`index.js\`, then enable:
|
|
469
581
|
\`\`\`bash
|
|
470
|
-
|
|
582
|
+
/plugins enable ${service.name}
|
|
471
583
|
\`\`\`
|
|
472
584
|
`;
|
|
473
585
|
|
|
@@ -531,6 +643,10 @@ function send(message) {
|
|
|
531
643
|
function handleRequest(request) {
|
|
532
644
|
const { id, method, params } = request;
|
|
533
645
|
|
|
646
|
+
// JSON-RPC notifications carry no id and must never receive a response,
|
|
647
|
+
// even when they use a request-style method such as tools/list.
|
|
648
|
+
if (id === undefined) return null;
|
|
649
|
+
|
|
534
650
|
switch (method) {
|
|
535
651
|
case 'initialize':
|
|
536
652
|
return {
|
|
@@ -575,7 +691,7 @@ function handleRequest(request) {
|
|
|
575
691
|
return {
|
|
576
692
|
id,
|
|
577
693
|
jsonrpc: '2.0',
|
|
578
|
-
error: { code: -
|
|
694
|
+
error: { code: -32602, message: \`Unknown tool: '\${toolName}'\` }
|
|
579
695
|
};
|
|
580
696
|
}
|
|
581
697
|
|
|
@@ -618,6 +734,10 @@ rl.on('line', (line) => {
|
|
|
618
734
|
if (!trimmed) return;
|
|
619
735
|
try {
|
|
620
736
|
const request = JSON.parse(trimmed);
|
|
737
|
+
if (!request || typeof request !== 'object' || Array.isArray(request)) {
|
|
738
|
+
send({ jsonrpc: '2.0', id: null, error: { code: -32600, message: 'Invalid Request' } });
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
621
741
|
const response = handleRequest(request);
|
|
622
742
|
if (response) send(response);
|
|
623
743
|
} catch (err) {
|
|
@@ -646,7 +766,7 @@ Where feasible, prefer native plugins or Python bridges for higher token efficie
|
|
|
646
766
|
## Registration & Grant
|
|
647
767
|
In Causyne Agent, register and review this server:
|
|
648
768
|
\`\`\`bash
|
|
649
|
-
causyne mcp add ${service.name} node
|
|
769
|
+
causyne mcp add ${service.name} node "$HOME/.causyne/mcp-servers/${service.name}/server.js"
|
|
650
770
|
causyne mcp grant ${service.name}
|
|
651
771
|
\`\`\`
|
|
652
772
|
`;
|
package/src/timeMachine.js
CHANGED
|
@@ -13,7 +13,8 @@ export function recoveryUserMessage(decision, tool) {
|
|
|
13
13
|
if (decision.kind === 'human') {
|
|
14
14
|
return `${tool} needs approval or authentication. Review the last tool error, then provide the needed access or choose another route. No success is claimed.`;
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
// A stop before the hard maximum only happens when further attempts were not approved.
|
|
17
|
+
if (decision.attempt < TIME_MACHINE_MAX_ATTEMPTS && decision.kind === 'stop') {
|
|
17
18
|
return `${tool} failed ${decision.attempt} times (${decision.failureClass}) and more attempts were not approved. The task stopped without verified success.`;
|
|
18
19
|
}
|
|
19
20
|
return `${tool} still failed after ${decision.attempt} attempts (${decision.failureClass}). The task stopped without verified success.`;
|
|
@@ -22,14 +23,16 @@ function record(value) {
|
|
|
22
23
|
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
23
24
|
? value : {};
|
|
24
25
|
}
|
|
26
|
+
function firstText(values) {
|
|
27
|
+
return values.find((value) => typeof value === 'string' && value.trim().length > 0) ?? '';
|
|
28
|
+
}
|
|
29
|
+
function commandText(args) {
|
|
30
|
+
return firstText([args.command, args.cmd, args.CommandLine, args.commandLine, args.script]);
|
|
31
|
+
}
|
|
25
32
|
function operationFamily(args) {
|
|
26
|
-
const command =
|
|
27
|
-
: typeof args.cmd === 'string' ? args.cmd
|
|
28
|
-
: typeof args.CommandLine === 'string' ? args.CommandLine
|
|
29
|
-
: typeof args.commandLine === 'string' ? args.commandLine
|
|
30
|
-
: typeof args.script === 'string' ? args.script : '';
|
|
33
|
+
const command = commandText(args);
|
|
31
34
|
if (!command) {
|
|
32
|
-
const endpoint =
|
|
35
|
+
const endpoint = firstText([args.url, args.endpoint]);
|
|
33
36
|
if (endpoint) {
|
|
34
37
|
try {
|
|
35
38
|
return new URL(endpoint).hostname.toLowerCase();
|
|
@@ -40,18 +43,31 @@ function operationFamily(args) {
|
|
|
40
43
|
}
|
|
41
44
|
return '';
|
|
42
45
|
}
|
|
43
|
-
const
|
|
46
|
+
const tokens = command.trim().split(/\s+/);
|
|
47
|
+
// Leading VAR=value assignments do not change which operation is retried, so
|
|
48
|
+
// `CI=1 npm test` must share the retry budget of `npm test`.
|
|
49
|
+
while (tokens.length > 1 && /^[A-Za-z_][A-Za-z0-9_]*=/.test(tokens[0] || ''))
|
|
50
|
+
tokens.shift();
|
|
51
|
+
const words = tokens.slice(0, 3);
|
|
52
|
+
// Windows shims (`npm.cmd`, `bun.exe`) are the same tools as their bare names.
|
|
53
|
+
const executable = (words[0] || '').replace(/^.*[\\/]/, '').replace(/\.(cmd|exe|bat|ps1)$/i, '').toLowerCase();
|
|
44
54
|
// Keep common verification commands distinct without retaining paths,
|
|
45
55
|
// source text, environment variables, or credentials in the journal.
|
|
46
|
-
if (/^(npm|pnpm|yarn|bun)$/.test(
|
|
47
|
-
|
|
56
|
+
if (/^(npm|pnpm|yarn|bun)$/.test(executable)) {
|
|
57
|
+
// Script names are case-sensitive; a passing `build` cannot resolve `Build`.
|
|
58
|
+
return [executable, ...words.slice(1, words[1] === 'run' ? 3 : 2)].join(' ');
|
|
59
|
+
}
|
|
60
|
+
if (/^(git|gh|docker|podman|kubectl)$/.test(executable)) {
|
|
61
|
+
// Distinct subcommands must have distinct recovery histories: a passing
|
|
62
|
+
// git status is not evidence that an earlier git push succeeded.
|
|
63
|
+
return [executable, (words[1] || '').toLowerCase().slice(0, 32)].filter(Boolean).join(' ');
|
|
48
64
|
}
|
|
49
|
-
return
|
|
65
|
+
return executable.slice(0, 32);
|
|
50
66
|
}
|
|
51
67
|
function issueKey(tool, args) {
|
|
52
68
|
const family = operationFamily(args);
|
|
53
|
-
const target =
|
|
54
|
-
const workspace = String(args.cwd ?? '');
|
|
69
|
+
const target = firstText([args.path, args.file_path, args.filePath, args.target, args.endpoint, args.url]);
|
|
70
|
+
const workspace = String(args.cwd ?? args.workingDirectory ?? args.workingDir ?? args.workspaceRoot ?? '');
|
|
55
71
|
// Changing error text/class does not buy another three attempts at the same
|
|
56
72
|
// operation. Targets are hashed and never included in recovery messages.
|
|
57
73
|
return createHash('sha256').update(`${tool}\0${family}\0${target}\0${workspace}`).digest('hex');
|
|
@@ -95,12 +111,16 @@ export class TimeMachine {
|
|
|
95
111
|
return this.extended.has(issueKeyValue);
|
|
96
112
|
}
|
|
97
113
|
observe(tool, args, result, outcomes = []) {
|
|
114
|
+
const safeArgs = record(args);
|
|
98
115
|
const value = record(result);
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
||
|
|
102
|
-
|
|
103
|
-
|
|
116
|
+
const exitStatus = value.exitCode ?? value.exit_code;
|
|
117
|
+
const failed = result instanceof Error || value.success === false || value.ok === false || value.isError === true || value.requiresConsent === true || value.requiresApproval === true || value.authenticationRequired === true || (typeof value.error === 'string' && value.error.trim().length > 0)
|
|
118
|
+
|| (typeof exitStatus === 'number' && (!Number.isFinite(exitStatus) || exitStatus !== 0))
|
|
119
|
+
|| value.failureKind === 'site_refusal' || value.status === 'error' || value.status === 'failed'
|
|
120
|
+
|| (typeof value.status === 'number' && (!Number.isFinite(value.status) || value.status >= 400))
|
|
121
|
+
|| (value.error !== null && typeof value.error === 'object');
|
|
122
|
+
const classification = failed ? (value.status === 429 ? 'rate_limited' : value.status === 401 ? 'permission' : failureClass(value) || 'failed') : '';
|
|
123
|
+
const key = issueKey(tool, safeArgs);
|
|
104
124
|
const good = lastGoodTool(outcomes);
|
|
105
125
|
if (!failed) {
|
|
106
126
|
// A successful check only clears its own failure family. A successful
|
|
@@ -116,14 +136,15 @@ export class TimeMachine {
|
|
|
116
136
|
issueKey: '',
|
|
117
137
|
lastGoodTool: good,
|
|
118
138
|
guidance: hadFailure
|
|
119
|
-
? isVerificationCommand(
|
|
139
|
+
? isVerificationCommand(commandText(safeArgs))
|
|
120
140
|
? 'The same verification command now passed. Report that check as evidence; assess the rest of the task separately.'
|
|
121
141
|
: 'This tool call succeeded. Verify the intended task outcome before reporting success.'
|
|
122
142
|
: ''
|
|
123
143
|
};
|
|
124
144
|
}
|
|
125
145
|
const error = typeof value.error === 'string' ? value.error : '';
|
|
126
|
-
const needsHuman =
|
|
146
|
+
const needsHuman = value.failureKind !== 'site_refusal'
|
|
147
|
+
&& (classification === 'permission' || value.requiresConsent === true || value.requiresApproval === true || value.authenticationRequired === true || /user denied|approval required|authentication required/i.test(error));
|
|
127
148
|
const attempt = Math.min(TIME_MACHINE_MAX_ATTEMPTS, (this.failures.get(key) || 0) + 1);
|
|
128
149
|
this.failures.set(key, attempt);
|
|
129
150
|
const checkpoint = good ? ` Last successful tool: ${good}.` : '';
|
|
@@ -135,7 +156,7 @@ export class TimeMachine {
|
|
|
135
156
|
if (attempt >= TIME_MACHINE_MAX_ATTEMPTS) {
|
|
136
157
|
return { kind: 'stop', attempt, maxAttempts: TIME_MACHINE_MAX_ATTEMPTS, issueKey: key,
|
|
137
158
|
failureClass: classification, lastGoodTool: good,
|
|
138
|
-
guidance: `The same
|
|
159
|
+
guidance: `The same operation failed through ${TIME_MACHINE_MAX_ATTEMPTS} attempts. Stop this task. Give a brief evidence-based report, state what remains unresolved, and ask for input only if needed. Put a detailed report in a Markdown file only if the user requests one.${checkpoint}` };
|
|
139
160
|
}
|
|
140
161
|
// The agent may spend three attempts alone. The fourth through sixth belong
|
|
141
162
|
// to the user: without an explicit grant the budget ends here.
|
|
@@ -149,7 +170,7 @@ export class TimeMachine {
|
|
|
149
170
|
failureClass: classification, lastGoodTool: good,
|
|
150
171
|
guidance: `Further attempts were not approved. Stop this task. Give a brief evidence-based report and state what remains unresolved.${checkpoint}` };
|
|
151
172
|
}
|
|
152
|
-
if (classification === 'rate_limited' && attempt <
|
|
173
|
+
if (classification === 'rate_limited' && attempt < TIME_MACHINE_MAX_ATTEMPTS) {
|
|
153
174
|
return { kind: 'replan', attempt, maxAttempts: TIME_MACHINE_MAX_ATTEMPTS, issueKey: key,
|
|
154
175
|
failureClass: classification, lastGoodTool: good,
|
|
155
176
|
guidance: `Rate limit reached. Respect the provider's retry/reset window; do not immediately resend the same request.${checkpoint}` };
|