mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 20:05:05 +00:00
Fix SDK tools to respect cwd option
Core tools now properly use the cwd passed to createAgentSession(). Added tool factory functions for SDK users who specify custom cwd with explicit tools. Fixes #279
This commit is contained in:
parent
42bc368e70
commit
face745f3d
16 changed files with 1243 additions and 1044 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { accessSync, constants } from "node:fs";
|
||||
import * as os from "node:os";
|
||||
import { isAbsolute, resolve as resolvePath } from "node:path";
|
||||
|
||||
const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
|
||||
const NARROW_NO_BREAK_SPACE = "\u202F";
|
||||
|
|
@ -32,17 +33,29 @@ export function expandPath(filePath: string): string {
|
|||
return normalized;
|
||||
}
|
||||
|
||||
export function resolveReadPath(filePath: string): string {
|
||||
/**
|
||||
* Resolve a path relative to the given cwd.
|
||||
* Handles ~ expansion and absolute paths.
|
||||
*/
|
||||
export function resolveToCwd(filePath: string, cwd: string): string {
|
||||
const expanded = expandPath(filePath);
|
||||
|
||||
if (fileExists(expanded)) {
|
||||
if (isAbsolute(expanded)) {
|
||||
return expanded;
|
||||
}
|
||||
return resolvePath(cwd, expanded);
|
||||
}
|
||||
|
||||
const macOSVariant = tryMacOSScreenshotPath(expanded);
|
||||
if (macOSVariant !== expanded && fileExists(macOSVariant)) {
|
||||
export function resolveReadPath(filePath: string, cwd: string): string {
|
||||
const resolved = resolveToCwd(filePath, cwd);
|
||||
|
||||
if (fileExists(resolved)) {
|
||||
return resolved;
|
||||
}
|
||||
|
||||
const macOSVariant = tryMacOSScreenshotPath(resolved);
|
||||
if (macOSVariant !== resolved && fileExists(macOSVariant)) {
|
||||
return macOSVariant;
|
||||
}
|
||||
|
||||
return expanded;
|
||||
return resolved;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue