Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.
TypeScript browser-shellcontrol-planefile-managerhomelabmobile-firstnextjsptyreactself-hostedserver-managementshadcn-uisysadmintailwindcssterminaltypescriptvpsweb-desktopweb-terminal
feat(infra): ensure Dokploy GitHub applications
Rahman122cebcb2769
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.mdindex 0b8ff7a3..7c399cb6 100644--- a/docs/CHANGELOG.md+++ b/docs/CHANGELOG.md@@ -4,6 +4,12 @@Newest first. `docs/PROGRESS.md` is the source of truth for *why* a change was made;this is the *what*, and it is what Settings → About shows as “What's new”.+## 2026-09-07++**Added**++- `infra` ensure Dokploy GitHub applications+## 2026-09-06**Added**diff --git a/lib/infra/clients.ts b/lib/infra/clients.tsindex 7374bf8e..c5b68dce 100644--- a/lib/infra/clients.ts+++ b/lib/infra/clients.ts@@ -9,7 +9,7 @@ import { doctorHostinger } from "./hostinger";import { doctorComposio } from "./composio";export { listCloudflareZones, upsertCloudflareDns } from "./cloudflare";-export { ensureDokployProject, listDokployProjects, listDokployApplications, listDokployDeployments, readDokployDeploymentLogs, inspectDokployApplication, listDokployGitProviders, inspectDokployGithubProvider, testDokployGithubProvider, recoverDokployPublicGithubToHttpsGit, deployDokployApplication, upsertDokployPublicBuildEnv } from "./dokploy";+export { ensureDokployProject, listDokployProjects, listDokployApplications, listDokployDeployments, readDokployDeploymentLogs, inspectDokployApplication, listDokployGitProviders, listDokployGithubRepositories, inspectDokployGithubProvider, testDokployGithubProvider, ensureDokployGithubApplication, ensureDokployApplicationDomain, recoverDokployPublicGithubToHttpsGit, deployDokployApplication, upsertDokployPublicBuildEnv } from "./dokploy";export { upsertHostingerDns } from "./hostinger";export { listHostingerMailOrders, getHostingerMailPlan, listHostingerMail, listHostingerMailLogs, mutateHostingerMail } from "./hostinger-mail";diff --git a/lib/infra/connection-dispatch.ts b/lib/infra/connection-dispatch.tsindex cd383db5..e29b4683 100644--- a/lib/infra/connection-dispatch.ts+++ b/lib/infra/connection-dispatch.ts@@ -4,7 +4,7 @@ import { authorizeIntegration, composioConnectionCall } from "./connection-exterimport { IntegrationError, identity, metadataOnly, type ConnectionSelector } from "./identity";import { importConvexCliPersonalConnection } from "./convex-cli-import";import { listConvexCustomDomains, ensureConvexCustomDomain, getConvexCanonicalUrls, setConvexCanonicalUrl, getConvexEnvPresence } from "./convex-cloud";-import { doctorInfraProvider, ensureDokployProject, listDokployApplications, listDokployDeployments, readDokployDeploymentLogs, recoverDokployPublicGithubToHttpsGit, deployDokployApplication, listDokployProjects, listCloudflareZones, upsertCloudflareDns, upsertDokployPublicBuildEnv, upsertHostingerDns, listHostingerMailOrders, getHostingerMailPlan, listHostingerMail, listHostingerMailLogs, mutateHostingerMail } from "./clients";+import { doctorInfraProvider, ensureDokployProject, listDokployApplications, listDokployDeployments, readDokployDeploymentLogs, listDokployGitProviders, listDokployGithubRepositories, ensureDokployGithubApplication, ensureDokployApplicationDomain, recoverDokployPublicGithubToHttpsGit, deployDokployApplication, listDokployProjects, listCloudflareZones, upsertCloudflareDns, upsertDokployPublicBuildEnv, upsertHostingerDns, listHostingerMailOrders, getHostingerMailPlan, listHostingerMail, listHostingerMailLogs, mutateHostingerMail } from "./clients";import { isInfraProviderId } from "./catalog";export const safeActionInput=(input:Record<string,unknown>)=>Object.fromEntries(Object.entries(input).filter(([key])=>key!=="workflow_id"));export const selectionFrom=(a:Record<string,unknown>):ConnectionSelector=>({user:typeof a.user==="string"?a.user:undefined,connection:typeof a.connection==="string"?a.connection:undefined,cwd:typeof a.cwd==="string"?a.cwd:undefined});@@ -39,6 +39,10 @@ export async function executeIntegrationAction(raw:Record<string,unknown>){const verbs:Record<string,{provider:string;fields:string[];run:()=>Promise<unknown>}>= {"dokploy.projects.list":{provider:"dokploy",fields:[],run:()=>listDokployProjects()},"dokploy.applications.list":{provider:"dokploy",fields:["projectId"],run:()=>listDokployApplications(String((args as Record<string,unknown>).projectId))},+ "dokploy.gitProviders.list":{provider:"dokploy",fields:[],run:()=>listDokployGitProviders()},+ "dokploy.github.repositories.list":{provider:"dokploy",fields:["githubId"],run:()=>listDokployGithubRepositories(String((args as Record<string,unknown>).githubId))},+ "dokploy.application.ensureGithub":{provider:"dokploy",fields:["projectId","name","githubId","owner","repository","branch","buildPath"],run:()=>ensureDokployGithubApplication(args as {projectId:string;name:string;githubId:string;owner:string;repository:string;branch:string;buildPath?:string})},+ "dokploy.domain.ensure":{provider:"dokploy",fields:["applicationId","host","port","https"],run:()=>ensureDokployApplicationDomain(args as {applicationId:string;host:string;port:number;https:boolean})},"dokploy.deployments.list":{provider:"dokploy",fields:["applicationId"],run:()=>listDokployDeployments(String((args as Record<string,unknown>).applicationId))},"dokploy.deployment.logs":{provider:"dokploy",fields:["deploymentId","tail"],run:()=>readDokployDeploymentLogs(String((args as Record<string,unknown>).deploymentId),Number((args as Record<string,unknown>).tail??160))},"dokploy.git.recover":{provider:"dokploy",fields:["applicationId"],run:()=>recoverDokployPublicGithubToHttpsGit(String((args as Record<string,unknown>).applicationId))},diff --git a/lib/infra/dokploy-application-ensure.test.ts b/lib/infra/dokploy-application-ensure.test.tsnew file mode 100644index 00000000..60c90529--- /dev/null+++ b/lib/infra/dokploy-application-ensure.test.ts@@ -0,0 +1,49 @@+import { afterEach, beforeEach, expect, it, vi } from "vitest";+import { promises as fs } from "node:fs";+import os from "node:os";+import path from "node:path";++let root:string;+const KEY="synthetic_dokploy_key_123456789";+beforeEach(async()=>{root=await fs.mkdtemp(path.join(os.tmpdir(),"mso-dokploy-app-"));process.env.OS_INFRA_STORE=path.join(root,"infra.json");vi.resetModules();});+afterEach(async()=>{delete process.env.OS_INFRA_STORE;vi.unstubAllGlobals();await fs.rm(root,{recursive:true,force:true});vi.resetModules();});+async function seeded(){+ const {integrationManage}=await import("./connection-manage");+ await integrationManage({action:"user.create",user:"alice",confirm:true});+ await integrationManage({action:"connection.create",user:"alice",provider:"dokploy",connection:"work",authMethod:"direct",source:"direct",confirm:true});+ const {withIntegrationSelection}=await import("./connection-service"),{setInfraProvider}=await import("./store");+ await withIntegrationSelection({user:"alice",connection:"work"},()=>setInfraProvider("dokploy",{apiUrl:"http://127.0.0.1:4123/api",apiKey:KEY}));+ return withIntegrationSelection;+}++it("idempotently creates a private GitHub-backed application through an accessible Dokploy provider",async()=>{+ const withSelection=await seeded();let created=false,sourceSaved=false;+ vi.stubGlobal("fetch",vi.fn(async(input:RequestInfo|URL,init?:RequestInit)=>{+ const req=new Request(input,init),url=new URL(req.url);+ if(url.pathname.endsWith("/github.one"))return new Response(JSON.stringify({githubId:"github_123",name:"Work"}),{status:200});+ if(url.pathname.endsWith("/github.getGithubRepositories"))return new Response(JSON.stringify([{name:"baton",owner:{login:"rahmanef63"}}]),{status:200});+ if(url.pathname.endsWith("/environment.byProjectId"))return new Response(JSON.stringify([{environmentId:"environment_123",name:"Production",isDefault:true,applications:created?[{applicationId:"application_123",name:"baton",appName:"baton",applicationStatus:"idle"}]:[]}]),{status:200});+ if(url.pathname.endsWith("/application.create")){expect(JSON.parse(await req.text())).toEqual({name:"baton",environmentId:"environment_123",sourceType:"github"});created=true;return new Response("{}",{status:200});}+ if(url.pathname.endsWith("/application.saveGithubProvider")){expect(JSON.parse(await req.text())).toEqual({applicationId:"application_123",repository:"baton",owner:"rahmanef63",buildPath:"/",githubId:"github_123",branch:"main",triggerType:"push",enableSubmodules:false,watchPaths:[]});sourceSaved=true;return new Response("{}",{status:200});}+ if(url.pathname.endsWith("/application.one"))return new Response(JSON.stringify({applicationId:"application_123",name:"baton",sourceType:sourceSaved?"github":"",githubId:"github_123",owner:"rahmanef63",repository:"baton",branch:"main",buildPath:"/"}),{status:200});+ return new Response("not found",{status:404});+ }));+ const {ensureDokployGithubApplication}=await import("./dokploy");+ const result=await withSelection({user:"alice",connection:"work"},()=>ensureDokployGithubApplication({projectId:"project_123",name:"baton",githubId:"github_123",owner:"rahmanef63",repository:"baton",branch:"main"}));+ expect(result).toMatchObject({applicationId:"application_123",sourceType:"github",owner:"rahmanef63",repository:"baton",created:true});+});++it("refuses a repository not exposed by the selected Dokploy GitHub provider",async()=>{+ const withSelection=await seeded();+ vi.stubGlobal("fetch",vi.fn(async(input:RequestInfo|URL)=>{const url=new URL(new Request(input).url);if(url.pathname.endsWith("/github.one"))return new Response(JSON.stringify({githubId:"github_123"}),{status:200});if(url.pathname.endsWith("/github.getGithubRepositories"))return new Response(JSON.stringify([{name:"other",owner:{login:"rahmanef63"}}]),{status:200});return new Response("not found",{status:404});}));+ const {ensureDokployGithubApplication}=await import("./dokploy");+ await expect(withSelection({user:"alice",connection:"work"},()=>ensureDokployGithubApplication({projectId:"project_123",name:"baton",githubId:"github_123",owner:"rahmanef63",repository:"baton",branch:"main"}))).rejects.toThrow(/not accessible/i);+});++it("ensures an HTTPS application domain and verifies it",async()=>{+ const withSelection=await seeded();let created=false;+ vi.stubGlobal("fetch",vi.fn(async(input:RequestInfo|URL,init?:RequestInit)=>{const req=new Request(input,init),url=new URL(req.url);if(url.pathname.endsWith("/domain.byApplicationId"))return new Response(JSON.stringify(created?[{domainId:"domain_123",host:"baton.rahmanef.com",port:3000,https:true}]:[]),{status:200});if(url.pathname.endsWith("/domain.create")){expect(JSON.parse(await req.text())).toEqual({host:"baton.rahmanef.com",port:3000,https:true,applicationId:"application_123",certificateType:"letsencrypt"});created=true;return new Response("{}",{status:200});}return new Response("not found",{status:404});}));+ const {ensureDokployApplicationDomain}=await import("./dokploy");+ const result=await withSelection({user:"alice",connection:"work"},()=>ensureDokployApplicationDomain({applicationId:"application_123",host:"baton.rahmanef.com",port:3000,https:true}));+ expect(result).toMatchObject({domainId:"domain_123",host:"baton.rahmanef.com",port:3000,https:true,created:true});+});diff --git a/lib/infra/dokploy.ts b/lib/infra/dokploy.tsindex a6358522..6b1d46c3 100644--- a/lib/infra/dokploy.ts+++ b/lib/infra/dokploy.ts@@ -201,6 +201,12 @@ export async function testDokployGithubProvider(githubId:string){const id=dokploexport async function deployDokployApplication(applicationId:string){const id=dokployId(applicationId,"application id");await call("/application.deploy","POST",{applicationId:id});return {applicationId:id,redeployQueued:true};}++const DOKPLOY_GIT_PART=/^[A-Za-z0-9_.-]{1,180}$/,DOKPLOY_BRANCH=/^[A-Za-z0-9._\-/#]{1,180}$/,DOKPLOY_BUILD_PATH=/^\/?[A-Za-z0-9._\-/]*$/,DOKPLOY_HOST=/^(?=.{1,253}$)(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;+export async function ensureDokployGithubApplication(args:{projectId:string;name:string;githubId:string;owner:string;repository:string;branch:string;buildPath?:string}){+ const projectId=dokployId(args.projectId,"project id"),githubId=dokployId(args.githubId,"github id"),name=args.name.trim(),owner=args.owner.trim(),repository=args.repository.trim(),branch=args.branch.trim(),buildPath=(args.buildPath??"/").trim()||"/";if(!/^[A-Za-z0-9][A-Za-z0-9._ -]{0,63}$/.test(name))throw new Error("invalid Dokploy application name");if(!DOKPLOY_GIT_PART.test(owner)||!DOKPLOY_GIT_PART.test(repository)||!DOKPLOY_BRANCH.test(branch)||!DOKPLOY_BUILD_PATH.test(buildPath))throw new Error("invalid Dokploy GitHub source metadata");const provider=await inspectDokployGithubProvider(githubId);if(provider.githubId!==githubId)throw new Error("Dokploy GitHub provider could not be verified");const repositories=await listDokployGithubRepositories(githubId);if(!repositories.some(row=>row.name===repository&&row.owner===owner))throw new Error("repository is not accessible through the selected Dokploy GitHub provider");let environmentsRaw=await call(`/environment.byProjectId?projectId=${encodeURIComponent(projectId)}`),environments=Array.isArray(environmentsRaw)?environmentsRaw.map(obj):[];if(!environments.length){await call("/environment.create","POST",{name:"Production",projectId});environmentsRaw=await call(`/environment.byProjectId?projectId=${encodeURIComponent(projectId)}`);environments=Array.isArray(environmentsRaw)?environmentsRaw.map(obj):[];}const environment=environments.find(row=>row.isDefault===true)||environments.find(row=>String(row.name??"").toLowerCase()==="production")||environments[0],environmentId=String(environment?.environmentId??environment?.id??"");if(!environmentId)throw new Error("Dokploy project has no usable environment");const apps=await listDokployApplications(projectId);let app=apps.find(row=>row.name===name||row.appName===name),created=false;if(!app){await call("/application.create","POST",{name,environmentId,sourceType:"github"});app=(await listDokployApplications(projectId)).find(row=>row.name===name||row.appName===name);created=true;}if(!app)throw new Error("Dokploy application create returned success but the application is absent");const applicationId=dokployId(app.applicationId,"application id");await call("/application.saveGithubProvider","POST",{applicationId,repository,owner,buildPath,githubId,branch,triggerType:"push",enableSubmodules:false,watchPaths:[]});const after=await inspectDokployApplication(applicationId);if(after.sourceType!=="github"||after.githubId!==githubId||after.owner!==owner||after.repository!==repository||after.branch!==branch)throw new Error("Dokploy GitHub application source could not be verified");return {projectId,environmentId,applicationId,name:after.name||name,sourceType:after.sourceType,owner,repository,branch,buildPath,created};+}+export async function ensureDokployApplicationDomain(args:{applicationId:string;host:string;port:number;https:boolean}){const applicationId=dokployId(args.applicationId,"application id"),host=args.host.trim().toLowerCase(),port=Math.trunc(args.port);if(!DOKPLOY_HOST.test(host))throw new Error("invalid Dokploy domain host");if(port<1||port>65535)throw new Error("invalid Dokploy domain port");const payload=await call(`/domain.byApplicationId?applicationId=${encodeURIComponent(applicationId)}`),domains=Array.isArray(payload)?payload.map(obj):[];let row=domains.find(item=>String(item.host??"").toLowerCase()===host),created=false;if(!row){await call("/domain.create","POST",{host,port,https:args.https,applicationId,certificateType:args.https?"letsencrypt":"none"});created=true;const next=await call(`/domain.byApplicationId?applicationId=${encodeURIComponent(applicationId)}`);row=(Array.isArray(next)?next.map(obj):[]).find(item=>String(item.host??"").toLowerCase()===host);}if(!row)throw new Error("Dokploy domain create returned success but the domain is absent");const domainId=String(row.domainId??row.id??"");if(!domainId)throw new Error("Dokploy domain has no id");const currentPort=Number(row.port??port),currentHttps=row.https===true;if(currentPort!==port||currentHttps!==args.https)await call("/domain.update","POST",{domainId,host,port,https:args.https,certificateType:args.https?"letsencrypt":"none"});const verify=await call(`/domain.byApplicationId?applicationId=${encodeURIComponent(applicationId)}`),verified=(Array.isArray(verify)?verify.map(obj):[]).find(item=>String(item.host??"").toLowerCase()===host);if(!verified||Number(verified.port??port)!==port||Boolean(verified.https)!==args.https)throw new Error("Dokploy domain could not be verified");return {applicationId,domainId,host,port,https:args.https,created};}export async function recoverDokployPublicGithubToHttpsGit(applicationId:string){const id=dokployId(applicationId,"application id"),before=await readDokployApplication(id);if(before.sourceType!=="github")throw new Error("Dokploy application is not using the GitHub source provider");diff --git a/lib/mcp/integration-model-contract.test.ts b/lib/mcp/integration-model-contract.test.tsindex 48a48562..51b200fa 100644--- a/lib/mcp/integration-model-contract.test.ts+++ b/lib/mcp/integration-model-contract.test.ts@@ -23,6 +23,10 @@ it("exposes the bounded Dokploy application operations through integration_execuconst schema=tool.inputSchema as {properties?:Record<string,{enum?:string[]}>};const operations=schema.properties?.operation?.enum??[];expect(operations).toContain("dokploy.applications.list");+ expect(operations).toContain("dokploy.gitProviders.list");+ expect(operations).toContain("dokploy.github.repositories.list");+ expect(operations).toContain("dokploy.application.ensureGithub");+ expect(operations).toContain("dokploy.domain.ensure");expect(operations).toContain("dokploy.application.publicEnv.upsert");expect(operations.some(operation=>/request|fetch|raw/i.test(operation))).toBe(false);});diff --git a/lib/mcp/tools-integrations.ts b/lib/mcp/tools-integrations.tsindex 701ade8c..fccc4cab 100644--- a/lib/mcp/tools-integrations.ts+++ b/lib/mcp/tools-integrations.ts@@ -8,21 +8,21 @@ const OUTPUT={type:"object",properties:{result:{type:"object"}},required:["resulexport const INTEGRATION_TOOLS:McpTool[]=[{name:"integration_query",title:"Inspect Integration Connections",scope:"read",annotations:{readOnlyHint:true,idempotentHint:true,openWorldHint:false},description:"Read native MSO credential users, providers, named connections, source/auth guidance and directory resolution. Never returns keys. User profiles are credential owners, not device roles. Resolve before acting when multiple accounts or deployments exist.",- chatgptDescription:"Inspect integrations.",+ chatgptDescription:"Inspect.",inputSchema:S({...BASE,view:{type:"string",enum:["snapshot","catalog","users","connections","which","resolve","request"]},source:{type:"string",enum:[...SOURCES]},authMethod:{type:"string",maxLength:64}}),outputSchema:OUTPUT,meta:{ui:{visibility:["model","app"]},"openai/widgetAccessible":true},run:async a=>({result:await queryIntegrationAction(a)}),},{name:"integration_manage",title:"Manage Named Integrations",scope:"write",annotations:{readOnlyHint:false,destructiveHint:true,idempotentHint:false,openWorldHint:true},audit:{action:"infra.write",targetArg:"user"},limit:{key:"integration.manage",max:30,windowMs:60000},description:"Manage native credential users, directory bindings and named provider connections. Actions require confirm=true. Direct credential values are forbidden: use integration_setup_open with user/provider/connection. Composio authorization keeps only external IDs/status and returns its transient URL privately to the UI. Native MCP authorization stays provider-owned.",- chatgptDescription:"Manage integrations privately.",+ chatgptDescription:"Manage.",inputSchema:S({...BASE,action:{type:"string",enum:[...INTEGRATION_ACTIONS,"connection.authorize","connection.import-convex-cli"]},confirm:{type:"boolean",const:true},target:{type:"string",maxLength:64},label:{type:"string",maxLength:120},path:{type:"string",maxLength:4096},source:{type:"string",enum:[...SOURCES]},authMethod:{type:"string",maxLength:64},copyCredentials:{type:"boolean",description:"Explicit opt-in when duplicating a user; default copies metadata only."},makeDefault:{type:"boolean"},key:{type:"string",maxLength:64},authConfigId:{type:"string",maxLength:64},brokerConnection:{type:"string",maxLength:64},createManaged:{type:"boolean"}},["action","confirm"]),outputSchema:OUTPUT,meta:{ui:{visibility:["model","app"]},"openai/widgetAccessible":true},run:async a=>{const out=await manageIntegrationAction(a);if("privateUrl" in out){const{privateUrl,...safe}=out;return mcpDirect([{type:"text",text:"Authorization link available in the private integration UI."}],false,{result:safe},{integrationAuthorization:{url:privateUrl}});}return{result:out};},},{name:"integration_execute",title:"Use an Exact Integration Connection",scope:"exec",annotations:{readOnlyHint:false,destructiveHint:true,openWorldHint:true},audit:{action:"infra.write",targetArg:"connection"},limit:{key:"integration.execute",max:30,windowMs:60000},description:"Execute using an explicit user/provider/named connection. Verify or inspect its route; bounded direct operations reject external backends. Composio tool execution requires an ACTIVE matching connected account and a toolkit-prefixed tool. Native-MCP returns the provider route without copying OAuth tokens. Non-verification operations require confirm=true. No credentials in arguments.",- chatgptDescription:"Run a bounded integration operation.",- inputSchema:S({...BASE,operation:{type:"string",enum:["route","verify","dokploy.projects.list","dokploy.applications.list","dokploy.deployments.list","dokploy.deployment.logs","dokploy.git.recover","dokploy.application.deploy","dokploy.application.publicEnv.upsert","dokploy.project.ensure","convex.customDomains.list","convex.customDomain.ensure","convex.canonical.get","convex.env.presence","convex.canonical.set","cloudflare.zones.list","cloudflare.dns.upsert","hostinger.dns.upsert","hostinger.mail.orders.list","hostinger.mail.plan.get","hostinger.mail.list","hostinger.mail.logs.list","hostinger.mail.mutate","composio.tool"]},confirm:{type:"boolean"},tool:{type:"string",maxLength:180},arguments:{type:"object",additionalProperties:true}},["user","provider","connection","operation"]),outputSchema:OUTPUT,+ chatgptDescription:"Execute.",+ inputSchema:S({...BASE,operation:{type:"string",enum:["route","verify","dokploy.projects.list","dokploy.applications.list","dokploy.gitProviders.list","dokploy.github.repositories.list","dokploy.application.ensureGithub","dokploy.domain.ensure","dokploy.deployments.list","dokploy.deployment.logs","dokploy.git.recover","dokploy.application.deploy","dokploy.application.publicEnv.upsert","dokploy.project.ensure","convex.customDomains.list","convex.customDomain.ensure","convex.canonical.get","convex.env.presence","convex.canonical.set","cloudflare.zones.list","cloudflare.dns.upsert","hostinger.dns.upsert","hostinger.mail.orders.list","hostinger.mail.plan.get","hostinger.mail.list","hostinger.mail.logs.list","hostinger.mail.mutate","composio.tool"]},confirm:{type:"boolean"},tool:{type:"string",maxLength:180},arguments:{type:"object",additionalProperties:true}},["user","provider","connection","operation"]),outputSchema:OUTPUT,meta:{ui:{visibility:["model","app"]},"openai/widgetAccessible":true},run:async a=>({result:await executeIntegrationAction(a)}),},];