chore: import upstream snapshot with attribution
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
# ========= 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. =========
|
||||
|
||||
from mirage.commands.spec.shell import ECHO_OPTION
|
||||
from mirage.io import IOResult
|
||||
from mirage.io.types import ByteSource
|
||||
from mirage.workspace.types import ExecutionNode
|
||||
|
||||
_SIMPLE_ESCAPES = {
|
||||
"\\": "\\",
|
||||
"n": "\n",
|
||||
"t": "\t",
|
||||
"r": "\r",
|
||||
"a": "\a",
|
||||
"b": "\b",
|
||||
"f": "\f",
|
||||
"v": "\v",
|
||||
}
|
||||
|
||||
_HEX = set("0123456789abcdefABCDEF")
|
||||
|
||||
_OCT = set("01234567")
|
||||
|
||||
|
||||
def _interpret_escapes(text: str) -> str:
|
||||
"""Process C-style escape sequences for echo -e.
|
||||
|
||||
Single-pass to handle \\\\ correctly (\\\\b → \\b literal).
|
||||
Supports: \\\\, \\n, \\t, \\r, \\a, \\b, \\f, \\v,
|
||||
\\xHH (hex), \\0NNN (octal), \\c (stop output).
|
||||
Unknown escapes like \\z pass through as \\z.
|
||||
"""
|
||||
out: list[str] = []
|
||||
i = 0
|
||||
n = len(text)
|
||||
while i < n:
|
||||
if text[i] != "\\" or i + 1 >= n:
|
||||
out.append(text[i])
|
||||
i += 1
|
||||
continue
|
||||
ch = text[i + 1]
|
||||
if ch in _SIMPLE_ESCAPES:
|
||||
out.append(_SIMPLE_ESCAPES[ch])
|
||||
i += 2
|
||||
elif ch == "c":
|
||||
break
|
||||
elif ch == "x":
|
||||
# \xHH — up to 2 hex digits
|
||||
digits = []
|
||||
j = i + 2
|
||||
while j < n and len(digits) < 2 and text[j] in _HEX:
|
||||
digits.append(text[j])
|
||||
j += 1
|
||||
if digits:
|
||||
out.append(chr(int("".join(digits), 16)))
|
||||
i = j
|
||||
else:
|
||||
out.append("\\x")
|
||||
i += 2
|
||||
elif ch == "0":
|
||||
# \0NNN — up to 3 octal digits
|
||||
digits = []
|
||||
j = i + 2
|
||||
while j < n and len(digits) < 3 and text[j] in _OCT:
|
||||
digits.append(text[j])
|
||||
j += 1
|
||||
out.append(chr(int("".join(digits), 8)) if digits else "\0")
|
||||
i = j
|
||||
else:
|
||||
# unknown escape — pass through literally
|
||||
out.append("\\")
|
||||
out.append(ch)
|
||||
i += 2
|
||||
return "".join(out)
|
||||
|
||||
|
||||
async def handle_echo(
|
||||
args: list[str], # noqa: E125
|
||||
) -> tuple[ByteSource | None, IOResult, ExecutionNode]:
|
||||
"""Print arguments, honoring GNU echo's option rules.
|
||||
|
||||
GNU echo is not getopt: options are LEADING words matching
|
||||
``-[neE]+`` only. The first word that does not match (including
|
||||
``-x`` or a repeated ``hi -n``) ends option parsing and prints
|
||||
literally. Within clusters the last of -e/-E wins; -n sticks.
|
||||
|
||||
Args:
|
||||
args (list[str]): words after the command name, as typed.
|
||||
"""
|
||||
no_newline = False
|
||||
escapes = False
|
||||
idx = 0
|
||||
for word in args:
|
||||
if not ECHO_OPTION.fullmatch(word):
|
||||
break
|
||||
for ch in word[1:]:
|
||||
if ch == "n":
|
||||
no_newline = True
|
||||
elif ch == "e":
|
||||
escapes = True
|
||||
else:
|
||||
escapes = False
|
||||
idx += 1
|
||||
text = " ".join(args[idx:])
|
||||
if escapes:
|
||||
text = _interpret_escapes(text)
|
||||
if not no_newline:
|
||||
text += "\n"
|
||||
out = text.encode()
|
||||
return out, IOResult(), ExecutionNode(command="echo", exit_code=0)
|
||||
|
||||
|
||||
async def handle_printf(
|
||||
args: list[str], # noqa: E125
|
||||
) -> tuple[ByteSource | None, IOResult, ExecutionNode]:
|
||||
if not args:
|
||||
return b"", IOResult(), ExecutionNode(command="printf", exit_code=0)
|
||||
fmt = args[0]
|
||||
fmt = fmt.replace("\\n", "\n").replace("\\t", "\t")
|
||||
if len(args) > 1:
|
||||
try:
|
||||
out = (fmt % tuple(args[1:])).encode()
|
||||
except TypeError:
|
||||
out = fmt.encode()
|
||||
else:
|
||||
out = fmt.encode()
|
||||
return out, IOResult(), ExecutionNode(command="printf", exit_code=0)
|
||||
Reference in New Issue
Block a user