UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

46 lines • 2.29 kB
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // ========= Copyright 2026 @ Strukto.AI All Rights Reserved. ========= import { isProgramInvocation } from "../../../../context/session_context.js"; import { IOResult } from "../../../../io/types.js"; import { encodeText } from "../../../../shell/bytes.js"; import { logicalCwd } from "../../../session/shell_dirs.js"; import { ExecutionNode } from "../../../types.js"; import { builtinUsage } from "../shared.js"; import { PWD_OPTIONS } from "./constants.js"; import { splitModeOptions } from "./dirs.js"; // Print the working directory, logical by default and physical under -P // (or `set -P`). GNU ignores every operand: `pwd extra` still prints the // cwd. export function handlePwd(operands, session) { const shellPhysical = session.shellOptions.physical === true; const { bad, physical } = splitModeOptions(operands, PWD_OPTIONS, shellPhysical); if (bad !== null) { // The program (`env pwd`) keeps its bare voice. const voice = isProgramInvocation(session) ? '' : 'bash: '; const err = encodeText(`${voice}pwd: -${bad}: invalid option\n${builtinUsage('pwd')}`); return [ null, new IOResult({ exitCode: 2, stderr: err }), new ExecutionNode({ command: 'pwd', exitCode: 2, stderr: err }), ]; } const cwd = physical ? session.cwd : logicalCwd(session); const out = encodeText(`${cwd}\n`); return [out, new IOResult(), new ExecutionNode({ command: 'pwd', exitCode: 0 })]; } /** The `pwd` arm. */ export function pwdBuiltin(call) { return Promise.resolve(handlePwd([...call.argv.operands], call.context.session)); } //# sourceMappingURL=pwd.js.map