UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines • 7.64 kB
import{defineSetupIntegration}from"../types.js";import{describeIntegrationSetupEnvironment}from"../shared/environment.js";import{installScaffoldDependencies}from"../shared/scaffold.js";import{relative}from"node:path";import{ensurePackageDependencies}from"#setup/scaffold/index.js";import{confirm,select,text}from"#setup/ask.js";import{classifySelfModificationConfig,connectorName,defaultSelfModificationSetupOperations,directoryError,gitRefError,renderSelfModificationConfig,repositoryPartError}from"#self-modification/setup.js";import{SELF_MODIFICATION_CONFIG_PATH}from"#self-modification/git-workspace.js";import{detectLegacySelfModificationScaffold,removeLegacySelfModificationScaffold}from"#self-modification/migration.js";import{DEFAULT_CONNECT_PACKAGE_VERSION,DEFAULT_MICROSANDBOX_PACKAGE_VERSION}from"#setup/scaffold/version-tokens.js";const defaultApplyDependencies={ensurePackageDependencies,installScaffoldDependencies},SELF_MODIFICATION_PRODUCTION_DEPENDENCIES={"@vercel/connect":DEFAULT_CONNECT_PACKAGE_VERSION,microsandbox:DEFAULT_MICROSANDBOX_PACKAGE_VERSION};function validationResult(e){return e??null}async function prepareLegacyScaffoldCleanup(e){let t=await detectLegacySelfModificationScaffold(e.appRoot);return t===void 0?void 0:await e.asker.ask(confirm({key:`self-modification-cleanup`,message:`A legacy self-modification scaffold was found at ${relative(e.appRoot,t.root)}. This scaffold format is no longer supported. Do you want to remove it?`,recommended:!0,required:!0}))?t:void 0}function withLegacyScaffold(e,t){return t===void 0?e:{...e,legacyScaffold:t}}async function prepareSelfModificationSetup(e,t=defaultSelfModificationSetupOperations(e.appRoot,void 0,e.projectRoot)){let n=await prepareLegacyScaffoldCleanup(e),r=await t.readConfig();if(classifySelfModificationConfig(r)===`authored`)return e.presenter.note(`The existing ${SELF_MODIFICATION_CONFIG_PATH} contains authored configuration and was not overwritten.`,`Manual update required`,{tone:`warning`}),withLegacyScaffold({kind:`authored`},n);if(await e.asker.ask(select({key:`self-modification-mode`,message:`How should self-modification be enabled?`,options:[{id:`deployed`,value:`deployed`,label:`Enable for deployed`,hint:`Let deployed agents propose source changes through draft pull requests`},{id:`local`,value:`local`,label:`Keep local`,hint:`Only enable source editing during local development`}],recommended:`local`,required:!0}))===`local`)return withLegacyScaffold({kind:`local`},n);let[i,a,o]=await Promise.all([e.resolveVercelProject(`self-modification`),t.detectGitRepository(),t.detectChannelNames()]),s=await e.asker.ask(text({key:`self-modification-repository-owner`,message:`GitHub repository owner`,detected:a.owner,required:!0,validate:e=>validationResult(repositoryPartError(e))})),c=await e.asker.ask(text({key:`self-modification-repository-name`,message:`GitHub repository name`,detected:a.repo,required:!0,validate:e=>validationResult(repositoryPartError(e))})),l=await e.asker.ask(text({key:`self-modification-repository-directory`,message:`Application directory relative to the repository root`,detected:a.directory??`.`,required:!0,validate:e=>validationResult(directoryError(e))})),u=await e.asker.ask(text({key:`self-modification-target-branch`,message:`Target branch`,detected:a.branch??`main`,required:!0,validate:e=>validationResult(gitRefError(e))})),d=connectorName(s,c),f={branch:u,channelNames:o,connector:`github/${d}`,directory:l,repository:`github.com/${s}/${c}`,vercelBackend:!0};return e.presenter.note(renderSelfModificationConfig(f),`Generated ${SELF_MODIFICATION_CONFIG_PATH}`),e.presenter.note(`Vercel Connect will issue short-lived GitHub App credentials restricted to this repository. Install the managed GitHub App and select only this repository. Review, merge, and deployment remain separate operator boundaries.`,`Security summary`),withLegacyScaffold(await e.asker.ask(confirm({key:`self-modification-confirm`,message:`Create or attach this GitHub connector and write this configuration?`,recommended:!1,required:!0}))?{kind:`deployed`,connectorName:d,project:i,values:f}:{kind:`local`},n)}async function applySelfModificationSetup(e,t,n=defaultSelfModificationSetupOperations(t.appRoot,void 0,t.projectRoot),r=defaultApplyDependencies){if(e.legacyScaffold!==void 0&&(await removeLegacySelfModificationScaffold(t.appRoot,e.legacyScaffold),t.presenter.log.success(`Removed the retired self-modification scaffold.`)),e.kind===`authored`)return{facts:[{label:`Self-modification`,value:`manual configuration update required`}]};if(e.kind===`local`)return{facts:[]};let i=await n.findOrCreateConnector(e.connectorName,e.project);await n.attachConnector(i,e.project);let a=await r.ensurePackageDependencies({dependencies:SELF_MODIFICATION_PRODUCTION_DEPENDENCIES,projectRoot:t.appRoot});return await r.installScaffoldDependencies({changed:a.length>0,log:t.presenter.log,projectPath:t.appRoot,signal:t.signal}),await n.writeConfig(renderSelfModificationConfig({...e.values,connector:i})),t.presenter.log.success(`Updated ${SELF_MODIFICATION_CONFIG_PATH}.`),t.presenter.nextSteps([`Install the managed GitHub App for the configured repository, then deploy or redeploy.`,e.values.vercelBackend?"After deployment, try self-modification by running `eve dev <deployment-url>` from this linked project. The generated policy admits its Vercel OIDC identity over HTTP; configured channels remain denied until you update `agent/extensions/self-modification/extension.ts`.":"Before deployment, configure `deployed.authorize` in `agent/extensions/self-modification/extension.ts` to admit a trusted principal for your deployment's channel. After deployment, use that channel to try self-modification."]),{deploymentRequired:!0,facts:[{label:`Repository`,value:e.values.repository},{label:`Application directory`,value:e.values.directory},{label:`Target branch`,value:e.values.branch},{label:`Credential`,value:i}]}}async function prepareLocalSelfModificationSetup(e,t=defaultSelfModificationSetupOperations(e.appRoot,void 0,e.projectRoot)){let n=await prepareLegacyScaffoldCleanup(e),r=await t.readConfig();return classifySelfModificationConfig(r)===`authored`?(e.presenter.note(`The existing ${SELF_MODIFICATION_CONFIG_PATH} contains authored configuration and was not overwritten.`,`Manual update required`,{tone:`warning`}),withLegacyScaffold({kind:`authored`},n)):withLegacyScaffold({kind:`local`},n)}function describeEnvironment(e){if(e.vercel.kind===`available`)return describeIntegrationSetupEnvironment(e);switch(e.vercel.reason){case`logged-out`:return`No authenticated Vercel account found. Local editing remains available; deployed proposals require Vercel Connect.`;case`cli-missing`:return`Vercel CLI not found. Local editing remains available; deployed proposals require Vercel Connect.`;case`unavailable`:return`Could not verify the Vercel account. Local editing remains available; deployed proposals require Vercel Connect.`}}const SELF_MODIFICATION_SETUP=defineSetupIntegration({kind:`self-modification`,label:`Self-modification`,hint:`Local source editing is enabled`,describeEnvironment,prepare:prepareLocalSelfModificationSetup,apply:applySelfModificationSetup}),SELF_MODIFICATION_PRODUCTION_SETUP=defineSetupIntegration({kind:`self-modification-production`,label:`Self-modification production`,hint:`Configure deployed draft pull requests`,describeEnvironment,prepare:prepareSelfModificationSetup,apply:applySelfModificationSetup});export{SELF_MODIFICATION_PRODUCTION_SETUP,SELF_MODIFICATION_SETUP,applySelfModificationSetup,prepareLocalSelfModificationSetup,prepareSelfModificationSetup};