fix(augment): make hook installation transactional
This commit is contained in:
1 parent
b59404cd33
commit
323757e43d
12 files changed
+1121
-506
No files matched your search
+25
-21
@@ -3,32 +3,36 @@ import { SUPPORTED_AGENTS } from './registry.js';
|
||||
import {
|
||||
AGENT_KEY,
|
||||
buildHandler,
|
||||
buildWrapper,
|
||||
removeManagedHooks,
|
||||
renderAugmentDocument,
|
||||
runtimeContracts,
|
||||
wrapperPaths,
|
||||
} from './augment-contract.js';
|
||||
import {
|
||||
commitAugmentInstallation,
|
||||
preflightAugmentInstallation,
|
||||
prepareAugmentInstallation,
|
||||
} from './augment-installation.js';
|
||||
import {
|
||||
augmentRuntimeFilesExist,
|
||||
readConfig,
|
||||
removeConfig,
|
||||
requireRuntime,
|
||||
runtimeFilesExist,
|
||||
writeConfig,
|
||||
writeWrapper,
|
||||
writeAugmentDocument,
|
||||
} from './augment-io.js';
|
||||
|
||||
const entry = SUPPORTED_AGENTS.get(AGENT_KEY)!;
|
||||
|
||||
export const augmentPlugin: AgentPlugin = {
|
||||
async install(config: InstallConfig): Promise<void> {
|
||||
if (!config.agentId) throw new Error('agentId is required');
|
||||
const document = await readConfig();
|
||||
await requireRuntime(config.guardScriptPath, 'Elydora guard runtime');
|
||||
await requireRuntime(config.hookScriptPath, 'Elydora audit runtime');
|
||||
managesRuntime: true,
|
||||
|
||||
const wrappers = wrapperPaths(config.agentId);
|
||||
await writeWrapper(wrappers.guardPath, buildWrapper(config.guardScriptPath));
|
||||
await writeWrapper(wrappers.auditPath, buildWrapper(config.hookScriptPath));
|
||||
async preflightInstall(config: InstallConfig): Promise<void> {
|
||||
const document = await readConfig();
|
||||
await preflightAugmentInstallation(config, document.configPath);
|
||||
},
|
||||
|
||||
async install(config: InstallConfig): Promise<void> {
|
||||
const document = await readConfig();
|
||||
const paths = await preflightAugmentInstallation(config, document.configPath);
|
||||
const wrappers = wrapperPaths(paths.agentDirectory);
|
||||
|
||||
const cleaned = removeManagedHooks(document.hooks).hooks;
|
||||
const hooks = {
|
||||
@@ -42,7 +46,9 @@ export const augmentPlugin: AgentPlugin = {
|
||||
{ matcher: '.*', hooks: [buildHandler(wrappers.auditPath)] },
|
||||
],
|
||||
};
|
||||
await writeConfig(document.configPath, { ...document.root, hooks });
|
||||
const rendered = renderAugmentDocument(document, hooks);
|
||||
const prepared = await prepareAugmentInstallation(config, rendered);
|
||||
await commitAugmentInstallation(prepared);
|
||||
console.log(' Auggie: user-level PreToolUse and PostToolUse hooks installed.');
|
||||
},
|
||||
|
||||
@@ -51,18 +57,16 @@ export const augmentPlugin: AgentPlugin = {
|
||||
if (!document.exists) return;
|
||||
const result = removeManagedHooks(document.hooks, agentId);
|
||||
if (!result.changed) return;
|
||||
const root = { ...document.root };
|
||||
if (Object.keys(result.hooks).length > 0) root.hooks = result.hooks;
|
||||
else delete root.hooks;
|
||||
if (Object.keys(root).length === 0) await removeConfig(document.configPath);
|
||||
else await writeConfig(document.configPath, root);
|
||||
await writeAugmentDocument(renderAugmentDocument(document, result.hooks));
|
||||
},
|
||||
|
||||
async status(): Promise<PluginStatus> {
|
||||
const document = await readConfig();
|
||||
const contracts = runtimeContracts(document.hooks);
|
||||
const hookConfigured = contracts.length > 0;
|
||||
const hookScriptExists = hookConfigured ? await runtimeFilesExist(contracts) : false;
|
||||
const hookScriptExists = hookConfigured
|
||||
? await augmentRuntimeFilesExist(contracts)
|
||||
: false;
|
||||
return {
|
||||
installed: hookConfigured && hookScriptExists,
|
||||
agentName: AGENT_KEY,
|
||||
|
||||
Reference in new issue
Block a user