/**
 * Shep Instance Service
 *
 * Infrastructure implementation of IShepInstanceService.
 * Detects whether a target path is the same directory as the running
 * Shep instance by canonicalizing both paths with realpathSync and
 * comparing them after normalizing separators to forward slashes.
 *
 * The running instance path is read from `SHEP_INSTANCE_PATH` (or the
 * legacy `NEXT_PUBLIC_SHEP_INSTANCE_PATH`) and falls back to `process.cwd()`.
 */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { realpathSync } from 'node:fs';
import { resolve } from 'node:path';
import { injectable } from 'tsyringe';
let ShepInstanceService = class ShepInstanceService {
    isSameInstance(targetPath) {
        const instancePath = process.env.SHEP_INSTANCE_PATH ?? process.env.NEXT_PUBLIC_SHEP_INSTANCE_PATH ?? process.cwd();
        try {
            const normalizedTarget = realpathSync(resolve(targetPath)).replace(/\\/g, '/');
            const normalizedInstance = realpathSync(resolve(instancePath)).replace(/\\/g, '/');
            return normalizedTarget === normalizedInstance;
        }
        catch {
            // Path does not exist or is not accessible — assume "not same instance"
            // so the caller can surface a more specific "path does not exist" error.
            return false;
        }
    }
};
ShepInstanceService = __decorate([
    injectable()
], ShepInstanceService);
export { ShepInstanceService };
