@causyne/agent 1.20.122 → 1.20.127
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/bin/causyne.js +38 -15
- package/docs/SECURITY_REVIEW.md +42 -6
- package/package.json +7 -7
- package/src/acp/agentCatalog.js +74 -50
- package/src/acp/agentCatalog.ts +82 -49
- package/src/acp/client.js +309 -86
- package/src/acp/client.ts +291 -84
- package/src/acp/protocol.js +147 -3
- package/src/acp/protocol.ts +181 -4
- package/src/acp/server.js +418 -45
- package/src/acp/server.ts +404 -47
- package/src/agent/abortableDelay.js +2 -2
- package/src/agent/abortableDelay.ts +2 -2
- package/src/agent/errorClassifier.js +51 -7
- package/src/agent/errorClassifier.ts +52 -6
- package/src/agent/providerFailure.js +1 -1
- package/src/agent/providerFailure.ts +7 -1
- package/src/agent/toolArgValidator.js +38 -4
- package/src/agent/toolArgValidator.ts +39 -4
- package/src/agent/toolTurnIntegrity.js +28 -7
- package/src/agent/toolTurnIntegrity.ts +25 -6
- package/src/agent/workspaceBoundary.js +30 -4
- package/src/agent/workspaceBoundary.ts +32 -4
- package/src/agentLoop.js +673 -236
- package/src/agentLoop.ts +705 -233
- package/src/approvalPolicy.js +61 -10
- package/src/approvalPolicy.ts +69 -11
- package/src/auditLog.js +641 -48
- package/src/auditLog.ts +661 -0
- package/src/autoUpdate.js +32 -5
- package/src/autoUpdate.ts +27 -5
- package/src/backgroundTasks.js +328 -0
- package/src/backgroundTasks.ts +339 -0
- package/src/benchmarks/codingEval.js +558 -0
- package/src/benchmarks/codingEval.ts +628 -0
- package/src/benchmarks/planCache.js +115 -134
- package/src/benchmarks/planCache.ts +163 -0
- package/src/browser/browserRuntime.js +52 -0
- package/src/browser/browserRuntime.ts +55 -0
- package/src/browser/causyneBrowser.js +914 -13
- package/src/browser/causyneBrowser.ts +1075 -35
- package/src/browser/searchProviders.js +94 -6
- package/src/browser/searchProviders.ts +89 -6
- package/src/browser/urlPolicy.js +22 -2
- package/src/browser/urlPolicy.ts +19 -2
- package/src/browser/workspacePathSafety.js +6 -4
- package/src/browser/workspacePathSafety.ts +7 -4
- package/src/capabilities.js +18 -17
- package/src/capabilities.ts +38 -0
- package/src/checkpoints.js +1241 -1127
- package/src/checkpoints.ts +1377 -0
- package/src/cliMode.js +718 -754
- package/src/cliMode.ts +792 -0
- package/src/codebase/repoMap.js +656 -0
- package/src/codebase/repoMap.ts +664 -0
- package/src/commands.js +3806 -2513
- package/src/commands.ts +4162 -0
- package/src/compiledSkills.js +8052 -8054
- package/src/compiledSkills.ts +8078 -0
- package/src/config.js +118 -1
- package/src/config.ts +124 -1
- package/src/configVault.js +29 -2
- package/src/configVault.ts +26 -2
- package/src/contextManager.js +473 -557
- package/src/contextManager.ts +599 -0
- package/src/continuum/adapters/antigravity.js +8 -3
- package/src/continuum/adapters/antigravity.ts +8 -3
- package/src/continuum/sanitizer.js +23 -1
- package/src/continuum/sanitizer.ts +23 -1
- package/src/continuum/ui/continuumPicker.js +0 -2
- package/src/continuum/ui/continuumPicker.ts +0 -2
- package/src/continuum/ui/continuumPickerView.js +0 -2
- package/src/continuum/ui/continuumPickerView.ts +4 -20
- package/src/core/contextCompactor.js +142 -14
- package/src/core/contextCompactor.ts +150 -15
- package/src/core/goalLoop.js +257 -0
- package/src/core/goalLoop.ts +310 -0
- package/src/creative/liveBridge.js +3 -2
- package/src/creative/liveBridge.ts +4 -2
- package/src/creative/studioScripts.js +1 -1
- package/src/creative/studioScripts.ts +1 -1
- package/src/decideTools.js +7 -2
- package/src/decideTools.ts +7 -2
- package/src/decisionPolicy.js +10 -2
- package/src/decisionPolicy.ts +10 -2
- package/src/designPalettes.js +72 -84
- package/src/designPalettes.ts +111 -0
- package/src/devMode.js +2 -2
- package/src/devMode.ts +6 -0
- package/src/diffReview.js +370 -0
- package/src/diffReview.ts +407 -0
- package/src/dynamicCatalogue.js +311 -11
- package/src/dynamicCatalogue.ts +331 -11
- package/src/embodimentSession.js +143 -154
- package/src/embodimentSession.ts +173 -0
- package/src/engines/installer.js +60 -29
- package/src/engines/installer.ts +73 -22
- package/src/enterprisePolicy.js +660 -0
- package/src/enterprisePolicy.ts +728 -0
- package/src/entrypoint.js +646 -268
- package/src/entrypoint.ts +740 -0
- package/src/game/causyneCoreBridge.js +686 -0
- package/src/game/causyneCoreBridge.ts +702 -0
- package/src/game/gameLauncher.js +287 -0
- package/src/game/gameLauncher.ts +352 -0
- package/src/game/gameProvisioner.js +425 -0
- package/src/game/gameProvisioner.ts +488 -0
- package/src/gitSnapshot.js +417 -312
- package/src/gitSnapshot.ts +500 -0
- package/src/headlessCli.js +343 -25
- package/src/headlessCli.ts +343 -20
- package/src/hooks.js +247 -26
- package/src/hooks.ts +236 -26
- package/src/ignoreRules.js +297 -0
- package/src/ignoreRules.ts +308 -0
- package/src/implementationPlan.js +7 -6
- package/src/implementationPlan.ts +8 -6
- package/src/infra/atomicWriter.js +127 -18
- package/src/infra/atomicWriter.ts +141 -20
- package/src/launchIntent.js +85 -4
- package/src/launchIntent.ts +88 -4
- package/src/licensing/entitlements.js +553 -237
- package/src/licensing/entitlements.ts +590 -0
- package/src/licensing/policy.js +17 -1
- package/src/licensing/policy.ts +31 -0
- package/src/lsp/lspCatalog.js +398 -0
- package/src/lsp/lspCatalog.ts +452 -0
- package/src/lsp/lspClient.js +770 -0
- package/src/lsp/lspClient.ts +862 -0
- package/src/lsp/lspProtocol.js +121 -0
- package/src/lsp/lspProtocol.ts +140 -0
- package/src/mcp/mcpClient.js +69 -8
- package/src/mcp/mcpClient.ts +66 -9
- package/src/mcp/mcpRegistry.js +255 -15
- package/src/mcp/mcpRegistry.ts +241 -14
- package/src/mcp/mcpSecurity.js +6 -7
- package/src/mcp/mcpSecurity.ts +7 -6
- package/src/memory/contextBudget.js +2 -0
- package/src/memory/contextBudget.ts +1 -0
- package/src/memory/episodicStore.js +2 -5
- package/src/memory/episodicStore.ts +2 -5
- package/src/memory.js +80 -32
- package/src/memory.ts +111 -0
- package/src/memoryManager.js +151 -143
- package/src/memoryManager.ts +182 -0
- package/src/modelCatalogue.js +172 -195
- package/src/modelCatalogue.ts +201 -0
- package/src/modelIds.js +8 -27
- package/src/modelIds.ts +33 -0
- package/src/modelVariants.js +645 -0
- package/src/modelVariants.ts +717 -0
- package/src/observer/evidence.js +5 -1
- package/src/observer/evidence.ts +5 -1
- package/src/osKeychain.js +17 -9
- package/src/osKeychain.ts +14 -9
- package/src/outputRecovery.js +3 -2
- package/src/outputRecovery.ts +4 -2
- package/src/outputStore.js +210 -156
- package/src/outputStore.ts +321 -0
- package/src/permissionPresets.js +327 -0
- package/src/permissionPresets.ts +361 -0
- package/src/planCache.js +3 -6
- package/src/planCache.ts +3 -6
- package/src/plugins/pluginManager.js +689 -461
- package/src/plugins/pluginManager.ts +807 -0
- package/src/plugins/pluginRunner.js +82 -37
- package/src/plugins/pluginRunner.ts +98 -0
- package/src/plugins/pluginSkills.js +47 -9
- package/src/plugins/pluginSkills.ts +46 -8
- package/src/pluginsFactory/discovery.js +0 -1
- package/src/pluginsFactory/discovery.ts +0 -1
- package/src/pluginsFactory/templates.js +17 -4
- package/src/pluginsFactory/templates.ts +17 -4
- package/src/prWorkflow.js +337 -0
- package/src/prWorkflow.ts +376 -0
- package/src/procSignal.js +1 -2
- package/src/procSignal.ts +1 -3
- package/src/projectInstructions.js +319 -0
- package/src/projectInstructions.ts +361 -0
- package/src/providers/acp.js +234 -49
- package/src/providers/acp.ts +240 -50
- package/src/providers/anthropic.js +152 -47
- package/src/providers/anthropic.ts +152 -45
- package/src/providers/antigravity.js +620 -356
- package/src/providers/antigravity.ts +621 -357
- package/src/providers/base.js +9 -2
- package/src/providers/base.ts +10 -2
- package/src/providers/byokHttp.js +134 -18
- package/src/providers/byokHttp.ts +181 -19
- package/src/providers/byokStream.js +183 -44
- package/src/providers/byokStream.ts +179 -62
- package/src/providers/dashscope-byok.js +50 -8
- package/src/providers/dashscope-byok.ts +59 -13
- package/src/providers/deepseek.js +12 -3
- package/src/providers/deepseek.ts +12 -3
- package/src/providers/factory.js +41 -0
- package/src/providers/factory.ts +42 -0
- package/src/providers/gemini.js +74 -22
- package/src/providers/gemini.ts +78 -26
- package/src/providers/moonshot.js +60 -8
- package/src/providers/moonshot.ts +64 -14
- package/src/providers/muse.js +6 -0
- package/src/providers/muse.ts +8 -0
- package/src/providers/ollama.js +299 -21
- package/src/providers/ollama.ts +331 -29
- package/src/providers/openai-compatible.js +81 -12
- package/src/providers/openai-compatible.ts +89 -18
- package/src/providers/openai.js +87 -6
- package/src/providers/openai.ts +74 -6
- package/src/providers/openrouter.js +248 -66
- package/src/providers/openrouter.ts +243 -70
- package/src/providers/qwen-byok.js +50 -8
- package/src/providers/qwen-byok.ts +59 -13
- package/src/providers/wireNormalizer.js +66 -0
- package/src/providers/wireNormalizer.ts +64 -0
- package/src/providers/xai.js +31 -8
- package/src/providers/xai.ts +38 -14
- package/src/provisioning/capabilityConsent.js +29 -11
- package/src/provisioning/capabilityConsent.ts +42 -0
- package/src/provisioning/capabilityProvisioner.js +309 -197
- package/src/provisioning/capabilityProvisioner.ts +413 -0
- package/src/provisioning/capabilityTools.js +31 -17
- package/src/provisioning/capabilityTools.ts +43 -0
- package/src/provisioning/npmInstall.js +33 -5
- package/src/provisioning/npmInstall.ts +33 -5
- package/src/reporting.js +330 -326
- package/src/reporting.ts +484 -0
- package/src/sandbox.js +71 -0
- package/src/sandbox.ts +81 -0
- package/src/scheduler/scheduler.js +372 -0
- package/src/scheduler/scheduler.ts +433 -0
- package/src/sessionJournal.js +24 -3
- package/src/sessionJournal.ts +18 -3
- package/src/sessionSearchIndex.js +267 -0
- package/src/sessionSearchIndex.ts +311 -0
- package/src/sessionStore.js +1 -2
- package/src/sessionStore.ts +2 -0
- package/src/skillsManager.js +2 -3
- package/src/skillsManager.ts +2 -3
- package/src/slopDetector.js +202 -265
- package/src/slopDetector.ts +279 -0
- package/src/smartToolsUse.js +10 -4
- package/src/smartToolsUse.ts +10 -4
- package/src/stallGuard.js +10 -3
- package/src/stallGuard.ts +9 -3
- package/src/taskBuffer.js +91 -40
- package/src/taskBuffer.ts +94 -0
- package/src/tokenTracker.js +78 -11
- package/src/tokenTracker.ts +69 -11
- package/src/toolPacks.js +11 -0
- package/src/toolPacks.ts +11 -0
- package/src/tools/applyPatch.js +610 -0
- package/src/tools/applyPatch.ts +661 -0
- package/src/tools/archive.js +135 -21
- package/src/tools/archive.ts +136 -21
- package/src/tools/astryxOracle.js +77 -72
- package/src/tools/astryxOracle.ts +95 -0
- package/src/tools/axSnapshot.js +127 -147
- package/src/tools/axSnapshot.ts +174 -0
- package/src/tools/backgroundTask.js +86 -0
- package/src/tools/backgroundTask.ts +121 -0
- package/src/tools/blenderAutomator.js +434 -390
- package/src/tools/blenderAutomator.ts +623 -0
- package/src/tools/checkSystemSpecs.js +54 -61
- package/src/tools/checkSystemSpecs.ts +73 -0
- package/src/tools/clipboard.js +42 -31
- package/src/tools/clipboard.ts +61 -0
- package/src/tools/codeSearchAst.js +359 -91
- package/src/tools/codeSearchAst.ts +399 -0
- package/src/tools/codeSearcher.js +179 -37
- package/src/tools/codeSearcher.ts +188 -33
- package/src/tools/codeTools.js +208 -245
- package/src/tools/codeTools.ts +271 -0
- package/src/tools/codebaseSearch.js +5 -0
- package/src/tools/codebaseSearch.ts +5 -0
- package/src/tools/desktopAct.js +185 -197
- package/src/tools/desktopAct.ts +257 -0
- package/src/tools/dynamicLoader.js +4 -40
- package/src/tools/dynamicLoader.ts +13 -0
- package/src/tools/executeProceduralMedia.js +117 -86
- package/src/tools/executeProceduralMedia.ts +135 -0
- package/src/tools/fileTracker.js +74 -0
- package/src/tools/fileTracker.ts +94 -0
- package/src/tools/fsDelete.js +57 -47
- package/src/tools/fsDelete.ts +80 -0
- package/src/tools/fsEdit.js +192 -74
- package/src/tools/fsEdit.ts +201 -72
- package/src/tools/fsMove.js +79 -52
- package/src/tools/fsMove.ts +108 -0
- package/src/tools/fsRead.js +54 -15
- package/src/tools/fsRead.ts +55 -15
- package/src/tools/fsSearch.js +5 -0
- package/src/tools/fsSearch.ts +5 -0
- package/src/tools/fsWrite.js +14 -6
- package/src/tools/fsWrite.ts +14 -6
- package/src/tools/gameAiBehaviorTree.js +74 -91
- package/src/tools/gameAiBehaviorTree.ts +219 -0
- package/src/tools/gameAnimationRig.js +128 -147
- package/src/tools/gameAnimationRig.ts +215 -0
- package/src/tools/gameAssetFetcher.js +403 -441
- package/src/tools/gameAssetFetcher.ts +477 -0
- package/src/tools/gameAssetHarvester.js +171 -200
- package/src/tools/gameAssetHarvester.ts +261 -0
- package/src/tools/gameAudioSynth.js +223 -259
- package/src/tools/gameAudioSynth.ts +255 -0
- package/src/tools/gameBuilder.js +100 -91
- package/src/tools/gameBuilder.ts +913 -0
- package/src/tools/gameCanvasAudit.js +138 -96
- package/src/tools/gameCanvasAudit.ts +157 -0
- package/src/tools/gameCinematicSequencer.js +93 -111
- package/src/tools/gameCinematicSequencer.ts +165 -0
- package/src/tools/gameDataForge.js +115 -118
- package/src/tools/gameDataForge.ts +151 -0
- package/src/tools/gameDialogueTreeGen.js +125 -156
- package/src/tools/gameDialogueTreeGen.ts +159 -0
- package/src/tools/gameEconomyBalancer.js +150 -153
- package/src/tools/gameEconomyBalancer.ts +186 -0
- package/src/tools/gameEntitySpawner.js +91 -108
- package/src/tools/gameEntitySpawner.ts +209 -0
- package/src/tools/gameLoreForge.js +125 -147
- package/src/tools/gameLoreForge.ts +162 -0
- package/src/tools/gameQuestArcBuilder.js +105 -144
- package/src/tools/gameQuestArcBuilder.ts +147 -0
- package/src/tools/gameSceneBuilder.js +143 -149
- package/src/tools/gameSceneBuilder.ts +196 -0
- package/src/tools/gameShaderForge.js +83 -101
- package/src/tools/gameShaderForge.ts +181 -0
- package/src/tools/gameTilemapGenerator.js +99 -129
- package/src/tools/gameTilemapGenerator.ts +158 -0
- package/src/tools/gameUiHudBuilder.js +109 -129
- package/src/tools/gameUiHudBuilder.ts +300 -0
- package/src/tools/gameVfxEmitterGen.js +86 -89
- package/src/tools/gameVfxEmitterGen.ts +133 -0
- package/src/tools/gameWebRuntimeInspector.js +153 -86
- package/src/tools/gameWebRuntimeInspector.ts +167 -0
- package/src/tools/generateMediaViaApi.js +57 -15
- package/src/tools/generateMediaViaApi.ts +56 -15
- package/src/tools/gitExec.js +133 -86
- package/src/tools/gitExec.ts +146 -0
- package/src/tools/gitWorktree.js +115 -0
- package/src/tools/gitWorktree.ts +150 -0
- package/src/tools/godotAutomator.js +417 -394
- package/src/tools/godotAutomator.ts +530 -0
- package/src/tools/lspCodeIntel.js +217 -0
- package/src/tools/lspCodeIntel.ts +260 -0
- package/src/tools/manageLocalAiDependencies.js +242 -206
- package/src/tools/manageLocalAiDependencies.ts +288 -0
- package/src/tools/multiEdit.js +16 -76
- package/src/tools/multiEdit.ts +20 -77
- package/src/tools/nativeEngine.js +2 -2
- package/src/tools/nativeEngine.ts +2 -2
- package/src/tools/openSourceToolProvisioner.js +2 -2
- package/src/tools/openSourceToolProvisioner.ts +2 -2
- package/src/tools/osSandbox.js +152 -15
- package/src/tools/osSandbox.ts +148 -15
- package/src/tools/palmierAutomator.js +147 -95
- package/src/tools/palmierAutomator.ts +171 -0
- package/src/tools/payloadSanitizer.js +0 -1
- package/src/tools/payloadSanitizer.ts +0 -1
- package/src/tools/pdfReader.js +197 -104
- package/src/tools/pdfReader.ts +216 -0
- package/src/tools/persistentShell.js +267 -144
- package/src/tools/persistentShell.ts +314 -0
- package/src/tools/pluginManager.js +84 -72
- package/src/tools/pluginManager.ts +109 -0
- package/src/tools/presentDeliverable.js +103 -0
- package/src/tools/presentDeliverable.ts +127 -0
- package/src/tools/printer.js +278 -296
- package/src/tools/printer.ts +326 -0
- package/src/tools/procTerm.js +96 -83
- package/src/tools/procTerm.ts +127 -0
- package/src/tools/processList.js +45 -48
- package/src/tools/processList.ts +73 -0
- package/src/tools/ptcRuntime.js +444 -0
- package/src/tools/ptcRuntime.ts +490 -0
- package/src/tools/ptyTerminal.js +1096 -0
- package/src/tools/ptyTerminal.ts +1231 -0
- package/src/tools/registry.js +308 -287
- package/src/tools/registry.ts +495 -0
- package/src/tools/repoMap.js +46 -0
- package/src/tools/repoMap.ts +66 -0
- package/src/tools/subagentOrchestrator.js +404 -348
- package/src/tools/subagentOrchestrator.ts +457 -0
- package/src/tools/sysRun.js +83 -26
- package/src/tools/sysRun.ts +80 -26
- package/src/tools/toolForge.js +84 -67
- package/src/tools/toolForge.ts +102 -0
- package/src/tools/toolOutputStore.js +26 -4
- package/src/tools/toolOutputStore.ts +22 -4
- package/src/tools/toolPathSafety.js +262 -0
- package/src/tools/toolPathSafety.ts +308 -0
- package/src/tools/toolScanner.js +28 -0
- package/src/tools/toolScanner.ts +29 -0
- package/src/tools/toolSelfRepair.js +21 -6
- package/src/tools/toolSelfRepair.ts +26 -6
- package/src/tools/walkerSafety.ts +1 -0
- package/src/tools/webFetch.js +163 -13
- package/src/tools/webFetch.ts +150 -13
- package/src/tools/webSearch.js +123 -36
- package/src/tools/webSearch.ts +124 -33
- package/src/toolsList.js +5 -0
- package/src/toolsList.ts +5 -0
- package/src/tui/ask.js +159 -168
- package/src/tui/ask.ts +259 -0
- package/src/tui/banner.js +5 -1
- package/src/tui/banner.ts +6 -1
- package/src/tui/block.js +0 -1
- package/src/tui/block.ts +0 -1
- package/src/tui/chatRenderer.js +1194 -1443
- package/src/tui/chatRenderer.ts +1335 -0
- package/src/tui/clipboardImage.js +36 -12
- package/src/tui/clipboardImage.ts +39 -13
- package/src/tui/clipboardSync.js +34 -9
- package/src/tui/clipboardSync.ts +38 -9
- package/src/tui/codeProgress.js +0 -1
- package/src/tui/codeProgress.ts +0 -1
- package/src/tui/completion.js +396 -371
- package/src/tui/completion.ts +575 -0
- package/src/tui/composerControls.js +212 -34
- package/src/tui/composerControls.ts +235 -34
- package/src/tui/consoleGuard.js +27 -7
- package/src/tui/consoleGuard.ts +29 -7
- package/src/tui/dialogs.js +867 -733
- package/src/tui/dialogs.ts +971 -0
- package/src/tui/diff.js +205 -195
- package/src/tui/diff.ts +336 -0
- package/src/tui/history.js +143 -108
- package/src/tui/history.ts +167 -0
- package/src/tui/home.js +166 -161
- package/src/tui/home.ts +252 -0
- package/src/tui/invocation.js +59 -67
- package/src/tui/invocation.ts +116 -0
- package/src/tui/keys.js +437 -420
- package/src/tui/keys.ts +597 -0
- package/src/tui/lineEditor.js +477 -432
- package/src/tui/lineEditor.ts +542 -0
- package/src/tui/messageActionPlacement.js +0 -1
- package/src/tui/messageActionPlacement.ts +0 -1
- package/src/tui/messageInteraction.js +0 -2
- package/src/tui/messageInteraction.ts +0 -2
- package/src/tui/modelPicker.js +22 -15
- package/src/tui/modelPicker.ts +25 -18
- package/src/tui/observerPicker.js +0 -2
- package/src/tui/observerPicker.ts +0 -2
- package/src/tui/overlay.js +2 -6
- package/src/tui/overlay.ts +2 -6
- package/src/tui/prompt.js +1818 -2151
- package/src/tui/prompt.ts +1872 -0
- package/src/tui/runningLight.js +0 -1
- package/src/tui/runningLight.ts +0 -1
- package/src/tui/selectList.js +369 -349
- package/src/tui/selectList.ts +433 -0
- package/src/tui/sessionPicker.js +0 -1
- package/src/tui/sessionPicker.ts +0 -1
- package/src/tui/sessionPickerView.js +0 -2
- package/src/tui/sessionPickerView.ts +4 -21
- package/src/tui/sessionSidebar.js +3 -1
- package/src/tui/sessionSidebar.ts +4 -1
- package/src/tui/setup.js +39 -14
- package/src/tui/setup.ts +45 -14
- package/src/tui/skillAuthoring.js +0 -2
- package/src/tui/skillAuthoring.ts +0 -3
- package/src/tui/stageSurface.js +829 -909
- package/src/tui/stageSurface.ts +1003 -0
- package/src/tui/statusLine.js +7 -4
- package/src/tui/statusLine.ts +9 -3
- package/src/tui/terminalInputFramer.js +82 -69
- package/src/tui/terminalInputFramer.ts +116 -0
- package/src/tui/text.js +25 -10
- package/src/tui/text.ts +24 -10
- package/src/tui/textLayout.js +0 -1
- package/src/tui/textLayout.ts +0 -1
- package/src/tui/theme.js +245 -250
- package/src/tui/theme.ts +441 -0
- package/src/tui/thinkingBox.js +0 -1
- package/src/tui/thinkingBox.ts +0 -1
- package/src/tui/transcript.js +239 -216
- package/src/tui/transcript.ts +324 -0
- package/src/tui/turnRail.js +53 -54
- package/src/tui/turnRail.ts +51 -49
- package/src/tui/usageCard.js +0 -2
- package/src/tui/usageCard.ts +0 -2
- package/src/tui/workspaceSwitch.js +4 -2
- package/src/tui/workspaceSwitch.ts +5 -2
- package/src/types/contracts.ts +4 -1
- package/src/utils/browserOpen.js +107 -0
- package/src/utils/browserOpen.ts +129 -0
- package/src/utils/cli_ui.js +0 -0
- package/src/utils/cli_ui.ts +158 -0
- package/src/utils/winSpawn.js +248 -0
- package/src/utils/winSpawn.ts +275 -0
- package/src/verification/boundedExplorer.js +138 -107
- package/src/verification/boundedExplorer.ts +154 -0
- package/src/verification/byokSmokeProbe.js +193 -0
- package/src/verification/byokSmokeProbe.ts +234 -0
- package/src/verification/cliProbe.js +144 -110
- package/src/verification/cliProbe.ts +170 -0
- package/src/verification/featureMap.js +105 -75
- package/src/verification/featureMap.ts +124 -0
- package/src/verification/interactivePty.js +195 -100
- package/src/verification/interactivePty.ts +333 -0
- package/src/verification/propertyProbe.js +109 -101
- package/src/verification/propertyProbe.ts +159 -0
- package/src/verification/ptyProbe.js +168 -73
- package/src/verification/ptyProbe.ts +254 -0
- package/src/verification/skillCatalog.js +25 -25
- package/src/verification/skillCatalog.ts +66 -0
- package/src/verification/statechart.js +140 -127
- package/src/verification/statechart.ts +196 -0
- package/src/verification/uiRuntime.js +80 -49
- package/src/verification/uiRuntime.ts +88 -0
- package/src/version.js +37 -32
- package/src/version.ts +45 -0
- package/src/web/client/browserPanel.js +702 -0
- package/src/web/client/browserPanel.ts +663 -0
- package/src/web/client/chatStream.js +309 -0
- package/src/web/client/chatStream.ts +289 -0
- package/src/web/client/cliPanel.js +165 -0
- package/src/web/client/cliPanel.ts +171 -0
- package/src/web/client/composer.js +204 -0
- package/src/web/client/composer.ts +209 -0
- package/src/web/client/diffPanel.js +176 -0
- package/src/web/client/diffPanel.ts +203 -0
- package/src/web/client/dom.js +220 -0
- package/src/web/client/dom.ts +221 -0
- package/src/web/client/filesAndCanvas.js +231 -0
- package/src/web/client/filesAndCanvas.ts +238 -0
- package/src/web/client/gameLauncherUi.js +78 -0
- package/src/web/client/gameLauncherUi.ts +78 -0
- package/src/web/client/main.js +301 -0
- package/src/web/client/main.ts +368 -0
- package/src/web/client/markdown.js +364 -0
- package/src/web/client/markdown.ts +373 -0
- package/src/web/client/modelPicker.js +455 -0
- package/src/web/client/modelPicker.ts +451 -0
- package/src/web/client/permissionPresetsUi.js +307 -0
- package/src/web/client/permissionPresetsUi.ts +333 -0
- package/src/web/client/sessions.js +353 -0
- package/src/web/client/sessions.ts +372 -0
- package/src/web/client/settingsModal.js +191 -0
- package/src/web/client/settingsModal.ts +176 -0
- package/src/web/client/state.js +250 -0
- package/src/web/client/state.ts +233 -0
- package/src/web/client/streamSmoother.js +127 -0
- package/src/web/client/streamSmoother.ts +119 -0
- package/src/web/client/studioLayout.js +54 -0
- package/src/web/client/studioLayout.ts +60 -0
- package/src/web/client/studioShell.js +327 -0
- package/src/web/client/studioShell.ts +340 -0
- package/src/web/client/studioStart.js +77 -0
- package/src/web/client/studioStart.ts +89 -0
- package/src/web/client/terminalPanel.js +357 -0
- package/src/web/client/terminalPanel.ts +345 -0
- package/src/web/client/turnView.js +934 -0
- package/src/web/client/turnView.ts +981 -0
- package/src/web/client/types.js +1 -0
- package/src/web/client/types.ts +319 -0
- package/src/web/client/validators.js +106 -0
- package/src/web/client/validators.ts +96 -0
- package/src/web/guiLauncher.js +89 -0
- package/src/web/guiLauncher.ts +119 -0
- package/src/web/server/activeRuns.js +152 -0
- package/src/web/server/activeRuns.ts +171 -0
- package/src/web/server/routesBrowser.js +355 -0
- package/src/web/server/routesBrowser.ts +386 -0
- package/src/web/server/routesChat.js +304 -0
- package/src/web/server/routesChat.ts +347 -0
- package/src/web/server/routesCore.js +472 -0
- package/src/web/server/routesCore.ts +522 -0
- package/src/web/server/routesTerminal.js +162 -0
- package/src/web/server/routesTerminal.ts +182 -0
- package/src/web/server/routesWorkspace.js +510 -0
- package/src/web/server/routesWorkspace.ts +546 -0
- package/src/web/server/security.js +98 -0
- package/src/web/server/security.ts +108 -0
- package/src/web/server/sessionTranscript.js +586 -0
- package/src/web/server/sessionTranscript.ts +566 -0
- package/src/web/server/staticAssets.js +80 -0
- package/src/web/server/staticAssets.ts +91 -0
- package/src/web/server/types.js +1 -0
- package/src/web/server/types.ts +135 -0
- package/src/web/server/workspaceFiles.js +368 -0
- package/src/web/server/workspaceFiles.ts +363 -0
- package/src/web/skybridgeBrowserBridge.js +256 -0
- package/src/web/skybridgeBrowserBridge.ts +285 -0
- package/src/web/skybridgeBrowserMcp.js +730 -0
- package/src/web/skybridgeBrowserMcp.ts +813 -0
- package/src/web/skybridgeServer.js +249 -0
- package/src/web/skybridgeServer.ts +305 -0
- package/src/web/skybridgeUi.js +38 -0
- package/src/web/skybridgeUi.ts +47 -0
- package/src/web/styles/agent.css +380 -0
- package/src/web/styles/composer.css +193 -0
- package/src/web/styles/overlays.css +436 -0
- package/src/web/styles/shell.css +387 -0
- package/src/web/styles/studio.css +723 -0
- package/src/web/styles/thread.css +221 -0
- package/src/web/styles/tokens.css +94 -0
- package/src/web/ui/brandMark.js +73 -0
- package/src/web/ui/brandMark.ts +82 -0
- package/src/web/ui/modalsTemplate.js +139 -0
- package/src/web/ui/modalsTemplate.ts +139 -0
- package/src/web/ui/sidebarTemplate.js +63 -0
- package/src/web/ui/sidebarTemplate.ts +64 -0
- package/src/web/ui/studioTemplate.js +258 -0
- package/src/web/ui/studioTemplate.ts +258 -0
- package/src/web/ui/workspaceTemplate.js +72 -0
- package/src/web/ui/workspaceTemplate.ts +73 -0
- package/src/worktreeManager.js +526 -0
- package/src/worktreeManager.ts +567 -0
- package/src/zeroCostFailover.js +168 -0
- package/src/zeroCostFailover.ts +198 -0
- package/src/zeroCostRouting.js +391 -0
- package/src/zeroCostRouting.ts +437 -0
- package/src/agentLoop.d.ts +0 -65
- package/src/auditLog.d.ts +0 -3
- package/src/checkpoints.d.ts +0 -4
- package/src/compiledSkills.d.ts +0 -5
- package/src/contextManager.d.ts +0 -14
- package/src/designPalettes.d.ts +0 -2
- package/src/devMode.d.ts +0 -1
- package/src/embodimentSession.d.ts +0 -2
- package/src/licensing/entitlements.d.ts +0 -14
- package/src/memory.d.ts +0 -13
- package/src/memoryManager.d.ts +0 -1
- package/src/modelCatalogue.d.ts +0 -6
- package/src/modelIds.d.ts +0 -2
- package/src/outputStore.d.ts +0 -4
- package/src/plugins/pluginManager.d.ts +0 -7
- package/src/providers/antigravity.d.ts +0 -19
- package/src/provisioning/capabilityProvisioner.d.ts +0 -12
- package/src/slopDetector.d.ts +0 -3
- package/src/taskBuffer.d.ts +0 -1
- package/src/tools/desktopAct.d.ts +0 -10
- package/src/tools/registry.d.ts +0 -5
- package/src/tui/chatRenderer.d.ts +0 -27
- package/src/tui/diff.d.ts +0 -3
- package/src/utils/cli_ui.d.ts +0 -19
- package/src/utils/paths.d.ts +0 -3
- package/src/verification/skillCatalog.d.ts +0 -1
- package/src/version.d.ts +0 -1
|
@@ -5,9 +5,18 @@ import { spawn } from 'node:child_process';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { causyneHome } from '../utils/paths.js';
|
|
7
7
|
import { parsePluginSkills } from './pluginSkills.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { isWithinPhysicalPath, physicalPath } from '../agent/workspaceBoundary.js';
|
|
9
|
+
import { isBlockedWorkspaceRoot } from '../sandboxPolicy.js';
|
|
10
|
+
import { redactProviderSecrets } from '../providers/byokHttp.js';
|
|
11
|
+
import { safeDisplay } from '../tui/text.js';
|
|
12
|
+
function pluginRoot() {
|
|
13
|
+
return path.join(causyneHome(), 'plugins');
|
|
14
|
+
}
|
|
15
|
+
function stateFile() {
|
|
16
|
+
return path.join(pluginRoot(), 'state.json');
|
|
17
|
+
}
|
|
18
|
+
const PLUGIN_ROOT = pluginRoot();
|
|
19
|
+
const STATE_FILE = stateFile();
|
|
11
20
|
const RUNNER_FILE = fileURLToPath(new URL('./pluginRunner.js', import.meta.url));
|
|
12
21
|
const PACKAGE_FILE = fileURLToPath(new URL('../../package.json', import.meta.url));
|
|
13
22
|
const MAX_MANIFEST_BYTES = 64 * 1024;
|
|
@@ -19,516 +28,735 @@ const MAX_RESULT_BYTES = 1024 * 1024;
|
|
|
19
28
|
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
20
29
|
const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
21
30
|
const TOOL_NAME = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
31
|
+
const EXPORT_IDENT = /^[A-Za-z_$][A-Za-z0-9_$]{0,63}$/;
|
|
22
32
|
const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
23
33
|
const CAPABILITIES = new Set([
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
34
|
+
'workspace:read',
|
|
35
|
+
'workspace:write',
|
|
36
|
+
'network',
|
|
37
|
+
'subprocess'
|
|
28
38
|
]);
|
|
29
|
-
|
|
30
39
|
function ensureRoot() {
|
|
31
|
-
|
|
40
|
+
const root = pluginRoot();
|
|
41
|
+
if (!fs.existsSync(root)) {
|
|
42
|
+
fs.mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const stat = fs.lstatSync(root);
|
|
46
|
+
if (stat.isSymbolicLink() || !stat.isDirectory()) {
|
|
47
|
+
throw new Error('Refusing symlink or non-directory plugin root');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (process.platform !== 'win32') {
|
|
51
|
+
try {
|
|
52
|
+
fs.chmodSync(root, 0o700);
|
|
53
|
+
}
|
|
54
|
+
catch { /* ignore */ }
|
|
55
|
+
}
|
|
32
56
|
}
|
|
33
|
-
|
|
34
57
|
function safeObject(value) {
|
|
35
|
-
|
|
58
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
36
59
|
}
|
|
37
|
-
|
|
60
|
+
const MAX_STATE_BYTES = 1024 * 1024;
|
|
61
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
38
62
|
function readState() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
63
|
+
try {
|
|
64
|
+
const sf = stateFile();
|
|
65
|
+
const stat = fs.lstatSync(sf);
|
|
66
|
+
if (stat.isSymbolicLink() || !stat.isFile() || stat.size > MAX_STATE_BYTES) {
|
|
67
|
+
return { version: 1, plugins: Object.create(null) };
|
|
68
|
+
}
|
|
69
|
+
const parsed = JSON.parse(fs.readFileSync(sf, 'utf8'));
|
|
70
|
+
const rawPlugins = safeObject(parsed?.plugins);
|
|
71
|
+
const clean = Object.create(null);
|
|
72
|
+
for (const [key, val] of Object.entries(rawPlugins)) {
|
|
73
|
+
if (!NAME.test(key) || FORBIDDEN_KEYS.has(key))
|
|
74
|
+
continue;
|
|
75
|
+
if (val && typeof val === 'object' && !Array.isArray(val)) {
|
|
76
|
+
clean[key] = val;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { version: 1, plugins: clean };
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return { version: 1, plugins: Object.create(null) };
|
|
83
|
+
}
|
|
46
84
|
}
|
|
47
|
-
|
|
48
85
|
function writeState(state) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
86
|
+
ensureRoot();
|
|
87
|
+
const sf = stateFile();
|
|
88
|
+
try {
|
|
89
|
+
const existing = fs.lstatSync(sf);
|
|
90
|
+
if (existing.isSymbolicLink() || !existing.isFile()) {
|
|
91
|
+
throw new Error('Refusing to overwrite symlink or non-regular plugin state file');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
const code = typeof err === 'object' && err !== null && 'code' in err ? String(err.code) : '';
|
|
96
|
+
if (code !== 'ENOENT')
|
|
97
|
+
throw err;
|
|
98
|
+
}
|
|
99
|
+
const temporary = `${sf}.tmp_${process.pid}_${crypto.randomBytes(6).toString('hex')}`;
|
|
100
|
+
const payload = Buffer.from(JSON.stringify(state, null, 2), 'utf8');
|
|
101
|
+
try {
|
|
102
|
+
const fd = fs.openSync(temporary, fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_WRONLY, 0o600);
|
|
103
|
+
try {
|
|
104
|
+
fs.writeSync(fd, payload, 0, payload.length);
|
|
105
|
+
fs.fsyncSync(fd);
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
fs.closeSync(fd);
|
|
109
|
+
}
|
|
110
|
+
fs.renameSync(temporary, sf);
|
|
111
|
+
if (process.platform !== 'win32') {
|
|
112
|
+
try {
|
|
113
|
+
fs.chmodSync(sf, 0o600);
|
|
114
|
+
}
|
|
115
|
+
catch { /* ignore */ }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
try {
|
|
120
|
+
if (fs.existsSync(temporary))
|
|
121
|
+
fs.unlinkSync(temporary);
|
|
122
|
+
}
|
|
123
|
+
catch { /* ignore */ }
|
|
124
|
+
throw err;
|
|
125
|
+
}
|
|
53
126
|
}
|
|
54
|
-
|
|
55
127
|
function resolveInside(root, relativePath) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
128
|
+
if (typeof relativePath !== 'string' || !relativePath || relativePath.includes('\0') || path.isAbsolute(relativePath)) {
|
|
129
|
+
throw new Error(`Invalid plugin relative path: ${String(relativePath)}`);
|
|
130
|
+
}
|
|
131
|
+
const resolvedRoot = path.resolve(root);
|
|
132
|
+
const resolved = path.resolve(root, relativePath);
|
|
133
|
+
if (resolved === resolvedRoot || !resolved.startsWith(resolvedRoot + path.sep)) {
|
|
134
|
+
throw new Error(`Path escapes plugin root: ${relativePath}`);
|
|
135
|
+
}
|
|
136
|
+
const realRoot = physicalPath(resolvedRoot);
|
|
137
|
+
const realTarget = physicalPath(resolved);
|
|
138
|
+
if (!realRoot || !realTarget || realTarget === realRoot || !isWithinPhysicalPath(realTarget, realRoot)) {
|
|
139
|
+
throw new Error(`Path escapes plugin root physically: ${relativePath}`);
|
|
140
|
+
}
|
|
141
|
+
return resolved;
|
|
62
142
|
}
|
|
63
|
-
|
|
64
143
|
function regularFile(file, maxBytes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
144
|
+
const stat = fs.lstatSync(file);
|
|
145
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
146
|
+
throw new Error(`${file} must be a regular file`);
|
|
147
|
+
if (stat.nlink > 1)
|
|
148
|
+
throw new Error(`${file} must not be a hardlink`);
|
|
149
|
+
if (stat.size > maxBytes)
|
|
150
|
+
throw new Error(`${file} exceeds ${Math.round(maxBytes / 1024)} KB`);
|
|
151
|
+
return stat;
|
|
69
152
|
}
|
|
70
|
-
|
|
153
|
+
const MAX_PLUGIN_DEPTH = 16;
|
|
71
154
|
function digestPluginDirectory(directory) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
155
|
+
const files = [];
|
|
156
|
+
let totalBytes = 0;
|
|
157
|
+
const visit = (current, depth) => {
|
|
158
|
+
if (depth > MAX_PLUGIN_DEPTH)
|
|
159
|
+
throw new Error(`Plugin directory nesting exceeds ${MAX_PLUGIN_DEPTH}`);
|
|
160
|
+
const entries = fs.readdirSync(current, { withFileTypes: true })
|
|
161
|
+
.sort((left, right) => left.name.localeCompare(right.name));
|
|
162
|
+
for (const entry of entries) {
|
|
163
|
+
const absolute = path.join(current, entry.name);
|
|
164
|
+
const stat = fs.lstatSync(absolute);
|
|
165
|
+
if (stat.isSymbolicLink())
|
|
166
|
+
throw new Error(`Plugin content must not be a symlink: ${entry.name}`);
|
|
167
|
+
if (stat.isDirectory()) {
|
|
168
|
+
visit(absolute, depth + 1);
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
if (!stat.isFile())
|
|
172
|
+
throw new Error(`Plugin content must be a regular file: ${entry.name}`);
|
|
173
|
+
if (stat.nlink > 1)
|
|
174
|
+
throw new Error(`Plugin content must not be a hardlink: ${entry.name}`);
|
|
175
|
+
totalBytes += stat.size;
|
|
176
|
+
if (totalBytes > MAX_PLUGIN_BYTES)
|
|
177
|
+
throw new Error('Plugin exceeds 2 MB');
|
|
178
|
+
files.push({ absolute, relative: path.relative(directory, absolute), size: stat.size });
|
|
179
|
+
if (files.length > MAX_PLUGIN_FILES)
|
|
180
|
+
throw new Error(`Plugin exceeds ${MAX_PLUGIN_FILES} files`);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
visit(directory, 0);
|
|
184
|
+
const digest = crypto.createHash('sha256');
|
|
185
|
+
for (const file of files) {
|
|
186
|
+
digest.update(file.relative);
|
|
187
|
+
digest.update('\0');
|
|
188
|
+
digest.update(fs.readFileSync(file.absolute));
|
|
189
|
+
digest.update('\0');
|
|
190
|
+
}
|
|
191
|
+
return digest.digest('hex');
|
|
101
192
|
}
|
|
102
|
-
|
|
103
193
|
function validateCapabilities(values, label) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
194
|
+
if (values == null)
|
|
195
|
+
return [];
|
|
196
|
+
if (!Array.isArray(values))
|
|
197
|
+
throw new Error(`${label} capabilities must be an array`);
|
|
198
|
+
const unique = [];
|
|
199
|
+
for (const value of values) {
|
|
200
|
+
if (typeof value !== 'string' || !CAPABILITIES.has(value)) {
|
|
201
|
+
throw new Error(`${label} requests unknown capability ${JSON.stringify(value)}`);
|
|
202
|
+
}
|
|
203
|
+
if (!unique.includes(value))
|
|
204
|
+
unique.push(value);
|
|
205
|
+
}
|
|
206
|
+
if (unique.includes('workspace:write') && !unique.includes('workspace:read'))
|
|
207
|
+
unique.unshift('workspace:read');
|
|
208
|
+
return unique;
|
|
113
209
|
}
|
|
114
|
-
|
|
115
210
|
function readPlugin(directory) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
211
|
+
const directoryStat = fs.lstatSync(directory);
|
|
212
|
+
if (!directoryStat.isDirectory() || directoryStat.isSymbolicLink()) {
|
|
213
|
+
throw new Error('Plugin directory must not be a symlink');
|
|
214
|
+
}
|
|
215
|
+
const manifestFile = path.join(directory, 'plugin.json');
|
|
216
|
+
regularFile(manifestFile, MAX_MANIFEST_BYTES);
|
|
217
|
+
const raw = fs.readFileSync(manifestFile, 'utf8');
|
|
218
|
+
const parsedManifest = JSON.parse(raw);
|
|
219
|
+
if (!parsedManifest || typeof parsedManifest !== 'object' || Array.isArray(parsedManifest)) {
|
|
220
|
+
throw new Error('Plugin manifest must be a JSON object');
|
|
221
|
+
}
|
|
222
|
+
const manifest = parsedManifest;
|
|
223
|
+
const folderName = path.basename(directory);
|
|
224
|
+
if (manifest.schemaVersion !== 1)
|
|
225
|
+
throw new Error('schemaVersion must be 1');
|
|
226
|
+
if (typeof manifest.name !== 'string' || !NAME.test(manifest.name) || manifest.name !== folderName) {
|
|
227
|
+
throw new Error('Plugin name must match its lowercase folder name');
|
|
228
|
+
}
|
|
229
|
+
if (typeof manifest.version !== 'string' || !VERSION.test(manifest.version)) {
|
|
230
|
+
throw new Error('Plugin version must use SemVer');
|
|
231
|
+
}
|
|
232
|
+
if (typeof manifest.description !== 'string' || !manifest.description.trim() || manifest.description.length > 2000) {
|
|
233
|
+
throw new Error('Plugin description is required (max 2000 chars)');
|
|
234
|
+
}
|
|
235
|
+
const manifestTools = manifest.tools ?? [];
|
|
236
|
+
if (!Array.isArray(manifestTools))
|
|
237
|
+
throw new Error('Plugin tools must be an array');
|
|
238
|
+
if (manifestTools.length > MAX_TOOLS_PER_PLUGIN) {
|
|
239
|
+
throw new Error(`Plugin exceeds ${MAX_TOOLS_PER_PLUGIN} tools`);
|
|
240
|
+
}
|
|
241
|
+
const pluginCapabilities = validateCapabilities(manifest.capabilities, manifest.name);
|
|
242
|
+
const names = new Set();
|
|
243
|
+
const tools = manifestTools.map((tool) => {
|
|
244
|
+
if (!tool || typeof tool !== 'object' || Array.isArray(tool)) {
|
|
245
|
+
throw new Error('Plugin tool entry must be an object');
|
|
246
|
+
}
|
|
247
|
+
if (typeof tool.name !== 'string' || !TOOL_NAME.test(tool.name)) {
|
|
248
|
+
throw new Error(`Invalid tool name ${JSON.stringify(tool.name)}`);
|
|
249
|
+
}
|
|
250
|
+
if (names.has(tool.name))
|
|
251
|
+
throw new Error(`Duplicate tool name ${tool.name}`);
|
|
252
|
+
names.add(tool.name);
|
|
253
|
+
if (typeof tool.description !== 'string' || !tool.description.trim()) {
|
|
254
|
+
throw new Error(`Tool ${tool.name} needs a description`);
|
|
255
|
+
}
|
|
256
|
+
if (!tool.parameters || typeof tool.parameters !== 'object' || Array.isArray(tool.parameters) || tool.parameters.type !== 'object') {
|
|
257
|
+
throw new Error(`Tool ${tool.name} parameters must be an object JSON schema`);
|
|
258
|
+
}
|
|
259
|
+
const entry = resolveInside(directory, tool.entry);
|
|
260
|
+
regularFile(entry, MAX_ENTRY_BYTES);
|
|
261
|
+
const exportName = tool.export === undefined ? 'execute' : tool.export;
|
|
262
|
+
if (typeof exportName !== 'string' || !EXPORT_IDENT.test(exportName) || FORBIDDEN_KEYS.has(exportName)) {
|
|
263
|
+
throw new Error(`Tool ${tool.name} has invalid export name ${JSON.stringify(exportName)}`);
|
|
264
|
+
}
|
|
265
|
+
const capabilities = validateCapabilities(tool.capabilities ?? pluginCapabilities, `${manifest.name}/${tool.name}`);
|
|
266
|
+
return {
|
|
267
|
+
localName: tool.name,
|
|
268
|
+
name: `plugin__${manifest.name.replace(/-/g, '_')}__${tool.name}`,
|
|
269
|
+
description: tool.description.trim().slice(0, 1000),
|
|
270
|
+
parameters: tool.parameters,
|
|
271
|
+
entry,
|
|
272
|
+
exportName,
|
|
273
|
+
capabilities,
|
|
274
|
+
timeoutMs: Number.isInteger(tool.timeoutMs)
|
|
275
|
+
? Math.max(1000, Math.min(tool.timeoutMs, 120_000))
|
|
276
|
+
: DEFAULT_TIMEOUT_MS
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
const skills = parsePluginSkills(directory, manifest.name, manifest.skills);
|
|
280
|
+
if (tools.length === 0 && skills.length === 0) {
|
|
281
|
+
throw new Error('Plugin must contribute at least one tool or skill');
|
|
282
|
+
}
|
|
156
283
|
return {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
: DEFAULT_TIMEOUT_MS
|
|
284
|
+
directory,
|
|
285
|
+
manifestFile,
|
|
286
|
+
// Pin every byte the plugin subprocess may read, not only the manifest.
|
|
287
|
+
// Otherwise an entry/helper could be replaced after review without
|
|
288
|
+
// changing plugin.json and would inherit stale trust.
|
|
289
|
+
digest: digestPluginDirectory(directory),
|
|
290
|
+
manifest: { ...manifest, capabilities: pluginCapabilities },
|
|
291
|
+
tools,
|
|
292
|
+
skills
|
|
167
293
|
};
|
|
168
|
-
});
|
|
169
|
-
const skills = parsePluginSkills(directory, manifest.name, manifest.skills);
|
|
170
|
-
if (tools.length === 0 && skills.length === 0) {
|
|
171
|
-
throw new Error('Plugin must contribute at least one tool or skill');
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
directory,
|
|
176
|
-
manifestFile,
|
|
177
|
-
// Pin every byte the plugin subprocess may read, not only the manifest.
|
|
178
|
-
// Otherwise an entry/helper could be replaced after review without
|
|
179
|
-
// changing plugin.json and would inherit stale trust.
|
|
180
|
-
digest: digestPluginDirectory(directory),
|
|
181
|
-
manifest: { ...manifest, capabilities: pluginCapabilities },
|
|
182
|
-
tools,
|
|
183
|
-
skills
|
|
184
|
-
};
|
|
185
294
|
}
|
|
186
|
-
|
|
187
295
|
function pluginDirectories() {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
296
|
+
try {
|
|
297
|
+
ensureRoot();
|
|
298
|
+
const root = pluginRoot();
|
|
299
|
+
return fs.readdirSync(root, { withFileTypes: true })
|
|
300
|
+
.filter((entry) => !entry.isSymbolicLink() && entry.isDirectory() && !entry.name.startsWith('.'))
|
|
301
|
+
.map((entry) => path.join(root, entry.name))
|
|
302
|
+
.sort();
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return [];
|
|
306
|
+
}
|
|
193
307
|
}
|
|
194
|
-
|
|
195
308
|
export function listPlugins() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
309
|
+
const state = readState();
|
|
310
|
+
const rows = [];
|
|
311
|
+
for (const directory of pluginDirectories()) {
|
|
312
|
+
try {
|
|
313
|
+
const plugin = readPlugin(directory);
|
|
314
|
+
const trust = Object.hasOwn(state.plugins, plugin.manifest.name) ? safeObject(state.plugins[plugin.manifest.name]) : {};
|
|
315
|
+
const modified = Boolean(trust.enabled && trust.digest !== plugin.digest);
|
|
316
|
+
rows.push({
|
|
317
|
+
name: plugin.manifest.name,
|
|
318
|
+
version: plugin.manifest.version,
|
|
319
|
+
description: plugin.manifest.description,
|
|
320
|
+
enabled: Boolean(trust.enabled && !modified),
|
|
321
|
+
modified,
|
|
322
|
+
digest: plugin.digest,
|
|
323
|
+
capabilities: plugin.manifest.capabilities,
|
|
324
|
+
tools: plugin.tools.map((tool) => tool.name),
|
|
325
|
+
skills: plugin.skills.map((skill) => `${skill.domain}/${skill.id}`),
|
|
326
|
+
path: plugin.directory
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
rows.push({
|
|
331
|
+
name: path.basename(directory),
|
|
332
|
+
enabled: false,
|
|
333
|
+
invalid: true,
|
|
334
|
+
error: error instanceof Error ? error.message : String(error),
|
|
335
|
+
path: directory
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
return rows;
|
|
220
340
|
}
|
|
221
|
-
|
|
222
341
|
export function enablePlugin(name) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
342
|
+
if (typeof name !== 'string' || !NAME.test(name))
|
|
343
|
+
return { ok: false, error: 'Invalid plugin name' };
|
|
344
|
+
try {
|
|
345
|
+
const plugin = readPlugin(resolveInside(pluginRoot(), name));
|
|
346
|
+
const state = readState();
|
|
347
|
+
state.plugins[name] = { enabled: true, digest: plugin.digest, enabledAt: Date.now() };
|
|
348
|
+
writeState(state);
|
|
349
|
+
return {
|
|
350
|
+
ok: true,
|
|
351
|
+
name,
|
|
352
|
+
digest: plugin.digest,
|
|
353
|
+
capabilities: plugin.manifest.capabilities,
|
|
354
|
+
tools: plugin.tools.map((tool) => tool.name),
|
|
355
|
+
skills: plugin.skills.map((skill) => `${skill.domain}/${skill.id}`)
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
catch (error) {
|
|
359
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
360
|
+
}
|
|
240
361
|
}
|
|
241
|
-
|
|
242
362
|
export function disablePlugin(name) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
363
|
+
if (typeof name !== 'string' || !NAME.test(name) || FORBIDDEN_KEYS.has(name)) {
|
|
364
|
+
return { ok: false, error: 'Invalid plugin name' };
|
|
365
|
+
}
|
|
366
|
+
const state = readState();
|
|
367
|
+
const current = Object.hasOwn(state.plugins, name) ? safeObject(state.plugins[name]) : {};
|
|
368
|
+
state.plugins[name] = { ...current, enabled: false, disabledAt: Date.now() };
|
|
369
|
+
writeState(state);
|
|
370
|
+
return { ok: true, name };
|
|
248
371
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
return {
|
|
296
|
-
ok: true,
|
|
297
|
-
name,
|
|
298
|
-
path: directory,
|
|
299
|
-
enabled: false,
|
|
300
|
-
message: 'Plugin created disabled. Review its manifest and source, then enable it explicitly.'
|
|
372
|
+
export function createPlugin(input) {
|
|
373
|
+
const safeInput = input && typeof input === 'object' ? input : {};
|
|
374
|
+
const { name, description, toolName, toolDescription, parameters, code, capabilities = [] } = safeInput;
|
|
375
|
+
if (typeof name !== 'string' || !NAME.test(name) || FORBIDDEN_KEYS.has(name)) {
|
|
376
|
+
return { ok: false, error: 'Plugin name must use lowercase letters, digits, and hyphens' };
|
|
377
|
+
}
|
|
378
|
+
if (typeof toolName !== 'string' || !TOOL_NAME.test(toolName)) {
|
|
379
|
+
return { ok: false, error: 'Tool name must start with a lowercase letter and use letters, digits, _ or -' };
|
|
380
|
+
}
|
|
381
|
+
if (typeof description !== 'string' || !description.trim() || description.length > 2000) {
|
|
382
|
+
return { ok: false, error: 'Plugin description is required (max 2000 chars)' };
|
|
383
|
+
}
|
|
384
|
+
if (typeof toolDescription !== 'string' || !toolDescription.trim() || toolDescription.length > 1000) {
|
|
385
|
+
return { ok: false, error: 'Tool description is required (max 1000 chars)' };
|
|
386
|
+
}
|
|
387
|
+
if (!parameters || typeof parameters !== 'object' || Array.isArray(parameters) || parameters.type !== 'object') {
|
|
388
|
+
return { ok: false, error: 'Tool parameters must be an object JSON schema' };
|
|
389
|
+
}
|
|
390
|
+
if (typeof code !== 'string' || !code.trim() || Buffer.byteLength(code, 'utf8') > MAX_ENTRY_BYTES) {
|
|
391
|
+
return { ok: false, error: 'Plugin code is required and must be at most 512 KB' };
|
|
392
|
+
}
|
|
393
|
+
let safeCapabilities;
|
|
394
|
+
try {
|
|
395
|
+
safeCapabilities = validateCapabilities(capabilities, name);
|
|
396
|
+
}
|
|
397
|
+
catch (error) {
|
|
398
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
399
|
+
}
|
|
400
|
+
ensureRoot();
|
|
401
|
+
const directory = path.join(pluginRoot(), name);
|
|
402
|
+
if (fs.existsSync(directory))
|
|
403
|
+
return { ok: false, error: `Plugin ${name} already exists` };
|
|
404
|
+
const entryName = `${toolName}.js`;
|
|
405
|
+
const manifest = {
|
|
406
|
+
schemaVersion: 1,
|
|
407
|
+
name,
|
|
408
|
+
version: '0.1.0',
|
|
409
|
+
description: description.trim(),
|
|
410
|
+
capabilities: safeCapabilities,
|
|
411
|
+
tools: [{
|
|
412
|
+
name: toolName,
|
|
413
|
+
description: toolDescription.trim(),
|
|
414
|
+
parameters,
|
|
415
|
+
entry: entryName,
|
|
416
|
+
export: 'execute'
|
|
417
|
+
}]
|
|
301
418
|
};
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
419
|
+
const trimmedCode = code.trim();
|
|
420
|
+
const source = trimmedCode.startsWith('export ')
|
|
421
|
+
? trimmedCode
|
|
422
|
+
: trimmedCode.startsWith('async ') || trimmedCode.startsWith('(async ')
|
|
423
|
+
? `export const execute = ${trimmedCode};\n`
|
|
424
|
+
: `export async function execute(args, context) {\n${trimmedCode}\n}\n`;
|
|
425
|
+
let created = false;
|
|
426
|
+
try {
|
|
427
|
+
fs.mkdirSync(directory, { recursive: false, mode: 0o700 });
|
|
428
|
+
created = true;
|
|
429
|
+
fs.writeFileSync(path.join(directory, 'plugin.json'), `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600, flag: 'wx' });
|
|
430
|
+
fs.writeFileSync(path.join(directory, entryName), source, { mode: 0o600, flag: 'wx' });
|
|
431
|
+
readPlugin(directory);
|
|
432
|
+
return {
|
|
433
|
+
ok: true,
|
|
434
|
+
name,
|
|
435
|
+
path: directory,
|
|
436
|
+
enabled: false,
|
|
437
|
+
message: 'Plugin created disabled. Review its manifest and source, then enable it explicitly.'
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
catch (error) {
|
|
441
|
+
if (created) {
|
|
442
|
+
try {
|
|
443
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
444
|
+
}
|
|
445
|
+
catch { /* ignore */ }
|
|
446
|
+
}
|
|
447
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
448
|
+
}
|
|
305
449
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}]
|
|
347
|
-
};
|
|
348
|
-
ensureRoot();
|
|
349
|
-
const directory = path.join(PLUGIN_ROOT, name);
|
|
350
|
-
if (fs.existsSync(directory)) return { ok: false, error: 'Plugin already exists' };
|
|
351
|
-
let created = false;
|
|
352
|
-
try {
|
|
353
|
-
fs.mkdirSync(directory, { mode: 0o700 });
|
|
354
|
-
created = true;
|
|
355
|
-
fs.writeFileSync(path.join(directory, 'SKILL.md'), skillContent, {
|
|
356
|
-
mode: 0o600, flag: 'wx'
|
|
357
|
-
});
|
|
358
|
-
fs.writeFileSync(path.join(directory, 'LICENSE'), licenseText, {
|
|
359
|
-
mode: 0o600, flag: 'wx'
|
|
360
|
-
});
|
|
361
|
-
fs.writeFileSync(path.join(directory, 'plugin.json'),
|
|
362
|
-
JSON.stringify(manifest, null, 2) + '\n', {
|
|
363
|
-
mode: 0o600, flag: 'wx'
|
|
364
|
-
});
|
|
365
|
-
const reviewed = readPlugin(directory);
|
|
366
|
-
return {
|
|
367
|
-
ok: true, name, enabled: false, tools: [],
|
|
368
|
-
skills: reviewed.skills.map(entry => entry.domain + '/' + entry.id),
|
|
369
|
-
license: isMit ? 'MIT' : 'Apache-2.0',
|
|
370
|
-
digest: reviewed.digest, path: directory,
|
|
371
|
-
message: 'Skill packaged disabled. Review its instructions and license before explicit enablement.'
|
|
450
|
+
export function createSkillPlugin(input) {
|
|
451
|
+
const safeInput = input && typeof input === 'object' ? input : {};
|
|
452
|
+
const { name, description, skillId, skillName, skillDescription, skillContent, licenseText } = safeInput;
|
|
453
|
+
if (typeof name !== 'string' || !NAME.test(name) || FORBIDDEN_KEYS.has(name)) {
|
|
454
|
+
return { ok: false, error: 'Invalid plugin name' };
|
|
455
|
+
}
|
|
456
|
+
if (typeof skillId !== 'string' || !NAME.test(skillId))
|
|
457
|
+
return { ok: false, error: 'Invalid skill id' };
|
|
458
|
+
if (typeof description !== 'string' || !description.trim() || description.length > 1000) {
|
|
459
|
+
return { ok: false, error: 'Plugin description must be 1..1000 characters' };
|
|
460
|
+
}
|
|
461
|
+
if (typeof skillName !== 'string' || !skillName.trim() || skillName.length > 120) {
|
|
462
|
+
return { ok: false, error: 'Skill name must be 1..120 characters' };
|
|
463
|
+
}
|
|
464
|
+
if (typeof skillDescription !== 'string' || !skillDescription.trim()
|
|
465
|
+
|| skillDescription.length > 400) {
|
|
466
|
+
return { ok: false, error: 'Skill description must be 1..400 characters' };
|
|
467
|
+
}
|
|
468
|
+
if (typeof skillContent !== 'string' || !skillContent.trim() || skillContent.includes('\0')
|
|
469
|
+
|| Buffer.byteLength(skillContent, 'utf8') > 32 * 1024) {
|
|
470
|
+
return { ok: false, error: 'Skill content must be nonempty and at most 32 KB' };
|
|
471
|
+
}
|
|
472
|
+
if (typeof licenseText !== 'string' || licenseText.includes('\0') || licenseText.length > 32 * 1024) {
|
|
473
|
+
return { ok: false, error: 'Full third-party license text is required' };
|
|
474
|
+
}
|
|
475
|
+
const isMit = /^MIT License\s*$/mi.test(licenseText)
|
|
476
|
+
&& /Permission is hereby granted, free of charge/i.test(licenseText)
|
|
477
|
+
&& /above copyright notice/i.test(licenseText);
|
|
478
|
+
const isApache = /Apache License\s*Version 2\.0/i.test(licenseText)
|
|
479
|
+
&& /TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION/i.test(licenseText);
|
|
480
|
+
if (!isMit && !isApache) {
|
|
481
|
+
return { ok: false, error: 'Only reviewed MIT or Apache-2.0 license text is accepted' };
|
|
482
|
+
}
|
|
483
|
+
const manifest = {
|
|
484
|
+
schemaVersion: 1, name, version: '0.1.0', description: description.trim(),
|
|
485
|
+
capabilities: [], tools: [],
|
|
486
|
+
skills: [{
|
|
487
|
+
id: skillId, name: skillName.trim(),
|
|
488
|
+
description: skillDescription.trim(), file: 'SKILL.md'
|
|
489
|
+
}]
|
|
372
490
|
};
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
491
|
+
ensureRoot();
|
|
492
|
+
const directory = path.join(pluginRoot(), name);
|
|
493
|
+
if (fs.existsSync(directory))
|
|
494
|
+
return { ok: false, error: 'Plugin already exists' };
|
|
495
|
+
let created = false;
|
|
496
|
+
try {
|
|
497
|
+
fs.mkdirSync(directory, { mode: 0o700 });
|
|
498
|
+
created = true;
|
|
499
|
+
fs.writeFileSync(path.join(directory, 'SKILL.md'), skillContent, {
|
|
500
|
+
mode: 0o600, flag: 'wx'
|
|
501
|
+
});
|
|
502
|
+
fs.writeFileSync(path.join(directory, 'LICENSE'), licenseText, {
|
|
503
|
+
mode: 0o600, flag: 'wx'
|
|
504
|
+
});
|
|
505
|
+
fs.writeFileSync(path.join(directory, 'plugin.json'), JSON.stringify(manifest, null, 2) + '\n', {
|
|
506
|
+
mode: 0o600, flag: 'wx'
|
|
507
|
+
});
|
|
508
|
+
const reviewed = readPlugin(directory);
|
|
509
|
+
return {
|
|
510
|
+
ok: true, name, enabled: false, tools: [],
|
|
511
|
+
skills: reviewed.skills.map(entry => entry.domain + '/' + entry.id),
|
|
512
|
+
license: isMit ? 'MIT' : 'Apache-2.0',
|
|
513
|
+
digest: reviewed.digest, path: directory,
|
|
514
|
+
message: 'Skill packaged disabled. Review its instructions and license before explicit enablement.'
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
if (created) {
|
|
519
|
+
try {
|
|
520
|
+
fs.rmSync(directory, { recursive: true, force: true });
|
|
521
|
+
}
|
|
522
|
+
catch { /* ignore */ }
|
|
523
|
+
}
|
|
524
|
+
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
376
525
|
}
|
|
377
|
-
return { ok: false, error: error instanceof Error ? error.message : String(error) };
|
|
378
|
-
}
|
|
379
526
|
}
|
|
380
|
-
|
|
381
527
|
function enabledTools() {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
528
|
+
const state = readState();
|
|
529
|
+
const tools = [];
|
|
530
|
+
for (const directory of pluginDirectories()) {
|
|
531
|
+
try {
|
|
532
|
+
const plugin = readPlugin(directory);
|
|
533
|
+
const trust = Object.hasOwn(state.plugins, plugin.manifest.name) ? safeObject(state.plugins[plugin.manifest.name]) : {};
|
|
534
|
+
if (!trust.enabled || trust.digest !== plugin.digest)
|
|
535
|
+
continue;
|
|
536
|
+
for (const tool of plugin.tools)
|
|
537
|
+
tools.push({ ...tool, plugin: plugin.manifest.name, pluginDirectory: directory });
|
|
538
|
+
}
|
|
539
|
+
catch {
|
|
540
|
+
// Invalid plugins are visible through listPlugins(), never through the model.
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return tools;
|
|
395
544
|
}
|
|
396
|
-
|
|
397
545
|
export function getPluginToolDefinitions() {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
546
|
+
return enabledTools().map((tool) => ({
|
|
547
|
+
name: tool.name,
|
|
548
|
+
description: tool.description,
|
|
549
|
+
parameters: tool.parameters,
|
|
550
|
+
xCausyneDeferred: true
|
|
551
|
+
}));
|
|
404
552
|
}
|
|
405
|
-
|
|
406
553
|
/**
|
|
407
554
|
* Reviewed, enabled plugins may contribute prompt-only skills. Discovery has
|
|
408
555
|
* already parsed these as inert UTF-8 data; no plugin module is imported.
|
|
409
556
|
*/
|
|
410
557
|
export function getPluginSkills() {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
558
|
+
const state = readState();
|
|
559
|
+
const skills = [];
|
|
560
|
+
for (const directory of pluginDirectories()) {
|
|
561
|
+
try {
|
|
562
|
+
const plugin = readPlugin(directory);
|
|
563
|
+
const trust = Object.hasOwn(state.plugins, plugin.manifest.name) ? safeObject(state.plugins[plugin.manifest.name]) : {};
|
|
564
|
+
if (!trust.enabled || trust.digest !== plugin.digest)
|
|
565
|
+
continue;
|
|
566
|
+
skills.push(...plugin.skills);
|
|
567
|
+
}
|
|
568
|
+
catch {
|
|
569
|
+
// Invalid or modified plugins contribute nothing to the prompt.
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return skills;
|
|
424
573
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
574
|
+
function permissionArgs(tool, workspaceRoots) {
|
|
575
|
+
// Node resolves `.js` module type by walking to package.json. Grant that one
|
|
576
|
+
// metadata file explicitly; granting the repository root would let an
|
|
577
|
+
// extension read Causyne's entire source tree for no functional reason.
|
|
578
|
+
const readable = [path.dirname(RUNNER_FILE), PACKAGE_FILE, tool.pluginDirectory];
|
|
579
|
+
const writable = [];
|
|
580
|
+
if (tool.capabilities.includes('workspace:read') || tool.capabilities.includes('workspace:write')) {
|
|
581
|
+
for (const root of workspaceRoots) {
|
|
582
|
+
if (!readable.includes(root))
|
|
583
|
+
readable.push(root);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (tool.capabilities.includes('workspace:write')) {
|
|
587
|
+
for (const root of workspaceRoots) {
|
|
588
|
+
if (!writable.includes(root))
|
|
589
|
+
writable.push(root);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
// Repeat the flag. Comma-joining paths is parsed as one literal path by
|
|
593
|
+
// Node's permission model on current releases.
|
|
594
|
+
const args = ['--permission', ...readable.map((entry) => `--allow-fs-read=${entry}`)];
|
|
595
|
+
if (writable.length > 0) {
|
|
596
|
+
args.push(...writable.map((entry) => `--allow-fs-write=${entry}`));
|
|
597
|
+
}
|
|
598
|
+
if (tool.capabilities.includes('network'))
|
|
599
|
+
args.push('--allow-net');
|
|
600
|
+
if (tool.capabilities.includes('subprocess'))
|
|
601
|
+
args.push('--allow-child-process');
|
|
602
|
+
return args;
|
|
446
603
|
}
|
|
447
|
-
|
|
448
604
|
async function runPluginTool(tool, args, context) {
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
let settled = false;
|
|
486
|
-
const finish = (value) => {
|
|
487
|
-
if (settled) return;
|
|
488
|
-
settled = true;
|
|
489
|
-
clearTimeout(timer);
|
|
490
|
-
resolve(value);
|
|
605
|
+
// Re-verify trust and whole-directory digest immediately before spawning to
|
|
606
|
+
// close TOCTOU tampering between tool resolution and execution.
|
|
607
|
+
try {
|
|
608
|
+
const state = readState();
|
|
609
|
+
const trust = Object.hasOwn(state.plugins, tool.plugin) ? safeObject(state.plugins[tool.plugin]) : {};
|
|
610
|
+
const fresh = readPlugin(tool.pluginDirectory);
|
|
611
|
+
if (!trust.enabled || trust.digest !== fresh.digest) {
|
|
612
|
+
return { success: false, error: 'Plugin trust revoked or modified before execution' };
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
catch (verifyErr) {
|
|
616
|
+
return {
|
|
617
|
+
success: false,
|
|
618
|
+
error: `Plugin integrity check failed: ${verifyErr instanceof Error ? verifyErr.message : String(verifyErr)}`
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
const rawWorkspace = context?.workspaceRoot || context?.workspacePaths?.[0] || process.cwd();
|
|
622
|
+
if (typeof rawWorkspace !== 'string' || !rawWorkspace.trim() || rawWorkspace.includes('\0')) {
|
|
623
|
+
return { success: false, error: 'Invalid workspace root for plugin execution' };
|
|
624
|
+
}
|
|
625
|
+
const workspaceRoot = path.resolve(rawWorkspace);
|
|
626
|
+
if (isBlockedWorkspaceRoot(workspaceRoot)) {
|
|
627
|
+
return { success: false, error: 'Refusing plugin execution on a blocked system root' };
|
|
628
|
+
}
|
|
629
|
+
const realWorkspaceRoot = physicalPath(workspaceRoot) || workspaceRoot;
|
|
630
|
+
const workspacePermissionRoots = realWorkspaceRoot === workspaceRoot
|
|
631
|
+
? [workspaceRoot]
|
|
632
|
+
: [workspaceRoot, realWorkspaceRoot];
|
|
633
|
+
// Resolve filesystem aliases before handing paths to Node's permission
|
|
634
|
+
// model. On macOS, /var and /tmp are symlinks into /private; authorizing the
|
|
635
|
+
// alias while the module loader opens the canonical target causes a false
|
|
636
|
+
// denial even though both names identify the same reviewed plugin file.
|
|
637
|
+
const runtimeTool = {
|
|
638
|
+
...tool,
|
|
639
|
+
entry: fs.realpathSync(tool.entry),
|
|
640
|
+
pluginDirectory: fs.realpathSync(tool.pluginDirectory)
|
|
491
641
|
};
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
642
|
+
if (runtimeTool.entry === runtimeTool.pluginDirectory || !isWithinPhysicalPath(runtimeTool.entry, runtimeTool.pluginDirectory)) {
|
|
643
|
+
return { success: false, error: 'Refusing plugin entry outside its canonical plugin directory' };
|
|
644
|
+
}
|
|
645
|
+
const childArgs = [
|
|
646
|
+
...permissionArgs(runtimeTool, workspacePermissionRoots),
|
|
647
|
+
RUNNER_FILE,
|
|
648
|
+
runtimeTool.entry,
|
|
649
|
+
runtimeTool.exportName
|
|
650
|
+
];
|
|
651
|
+
const payload = JSON.stringify({
|
|
652
|
+
args: safeObject(args),
|
|
653
|
+
context: {
|
|
654
|
+
workspaceRoot,
|
|
655
|
+
pluginRoot: runtimeTool.pluginDirectory,
|
|
656
|
+
capabilities: runtimeTool.capabilities
|
|
657
|
+
}
|
|
507
658
|
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
659
|
+
const runToken = crypto.randomBytes(16).toString('hex');
|
|
660
|
+
const resultMarker = `CAUSYNE_PLUGIN_RESULT:${runToken}:`;
|
|
661
|
+
return new Promise((resolve) => {
|
|
662
|
+
const childEnv = {
|
|
663
|
+
PATH: process.env.PATH || process.env.Path || '',
|
|
664
|
+
LANG: process.env.LANG || 'C.UTF-8',
|
|
665
|
+
TMPDIR: process.env.TMPDIR || '',
|
|
666
|
+
CAUSYNE_PLUGIN_TOKEN: runToken
|
|
667
|
+
};
|
|
668
|
+
if (process.platform === 'win32') {
|
|
669
|
+
if (process.env.SystemRoot)
|
|
670
|
+
childEnv.SystemRoot = process.env.SystemRoot;
|
|
671
|
+
if (process.env.TEMP)
|
|
672
|
+
childEnv.TEMP = process.env.TEMP;
|
|
673
|
+
if (process.env.TMP)
|
|
674
|
+
childEnv.TMP = process.env.TMP;
|
|
675
|
+
if (process.env.PATHEXT)
|
|
676
|
+
childEnv.PATHEXT = process.env.PATHEXT;
|
|
677
|
+
}
|
|
678
|
+
const child = spawn(process.execPath, childArgs, {
|
|
679
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
680
|
+
windowsHide: true,
|
|
681
|
+
env: childEnv
|
|
682
|
+
});
|
|
683
|
+
let stdout = '';
|
|
684
|
+
let stderr = '';
|
|
685
|
+
let settled = false;
|
|
686
|
+
const finish = (value) => {
|
|
687
|
+
if (settled)
|
|
688
|
+
return;
|
|
689
|
+
settled = true;
|
|
690
|
+
clearTimeout(timer);
|
|
691
|
+
resolve(value);
|
|
692
|
+
};
|
|
693
|
+
const terminateChild = () => {
|
|
694
|
+
try {
|
|
695
|
+
child.kill('SIGTERM');
|
|
696
|
+
}
|
|
697
|
+
catch { /* ignore */ }
|
|
698
|
+
const killTimer = setTimeout(() => {
|
|
699
|
+
try {
|
|
700
|
+
child.kill('SIGKILL');
|
|
701
|
+
}
|
|
702
|
+
catch { /* ignore */ }
|
|
703
|
+
}, 1500);
|
|
704
|
+
killTimer.unref?.();
|
|
705
|
+
};
|
|
706
|
+
const timer = setTimeout(() => {
|
|
707
|
+
terminateChild();
|
|
708
|
+
finish({ success: false, error: `Plugin timed out after ${runtimeTool.timeoutMs} ms` });
|
|
709
|
+
}, runtimeTool.timeoutMs);
|
|
710
|
+
if (timer.unref)
|
|
711
|
+
timer.unref();
|
|
712
|
+
child.stdout.on('data', (chunk) => {
|
|
713
|
+
stdout += String(chunk);
|
|
714
|
+
if (Buffer.byteLength(stdout, 'utf8') > MAX_RESULT_BYTES) {
|
|
715
|
+
terminateChild();
|
|
716
|
+
finish({ success: false, error: 'Plugin result exceeded 1 MB' });
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
child.stderr.on('data', (chunk) => {
|
|
720
|
+
stderr = (stderr + String(chunk)).slice(-16_000);
|
|
721
|
+
});
|
|
722
|
+
child.on('error', (error) => finish({
|
|
723
|
+
success: false,
|
|
724
|
+
error: safeDisplay(redactProviderSecrets(error.message))
|
|
725
|
+
}));
|
|
726
|
+
child.on('close', () => {
|
|
727
|
+
const lines = stdout.split(/\r?\n/);
|
|
728
|
+
let line;
|
|
729
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
730
|
+
if (lines[i]?.startsWith(resultMarker)) {
|
|
731
|
+
line = lines[i];
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (!line) {
|
|
736
|
+
const cleanErr = safeDisplay(redactProviderSecrets(stderr.trim()));
|
|
737
|
+
finish({ success: false, error: cleanErr || 'Plugin returned no structured result' });
|
|
738
|
+
return;
|
|
739
|
+
}
|
|
740
|
+
try {
|
|
741
|
+
finish(JSON.parse(line.slice(resultMarker.length)));
|
|
742
|
+
}
|
|
743
|
+
catch (error) {
|
|
744
|
+
finish({ success: false, error: `Plugin returned invalid JSON: ${error instanceof Error ? error.message : String(error)}` });
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
child.stdin.on('error', () => { });
|
|
748
|
+
child.stdin.end(payload);
|
|
520
749
|
});
|
|
521
|
-
child.stdin.end(payload);
|
|
522
|
-
});
|
|
523
750
|
}
|
|
524
|
-
|
|
525
751
|
export function resolvePluginTool(name) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
752
|
+
if (typeof name !== 'string' || !name || name.length > 160 || /[\r\n\0]/.test(name))
|
|
753
|
+
return null;
|
|
754
|
+
const tool = enabledTools().find((candidate) => candidate.name === name);
|
|
755
|
+
if (!tool)
|
|
756
|
+
return null;
|
|
757
|
+
return {
|
|
758
|
+
schema: { name: tool.name, description: tool.description, parameters: tool.parameters },
|
|
759
|
+
execute: (args, context = {}) => runPluginTool(tool, args, context)
|
|
760
|
+
};
|
|
532
761
|
}
|
|
533
|
-
|
|
534
762
|
export { PLUGIN_ROOT, STATE_FILE, CAPABILITIES };
|