Add plugins/common.ts for the helpers and size limits copied across plugin files; managed-transaction compares snapshots in one place; guard template imported directly. Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import path from 'node:path';
|
|
|
|
export const MAX_SECRET_BYTES = 64 * 1024;
|
|
export const MAX_CONFIG_BYTES = 512 * 1024;
|
|
export const MAX_SOURCE_BYTES = 2 * 1024 * 1024;
|
|
|
|
export function asError(error: unknown): Error {
|
|
return error instanceof Error ? error : new Error(String(error));
|
|
}
|
|
|
|
export function errorMessage(error: unknown): string {
|
|
return error instanceof Error ? error.message : String(error);
|
|
}
|
|
|
|
export function hasCode(error: unknown, code: string): boolean {
|
|
return typeof error === 'object' && error !== null && 'code' in error && error.code === code;
|
|
}
|
|
|
|
export function samePath(left: string, right: string): boolean {
|
|
const normalizedLeft = path.resolve(left);
|
|
const normalizedRight = path.resolve(right);
|
|
return process.platform === 'win32'
|
|
? normalizedLeft.toLowerCase() === normalizedRight.toLowerCase()
|
|
: normalizedLeft === normalizedRight;
|
|
}
|
|
|
|
export function sameAgentId(left: unknown, right: string): boolean {
|
|
return typeof left === 'string' && (process.platform === 'win32'
|
|
? left.toLowerCase() === right.toLowerCase()
|
|
: left === right);
|
|
}
|