Command files use shell-command and managedScriptReference; runtime checks use managed-runtime-status; jsonc-edit.ts and parseCommentedJsonObject replace copied JSONC helpers. Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import path from 'node:path';
|
|
import { managedScriptReference } from './common.js';
|
|
import {
|
|
isNodeExecutable,
|
|
parsePosixCommand,
|
|
parsePowerShellSource,
|
|
posixSource,
|
|
powerShellSource,
|
|
} from './shell-command.js';
|
|
|
|
export interface LettaRuntimeReference {
|
|
readonly agentId: string;
|
|
readonly executablePath?: string;
|
|
readonly scriptPath: string;
|
|
}
|
|
|
|
export function buildLettaCommand(scriptPath: string): string {
|
|
if (!path.isAbsolute(process.execPath) || !path.isAbsolute(scriptPath)) {
|
|
throw new Error('Letta Code hook commands require absolute executable and script paths');
|
|
}
|
|
return process.platform === 'win32' ? powerShellSource(scriptPath) : posixSource(scriptPath);
|
|
}
|
|
|
|
function legacyScriptPath(command: string): string | undefined {
|
|
if (!command.startsWith('node "') || !command.endsWith('"')) return undefined;
|
|
const scriptPath = command.slice(6, -1);
|
|
return scriptPath.includes('"') ? undefined : scriptPath;
|
|
}
|
|
|
|
export function lettaRuntimeReference(
|
|
command: string,
|
|
scriptName: string,
|
|
): LettaRuntimeReference | undefined {
|
|
const parsed = process.platform === 'win32'
|
|
? parsePowerShellSource(command)
|
|
: parsePosixCommand(command);
|
|
if (!parsed || !path.isAbsolute(parsed[0]) || !isNodeExecutable(parsed[0])) return undefined;
|
|
const reference = managedScriptReference(parsed[1], scriptName);
|
|
return reference ? { ...reference, executablePath: parsed[0] } : undefined;
|
|
}
|
|
|
|
export function lettaLegacyRuntimeReference(
|
|
command: string,
|
|
scriptName: string,
|
|
): LettaRuntimeReference | undefined {
|
|
const legacy = legacyScriptPath(command);
|
|
return legacy ? managedScriptReference(legacy, scriptName) : undefined;
|
|
}
|