(input?: string, opts: { home?: boolean } = {})
| 248 | } |
| 249 | |
| 250 | export function toolPath(input?: string, opts: { home?: boolean } = {}): string { |
| 251 | if (!input) { |
| 252 | return "" |
| 253 | } |
| 254 | |
| 255 | const cwd = process.cwd() |
| 256 | const home = os.homedir() |
| 257 | const abs = path.isAbsolute(input) ? input : path.resolve(cwd, input) |
| 258 | const rel = path.relative(cwd, abs) |
| 259 | |
| 260 | if (!rel) { |
| 261 | return "." |
| 262 | } |
| 263 | |
| 264 | if (!rel.startsWith("..")) { |
| 265 | return rel.replaceAll("\\", "/") |
| 266 | } |
| 267 | |
| 268 | if (opts.home && home && (abs === home || abs.startsWith(home + path.sep))) { |
| 269 | return abs.replace(home, "~").replaceAll("\\", "/") |
| 270 | } |
| 271 | |
| 272 | return abs.replaceAll("\\", "/") |
| 273 | } |
| 274 | |
| 275 | function fallbackInline(ctx: ToolFrame): ToolInline { |
| 276 | const title = text(ctx.state.title) || (Object.keys(ctx.input).length > 0 ? JSON.stringify(ctx.input) : "Unknown") |
no test coverage detected