@causyne/agent 1.20.112 → 1.20.117
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 +153 -68
- package/src/agentLoop.ts +152 -71
- package/src/browser/browserRuntime.js +13 -8
- package/src/browser/browserRuntime.ts +16 -8
- package/src/browser/causyneBrowser.js +37 -9
- package/src/browser/causyneBrowser.ts +37 -9
- 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/cliMode.js +5 -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/memory/scopedFacts.js +171 -0
- package/src/memory/scopedFacts.ts +214 -0
- package/src/memory.d.ts +13 -1
- package/src/memory.js +9 -12
- 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/perception.js +124 -3
- package/src/perception.ts +128 -4
- package/src/planCache.js +17 -3
- package/src/planCache.ts +17 -3
- 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/smartToolsUse.js +4 -5
- package/src/smartToolsUse.ts +4 -6
- package/src/taskShape.js +49 -7
- package/src/taskShape.ts +55 -7
- package/src/timeMachine.js +43 -22
- package/src/timeMachine.ts +44 -22
- package/src/tool-scripts/desktop_act.applescript +1 -0
- package/src/toolPacks.js +27 -5
- package/src/toolPacks.ts +32 -5
- package/src/tools/computerUse.js +23 -10
- package/src/tools/computerUse.ts +19 -8
- package/src/tools/desktopAct.js +12 -1
- package/src/tools/memoryWrite.js +8 -10
- package/src/tools/memoryWrite.ts +13 -11
- 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 +139 -84
- 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 +60 -28
- package/src/tui/codeProgress.ts +60 -27
- package/src/tui/codeStreamRenderer.js +94 -23
- package/src/tui/codeStreamRenderer.ts +92 -23
- 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 +36 -18
- 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 +186 -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 +232 -51
- 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 +176 -80
- package/src/tui/turnRail.ts +173 -71
- package/src/tui/usageCard.js +136 -80
- package/src/tui/usageCard.ts +145 -103
- 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
- package/src/types/contracts.ts +3 -0
|
@@ -19,8 +19,27 @@ import fs from 'node:fs';
|
|
|
19
19
|
import path from 'node:path';
|
|
20
20
|
import { causyneHome } from '../utils/paths.js';
|
|
21
21
|
import { assessRoute } from './strategy.js';
|
|
22
|
-
import { generateCliPluginScaffold, generateHttpPluginScaffold, generateMcpServerScaffold, generatePythonBridgeScaffold } from './templates.js';
|
|
22
|
+
import { generateCliPluginScaffold, generateHttpPluginScaffold, generateMcpServerScaffold, generatePythonBridgeScaffold, shellQuote } from './templates.js';
|
|
23
23
|
const NAME_PATTERN = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
24
|
+
const TOOL_NAME_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
25
|
+
const MAX_TOOLS = 32;
|
|
26
|
+
const CAPABILITIES = new Set(['workspace:read', 'workspace:write', 'network', 'subprocess']);
|
|
27
|
+
/**
|
|
28
|
+
* Resolves symlinked ancestors even when the final path does not exist yet.
|
|
29
|
+
* Keeps containment checks consistent on macOS, where /var is a symlink.
|
|
30
|
+
*/
|
|
31
|
+
function resolveWithExistingAncestors(target) {
|
|
32
|
+
let current = path.resolve(target);
|
|
33
|
+
const missing = [];
|
|
34
|
+
while (!fs.existsSync(current)) {
|
|
35
|
+
const parent = path.dirname(current);
|
|
36
|
+
if (parent === current)
|
|
37
|
+
return path.resolve(target);
|
|
38
|
+
missing.unshift(path.basename(current));
|
|
39
|
+
current = parent;
|
|
40
|
+
}
|
|
41
|
+
return path.join(fs.realpathSync(current), ...missing);
|
|
42
|
+
}
|
|
24
43
|
/**
|
|
25
44
|
* Computes the exact SHA-256 directory digest matching Causyne's pluginManager.
|
|
26
45
|
*/
|
|
@@ -91,18 +110,66 @@ export class PluginsFactory {
|
|
|
91
110
|
error: `Invalid service name "${service.name}". Must match ^[a-z0-9][a-z0-9-]{0,63}$`
|
|
92
111
|
};
|
|
93
112
|
}
|
|
113
|
+
const normalizedService = { ...service, name: normalizedName };
|
|
94
114
|
const route = proposal.userConfirmedRoute ?? proposal.recommendedRoute;
|
|
115
|
+
if (route !== 'native_plugin' && route !== 'python_bridge' && route !== 'mcp_server') {
|
|
116
|
+
return {
|
|
117
|
+
success: false,
|
|
118
|
+
route,
|
|
119
|
+
targetDirectory: '',
|
|
120
|
+
createdFiles: [],
|
|
121
|
+
instructions: '',
|
|
122
|
+
error: `Unsupported route "${String(route)}".`
|
|
123
|
+
};
|
|
124
|
+
}
|
|
95
125
|
const isMcp = route === 'mcp_server';
|
|
126
|
+
const toolError = this.validateTools(service.tools);
|
|
127
|
+
if (toolError) {
|
|
128
|
+
return {
|
|
129
|
+
success: false,
|
|
130
|
+
route,
|
|
131
|
+
targetDirectory: '',
|
|
132
|
+
createdFiles: [],
|
|
133
|
+
instructions: '',
|
|
134
|
+
error: toolError
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const capabilityError = this.validateCapabilities(service.capabilities || []);
|
|
138
|
+
if (capabilityError) {
|
|
139
|
+
return {
|
|
140
|
+
success: false,
|
|
141
|
+
route,
|
|
142
|
+
targetDirectory: '',
|
|
143
|
+
createdFiles: [],
|
|
144
|
+
instructions: '',
|
|
145
|
+
error: capabilityError
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const endpointError = this.validateEndpoint(service, route);
|
|
149
|
+
if (endpointError) {
|
|
150
|
+
return {
|
|
151
|
+
success: false,
|
|
152
|
+
route,
|
|
153
|
+
targetDirectory: '',
|
|
154
|
+
createdFiles: [],
|
|
155
|
+
instructions: '',
|
|
156
|
+
error: endpointError
|
|
157
|
+
};
|
|
158
|
+
}
|
|
96
159
|
const baseDir = options.baseDir
|
|
97
160
|
? path.resolve(options.baseDir)
|
|
98
161
|
: isMcp
|
|
99
162
|
? this.mcpServersRoot
|
|
100
163
|
: this.pluginsRoot;
|
|
101
164
|
const targetDir = path.join(baseDir, normalizedName);
|
|
102
|
-
// Path containment check:
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
165
|
+
// Path containment check: resolve the nearest real parent so a symlinked
|
|
166
|
+
// target or parent cannot redirect writes outside the base directory.
|
|
167
|
+
const resolvedBase = resolveWithExistingAncestors(baseDir);
|
|
168
|
+
const targetParent = path.dirname(targetDir);
|
|
169
|
+
const resolvedParent = resolveWithExistingAncestors(targetParent);
|
|
170
|
+
const resolvedTarget = path.join(resolvedParent, path.basename(targetDir));
|
|
171
|
+
const relativeTarget = path.relative(resolvedBase, resolvedTarget);
|
|
172
|
+
if (!relativeTarget || relativeTarget.startsWith('..') || path.isAbsolute(relativeTarget)) {
|
|
106
173
|
return {
|
|
107
174
|
success: false,
|
|
108
175
|
route,
|
|
@@ -112,31 +179,54 @@ export class PluginsFactory {
|
|
|
112
179
|
error: `Target path escapes directory boundary: ${targetDir}`
|
|
113
180
|
};
|
|
114
181
|
}
|
|
115
|
-
if (fs.existsSync(targetDir)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
182
|
+
if (fs.existsSync(targetDir)) {
|
|
183
|
+
const targetStat = fs.lstatSync(targetDir);
|
|
184
|
+
if (targetStat.isSymbolicLink()) {
|
|
185
|
+
return {
|
|
186
|
+
success: false,
|
|
187
|
+
route,
|
|
188
|
+
targetDirectory: targetDir,
|
|
189
|
+
createdFiles: [],
|
|
190
|
+
instructions: '',
|
|
191
|
+
error: `Target path must not be a symlink: ${targetDir}`
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
if (!targetStat.isDirectory()) {
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
route,
|
|
198
|
+
targetDirectory: targetDir,
|
|
199
|
+
createdFiles: [],
|
|
200
|
+
instructions: '',
|
|
201
|
+
error: `Target path is not a directory: ${targetDir}`
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
if (!options.force) {
|
|
205
|
+
return {
|
|
206
|
+
success: false,
|
|
207
|
+
route,
|
|
208
|
+
targetDirectory: targetDir,
|
|
209
|
+
createdFiles: [],
|
|
210
|
+
instructions: '',
|
|
211
|
+
error: `Directory already exists: ${targetDir}. Use force: true to overwrite.`
|
|
212
|
+
};
|
|
213
|
+
}
|
|
124
214
|
}
|
|
125
215
|
// Select scaffolding payload generator based on route
|
|
126
216
|
let payload;
|
|
127
217
|
if (route === 'native_plugin') {
|
|
128
218
|
if (service.serviceKind === 'cli' || service.cliBinary) {
|
|
129
|
-
payload = generateCliPluginScaffold(
|
|
219
|
+
payload = generateCliPluginScaffold(normalizedService);
|
|
130
220
|
}
|
|
131
221
|
else {
|
|
132
|
-
payload = generateHttpPluginScaffold(
|
|
222
|
+
payload = generateHttpPluginScaffold(normalizedService);
|
|
133
223
|
}
|
|
134
224
|
}
|
|
135
225
|
else if (route === 'python_bridge') {
|
|
136
|
-
payload = generatePythonBridgeScaffold(
|
|
226
|
+
payload = generatePythonBridgeScaffold(normalizedService);
|
|
137
227
|
}
|
|
138
228
|
else {
|
|
139
|
-
payload = generateMcpServerScaffold(
|
|
229
|
+
payload = generateMcpServerScaffold(normalizedService);
|
|
140
230
|
}
|
|
141
231
|
if (options.dryRun) {
|
|
142
232
|
return {
|
|
@@ -144,28 +234,64 @@ export class PluginsFactory {
|
|
|
144
234
|
route,
|
|
145
235
|
targetDirectory: targetDir,
|
|
146
236
|
createdFiles: payload.files.map(f => f.relativePath),
|
|
147
|
-
instructions: `[Dry Run] Scaffolding plan ready for ${
|
|
237
|
+
instructions: `[Dry Run] Scaffolding plan ready for ${normalizedName} at ${targetDir}`
|
|
148
238
|
};
|
|
149
239
|
}
|
|
150
240
|
// Write files to target directory
|
|
151
|
-
fs.
|
|
241
|
+
const createdRoot = !fs.existsSync(targetDir);
|
|
152
242
|
const createdFiles = [];
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
243
|
+
try {
|
|
244
|
+
fs.mkdirSync(targetDir, { recursive: true, mode: 0o700 });
|
|
245
|
+
for (const file of payload.files) {
|
|
246
|
+
const filePath = path.join(targetDir, file.relativePath);
|
|
247
|
+
const fileDir = path.dirname(filePath);
|
|
248
|
+
if (fs.existsSync(fileDir)) {
|
|
249
|
+
const dirStat = fs.lstatSync(fileDir);
|
|
250
|
+
if (dirStat.isSymbolicLink()) {
|
|
251
|
+
throw new Error(`Refusing to write through symlinked directory: ${fileDir}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (fs.existsSync(filePath)) {
|
|
255
|
+
const fileStat = fs.lstatSync(filePath);
|
|
256
|
+
if (fileStat.isSymbolicLink()) {
|
|
257
|
+
throw new Error(`Refusing to overwrite symlinked file: ${filePath}`);
|
|
258
|
+
}
|
|
259
|
+
if (!fileStat.isFile()) {
|
|
260
|
+
throw new Error(`Refusing to overwrite non-file path: ${filePath}`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (!fs.existsSync(fileDir)) {
|
|
264
|
+
fs.mkdirSync(fileDir, { recursive: true, mode: 0o700 });
|
|
265
|
+
}
|
|
266
|
+
fs.writeFileSync(filePath, file.content, { encoding: 'utf8', mode: 0o600 });
|
|
267
|
+
createdFiles.push(file.relativePath);
|
|
158
268
|
}
|
|
159
|
-
|
|
160
|
-
|
|
269
|
+
}
|
|
270
|
+
catch (err) {
|
|
271
|
+
if (createdRoot) {
|
|
272
|
+
try {
|
|
273
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
274
|
+
}
|
|
275
|
+
catch {
|
|
276
|
+
// Preserve the original write failure.
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
success: false,
|
|
281
|
+
route,
|
|
282
|
+
targetDirectory: targetDir,
|
|
283
|
+
createdFiles: [],
|
|
284
|
+
instructions: '',
|
|
285
|
+
error: `Failed to scaffold ${normalizedName}: ${err instanceof Error ? err.message : String(err)}`
|
|
286
|
+
};
|
|
161
287
|
}
|
|
162
288
|
let digest;
|
|
163
289
|
let instructions;
|
|
164
290
|
if (!isMcp) {
|
|
165
291
|
// Calculate plugin digest
|
|
166
292
|
digest = computePluginDirectoryDigest(targetDir);
|
|
167
|
-
// Record disabled state in state.json
|
|
168
|
-
this.recordPluginState(normalizedName, digest);
|
|
293
|
+
// Record disabled state in state.json next to the scaffolded plugin.
|
|
294
|
+
this.recordPluginState(normalizedName, digest, baseDir);
|
|
169
295
|
instructions = [
|
|
170
296
|
`Custom plugin '${normalizedName}' successfully scaffolded at: ${targetDir}`,
|
|
171
297
|
`Kind: ${route === 'python_bridge' ? 'Python Bridge Plugin' : 'Native Plugin'}`,
|
|
@@ -173,8 +299,7 @@ export class PluginsFactory {
|
|
|
173
299
|
`Security Status: DISABLED (Review source files before enabling)`,
|
|
174
300
|
'',
|
|
175
301
|
`To activate after review:`,
|
|
176
|
-
`
|
|
177
|
-
` (or in chat: /plugins enable ${normalizedName})`
|
|
302
|
+
` /plugins enable ${normalizedName}`
|
|
178
303
|
].join('\n');
|
|
179
304
|
}
|
|
180
305
|
else {
|
|
@@ -184,7 +309,7 @@ export class PluginsFactory {
|
|
|
184
309
|
`Security Status: UNGRANTED (Review source files before granting)`,
|
|
185
310
|
'',
|
|
186
311
|
`To register and grant:`,
|
|
187
|
-
` causyne mcp add ${normalizedName} node ${path.join(targetDir, 'server.js')}`,
|
|
312
|
+
` causyne mcp add ${normalizedName} node ${shellQuote(path.join(targetDir, 'server.js'))}`,
|
|
188
313
|
` causyne mcp grant ${normalizedName}`,
|
|
189
314
|
` (or in chat: /mcp grant ${normalizedName})`
|
|
190
315
|
].join('\n');
|
|
@@ -201,15 +326,62 @@ export class PluginsFactory {
|
|
|
201
326
|
}
|
|
202
327
|
return result;
|
|
203
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Rejects descriptors that the plugin loader would refuse after the factory
|
|
331
|
+
* has already written files and recorded a digest.
|
|
332
|
+
*/
|
|
333
|
+
validateTools(tools) {
|
|
334
|
+
if (tools.length > MAX_TOOLS) {
|
|
335
|
+
return `Plugin exceeds ${MAX_TOOLS} tools.`;
|
|
336
|
+
}
|
|
337
|
+
const seen = new Set();
|
|
338
|
+
for (const tool of tools) {
|
|
339
|
+
if (!TOOL_NAME_PATTERN.test(tool.name)) {
|
|
340
|
+
return `Invalid tool name "${tool.name}". Must match ^[a-z][a-z0-9_-]{0,63}$`;
|
|
341
|
+
}
|
|
342
|
+
if (seen.has(tool.name)) {
|
|
343
|
+
return `Duplicate tool name "${tool.name}".`;
|
|
344
|
+
}
|
|
345
|
+
seen.add(tool.name);
|
|
346
|
+
if (!tool.parameters || tool.parameters.type !== 'object') {
|
|
347
|
+
return `Tool "${tool.name}" parameters must be an object JSON schema.`;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
validateCapabilities(capabilities) {
|
|
353
|
+
for (const capability of capabilities) {
|
|
354
|
+
if (!CAPABILITIES.has(capability)) {
|
|
355
|
+
return `Unknown capability "${capability}".`;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
validateEndpoint(service, route) {
|
|
361
|
+
const isHttpNative = route === 'native_plugin' && service.serviceKind !== 'cli' && !service.cliBinary;
|
|
362
|
+
if (!isHttpNative || !service.endpoint)
|
|
363
|
+
return null;
|
|
364
|
+
let parsed;
|
|
365
|
+
try {
|
|
366
|
+
parsed = new URL(service.endpoint);
|
|
367
|
+
}
|
|
368
|
+
catch {
|
|
369
|
+
return `Invalid endpoint URL "${service.endpoint}".`;
|
|
370
|
+
}
|
|
371
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:') {
|
|
372
|
+
return `Endpoint must use http or https, received "${parsed.protocol}".`;
|
|
373
|
+
}
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
204
376
|
/**
|
|
205
377
|
* Ensures state.json records the newly scaffolded plugin as disabled.
|
|
206
378
|
*/
|
|
207
|
-
recordPluginState(pluginName, digest) {
|
|
379
|
+
recordPluginState(pluginName, digest, stateRoot = this.pluginsRoot) {
|
|
208
380
|
try {
|
|
209
|
-
if (!fs.existsSync(
|
|
210
|
-
fs.mkdirSync(
|
|
381
|
+
if (!fs.existsSync(stateRoot)) {
|
|
382
|
+
fs.mkdirSync(stateRoot, { recursive: true, mode: 0o700 });
|
|
211
383
|
}
|
|
212
|
-
const stateFile = path.join(
|
|
384
|
+
const stateFile = path.join(stateRoot, 'state.json');
|
|
213
385
|
let state = {
|
|
214
386
|
version: 1,
|
|
215
387
|
plugins: {}
|
|
@@ -218,8 +390,11 @@ export class PluginsFactory {
|
|
|
218
390
|
try {
|
|
219
391
|
const raw = fs.readFileSync(stateFile, 'utf8');
|
|
220
392
|
const parsed = JSON.parse(raw);
|
|
221
|
-
|
|
222
|
-
|
|
393
|
+
const parsedPlugins = parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
394
|
+
? parsed.plugins
|
|
395
|
+
: undefined;
|
|
396
|
+
if (parsedPlugins && typeof parsedPlugins === 'object' && !Array.isArray(parsedPlugins)) {
|
|
397
|
+
state = { version: 1, plugins: parsedPlugins };
|
|
223
398
|
}
|
|
224
399
|
}
|
|
225
400
|
catch {
|