@struktoai/mirage-claude-managed-agents 0.0.0-stage → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 @ Strukto.AI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,338 @@
1
- # Temporary Holding Version
1
+ <h1 align="center">
2
+ <a href="https://www.strukto.ai/mirage">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/mirage-header-dark.svg">
5
+ <img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/mirage-header-light.svg" width="100%" alt="Mirage: A Virtual Terminal for AI Agents" />
6
+ </picture>
7
+ </a>
8
+ <a href="https://agentvfs.org">
9
+ <picture>
10
+ <source media="(max-width: 767px) and (prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/agentvfs-banner-narrow-dark.svg">
11
+ <source media="(max-width: 767px)" srcset="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/agentvfs-banner-narrow-light.svg">
12
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/agentvfs-banner-dark.svg">
13
+ <img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/agentvfs-banner-light.svg" width="100%" alt="AgentVFS: the open, vendor-neutral virtual filesystem interface for AI agents" />
14
+ </picture>
15
+ </a>
16
+ </h1>
2
17
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
18
+ <p align="center">
19
+ <a href="https://docs.mirage.strukto.ai" alt="Documentation">
20
+ <img src="https://img.shields.io/badge/mirage-docs-0C0C0C?labelColor=F0ECE2" /></a>
21
+ <a href="https://github.com/strukto-ai/mirage/releases" alt="Status">
22
+ <img src="https://img.shields.io/badge/status-preview-0C0C0C?labelColor=F0ECE2" alt="Status: preview" /></a>
23
+ <a href="https://www.strukto.ai" alt="Website">
24
+ <img src="https://img.shields.io/badge/made by-strukto.ai-0C0C0C?labelColor=F0ECE2" /></a>
25
+ <a href="https://github.com/strukto-ai/mirage/blob/main/LICENSE" alt="License">
26
+ <img src="https://img.shields.io/badge/license-Apache--2.0-0C0C0C?labelColor=F0ECE2" /></a>
27
+ <a href="https://doi.org/10.5281/zenodo.23504502" alt="DOI">
28
+ <img src="https://img.shields.io/badge/DOI-10.5281%2Fzenodo.23504502-0C0C0C?labelColor=F0ECE2" alt="DOI 10.5281/zenodo.23504502" /></a>
29
+ <a href="https://discord.gg/u8BPQ65KsS" alt="Discord">
30
+ <img src="https://img.shields.io/badge/discord-join-0C0C0C?labelColor=F0ECE2&logo=discord&logoColor=0C0C0C" /></a>
31
+ <br/>
32
+ <a href="https://docs.mirage.strukto.ai/python/quickstart" alt="Python docs">
33
+ <img src="https://img.shields.io/badge/python-docs-0C0C0C?labelColor=F0ECE2&logo=python&logoColor=0C0C0C" alt="Python docs"></a>
34
+ <a href="https://pypi.org/project/mirage-ai/" alt="PyPI Version">
35
+ <img src="https://img.shields.io/pypi/v/mirage-ai.svg?color=0C0C0C&labelColor=F0ECE2"/></a>
36
+ <br/>
37
+ <a href="https://docs.mirage.strukto.ai/typescript/quickstart" alt="TypeScript docs">
38
+ <img src="https://img.shields.io/badge/typescript-docs-0C0C0C?labelColor=F0ECE2&logo=typescript&logoColor=0C0C0C" alt="TypeScript docs"></a>
39
+ <a href="https://www.npmjs.com/package/@struktoai/mirage-node" alt="NPM Version">
40
+ <img src="https://img.shields.io/npm/v/@struktoai/mirage-node.svg?color=0C0C0C&labelColor=F0ECE2"/></a>
41
+ </p>
42
+
43
+ <p align="center">
44
+ <a href="https://github.com/strukto-ai/mirage/blob/main/README.md"><img alt="README in English" src="https://img.shields.io/badge/English-F0ECE2"></a>
45
+ <a href="https://github.com/strukto-ai/mirage/blob/main/readme/README.zh-CN.md"><img alt="简体中文 README" src="https://img.shields.io/badge/简体中文-F0ECE2"></a>
46
+ <a href="https://github.com/strukto-ai/mirage/blob/main/readme/README.zh-TW.md"><img alt="繁體中文 README" src="https://img.shields.io/badge/繁體中文-F0ECE2"></a>
47
+ <a href="https://github.com/strukto-ai/mirage/blob/main/readme/README.fr.md"><img alt="README en Français" src="https://img.shields.io/badge/Français-F0ECE2"></a>
48
+ <a href="https://github.com/strukto-ai/mirage/blob/main/readme/README.de.md"><img alt="README auf Deutsch" src="https://img.shields.io/badge/Deutsch-F0ECE2"></a>
49
+ <a href="https://github.com/strukto-ai/mirage/blob/main/readme/README.vi.md"><img alt="README Tiếng Việt" src="https://img.shields.io/badge/Ti%E1%BA%BFng%20Vi%E1%BB%87t-F0ECE2"></a>
50
+ <a href="https://github.com/strukto-ai/mirage/blob/main/readme/README.ko.md"><img alt="README 한국어" src="https://img.shields.io/badge/%ED%95%9C%EA%B5%AD%EC%96%B4-F0ECE2"></a>
51
+ </p>
52
+
53
+ Mirage is **a Virtual Terminal for AI Agents**: one shell over data, CLIs and runtimes. Unix tools reach every service, and `grep` runs on each service's own search, such as Gmail's or Slack's. Mirage routes each command to the runtime that fits it, so most lines run in-process and only heavy work reaches a sandbox, which cuts infrastructure cost and tokens. The terminal itself is light: a workspace takes **about 100 KB** of memory and each new session **about 10 KB**, so one process serves many agents at once. Profiles decide what an agent can run and even what it can see, and scriptable policies refuse anything those rules cannot express.
54
+
55
+ <p align="center">
56
+ <picture>
57
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/mirage-arch-dark.svg">
58
+ <img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/mirage-arch-light.svg" alt="Mirage architecture: agents and harness reach profiles and the Mirage shell, which resolve Unix-like commands, virtual CLIs and programming languages onto runtimes and the virtual filesystem, with authentication, the policy engine and notifications alongside" width="100%">
59
+ </picture>
60
+ </p>
61
+
62
+ Here is an example of launching Mirage inside an application:
63
+
64
+ ```python
65
+ ws = Workspace(
66
+ {
67
+ "/s3": (S3VFS(S3Config(bucket="my-bucket")), MountMode.WRITE),
68
+ "/slack": (SlackVFS(SlackConfig(token=slack_bot_token)), MountMode.EXEC),
69
+ "/gmail": (GmailVFS(GmailConfig(**google_credentials)), MountMode.READ),
70
+ },
71
+ # Install the Slack CLI, run by name and listed by `man` and `which` like any program
72
+ clis={"slack": (SLACK, {"token": slack_bot_token})},
73
+ # the analyst profile hides /s3/secrets and denies posting to Slack and curl
74
+ profiles={
75
+ "analyst": {
76
+ "paths": {"hide": ["/s3/secrets"]},
77
+ "commands": {"deny": ["slack send-message", "curl"]},
78
+ },
79
+ },
80
+ runtimes=[
81
+ MontyRuntime(captures=["python", "python3"]),
82
+ E2BRuntime(
83
+ captures=["python", "python3"],
84
+ config={"sandbox_id": sandbox_id, "mount_type": "ssh"},
85
+ ),
86
+ ],
87
+ # route the underlying computation: numpy lines run in the e2b sandbox, the rest on monty
88
+ route_policy=lambda ctx: "e2b" if "numpy" in ctx.line else None,
89
+ )
90
+
91
+ # Add an agent using the analyst profile
92
+ alice = await ws.session("alice", profile="analyst")
93
+
94
+ # one grep sweeps S3, Slack and Gmail, on each service's own search where it has one
95
+ await alice.shell("grep -rlw invoice /s3 /slack /gmail")
96
+
97
+ # run a script that lives in Slack on monty, file the report into S3
98
+ await alice.shell("python3 /slack/channels/general__C0123/2026-10-21/files/report__F0456.py > /s3/report.txt")
99
+
100
+ # numpy is not in monty, so the route policy sends this line to e2b
101
+ await alice.shell("python3 -c 'import numpy; print(numpy.arange(10).sum())'")
102
+ ```
103
+
104
+ And what `alice` sees in the shell:
105
+
106
+ ```console
107
+ $ grep -rlw invoice /s3 /slack /gmail
108
+ /s3/billing/2026-10.csv
109
+ /gmail/INBOX/2026-10-21/Invoice_1042__18f3a9c2b7d1e0f4.gmail.json
110
+ $ ls /s3
111
+ billing
112
+ report.txt
113
+ $ cat /s3/secrets/aws.txt
114
+ cat: /s3/secrets/aws.txt: No such file or directory
115
+ $ slack send-message --channel general --text "report is up"
116
+ slack: Permission denied
117
+ ```
118
+
119
+ ## About
120
+
121
+ - **Unified virtual terminal interface, not N SDKs and M MCPs.** Every backend speaks the same filesystem semantics, so pipelines compose across services.
122
+ - **A virtual filesystem over every source.** S3, Google Drive, Slack, Gmail, Redis and the rest mount side by side under one root, so an agent reaches all of them through a unified interface with the unix tools it already knows, like `ls`, `grep`, `find` and `jq`.
123
+ - **Virtual command line tools (CLIs).** `git`, `slack` and `ntn` are answered by Mirage itself, so an agent drives the service with nothing installed, across different runtimes and machines, and one tool can be virtualized into two or more, each under its own name with its own credentials.
124
+ - **Routed, dynamic runtimes.** Python, JavaScript and any other command can be sent to a configured runtime, in process, sandboxed or remote, which decouples computation from storage and lets either change without touching the other.
125
+ - **The virtualized Mirage shell.** It binds the filesystem, the CLIs and the runtimes into one command line, so pipes, redirection, variables, jobs and history work across all three.
126
+ - **Lightweight by design.** A workspace, the virtual terminal itself, takes about 100 KB of memory and each new session about 10 KB, so one process serves many agents without a container or VM per agent.
127
+ - **Profiles designed for agents.** `allow`, `ask` and `deny` govern commands and CLIs, while `hide` and `show` govern files and folders, so a hidden path is not merely unreadable but absent from the filesystem the agent sees.
128
+ - **A scriptable policy engine.** A policy script can prohibit any dangerous action before it runs, and the same stack gates every VFS op and session write, so neither a file nor an environment variable leaks.
129
+ - **Notifications wired into the VFS and agents.** External changes become an event stream on the mount, so a new Slack reply surfaces as a change to the chat file in the virtual filesystem, and the agent reacts to it instead of rescanning the tree.
130
+
131
+ ## Virtual Filesystem
132
+
133
+ Everything [Mirage](https://www.strukto.ai/mirage) "mounts" as one unified virtual filesystem for AI agents. Each
134
+ service sits side-by-side under a single root and answers the same POSIX semantics.
135
+
136
+ | | VFS |
137
+ | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
138
+ | **Object Storage** | <a href="https://aws.amazon.com/s3/"><img src="https://api.iconify.design/logos/aws-s3.svg" width="20" height="20" alt="Amazon S3" title="Amazon S3" /></a>  <a href="https://developers.cloudflare.com/r2/"><img src="https://cdn.simpleicons.org/cloudflare" width="20" height="20" alt="Cloudflare R2" title="Cloudflare R2" /></a>  <a href="https://cloud.google.com/storage"><img src="https://api.iconify.design/logos/google-cloud.svg" width="25" height="20" alt="Google Cloud Storage" title="Google Cloud Storage" /></a>  <a href="https://www.oracle.com/cloud/storage/"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/oracle.svg" width="32" height="20" alt="Oracle OCI" title="Oracle OCI" /></a>  <a href="https://supabase.com/storage"><img src="https://api.iconify.design/logos/supabase-icon.svg" width="19" height="20" alt="Supabase Storage" title="Supabase Storage" /></a>  <a href="https://min.io"><img src="https://cdn.simpleicons.org/minio" width="20" height="20" alt="MinIO" title="MinIO" /></a>  <a href="https://ceph.io/en/discover/technology/"><img src="https://cdn.simpleicons.org/ceph" width="20" height="20" alt="Ceph" title="Ceph" /></a>  <a href="https://github.com/seaweedfs/seaweedfs"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/seaweedfs.svg" width="20" height="20" alt="SeaweedFS" title="SeaweedFS" /></a>  <a href="https://wasabi.com/cloud-object-storage"><img src="https://cdn.simpleicons.org/wasabi" width="20" height="20" alt="Wasabi" title="Wasabi" /></a>  <a href="https://www.backblaze.com/cloud-storage"><img src="https://cdn.simpleicons.org/backblaze" width="20" height="20" alt="Backblaze B2" title="Backblaze B2" /></a>  <a href="https://www.digitalocean.com/products/spaces"><img src="https://cdn.simpleicons.org/digitalocean" width="20" height="20" alt="DigitalOcean Spaces" title="DigitalOcean Spaces" /></a>  <a href="https://www.alibabacloud.com/product/oss"><img src="https://cdn.simpleicons.org/alibabacloud" width="20" height="20" alt="Alibaba Cloud OSS" title="Alibaba Cloud OSS" /></a>  <a href="https://www.tencentcloud.com/products/cos"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/tencent.png" width="20" height="20" alt="Tencent Cloud COS" title="Tencent Cloud COS" /></a>  <a href="https://www.scaleway.com/en/object-storage/"><img src="https://cdn.simpleicons.org/scaleway" width="20" height="20" alt="Scaleway" title="Scaleway" /></a>  <a href="https://www.qingcloud.com/products/qingstor"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/qingstor.png" width="20" height="20" alt="QingStor" title="QingStor" /></a>  <a href="https://huggingface.co/docs/hub/storage-buckets"><img src="https://cdn.simpleicons.org/huggingface" width="20" height="20" alt="Hugging Face Buckets" title="Hugging Face Buckets" /></a>  <a href="https://www.mongodb.com/docs/manual/core/gridfs/"><img src="https://cdn.simpleicons.org/mongodb" width="20" height="20" alt="GridFS" title="GridFS" /></a> |
139
+ | **Files and Documents** | <a href="https://workspace.google.com/products/drive/"><img src="https://cdn.simpleicons.org/googledrive" width="20" height="20" alt="Google Drive" title="Google Drive" /></a>  <a href="https://docs.google.com"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/google-docs.svg" width="14" height="20" alt="Google Docs" title="Google Docs" /></a>  <a href="https://sheets.google.com"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/google-sheets.svg" width="15" height="20" alt="Google Sheets" title="Google Sheets" /></a>  <a href="https://slides.google.com"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/google-slides.svg" width="15" height="20" alt="Google Slides" title="Google Slides" /></a>  <a href="https://www.microsoft.com/microsoft-365/onedrive/online-cloud-storage"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/microsoft-onedrive.svg" width="30" height="20" alt="OneDrive" title="OneDrive" /></a>  <a href="https://www.microsoft.com/microsoft-365/sharepoint/collaboration"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/microsoft-sharepoint.svg" width="20" height="20" alt="SharePoint" title="SharePoint" /></a>  <a href="https://www.box.com"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/box.svg" width="20" height="20" alt="Box" title="Box" /></a>  <a href="https://www.dropbox.com"><img src="https://cdn.simpleicons.org/dropbox" width="20" height="20" alt="Dropbox" title="Dropbox" /></a>  <a href="https://nextcloud.com/files/"><img src="https://cdn.simpleicons.org/nextcloud" width="20" height="20" alt="Nextcloud" title="Nextcloud" /></a> |
140
+ | **Messaging and Work** | <a href="https://slack.com"><img src="https://api.iconify.design/logos/slack-icon.svg" width="20" height="20" alt="Slack" title="Slack" /></a>  <a href="https://discord.com"><img src="https://cdn.simpleicons.org/discord" width="20" height="20" alt="Discord" title="Discord" /></a>  <a href="https://mail.google.com"><img src="https://cdn.simpleicons.org/gmail" width="20" height="20" alt="Gmail" title="Gmail" /></a>  <a href="https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol"><img src="https://api.iconify.design/lucide/mail.svg?color=%23888888" width="20" height="20" alt="IMAP / SMTP email" title="IMAP / SMTP email" /></a>  <a href="https://github.com"><img src="https://cdn.simpleicons.org/github/181717/e6edf3" width="20" height="20" alt="GitHub" title="GitHub" /></a>  <a href="https://linear.app"><img src="https://cdn.simpleicons.org/linear" width="20" height="20" alt="Linear" title="Linear" /></a>  <a href="https://www.notion.so"><img src="https://cdn.simpleicons.org/notion/000000/e6edf3" width="20" height="20" alt="Notion" title="Notion" /></a>  <a href="https://trello.com"><img src="https://cdn.simpleicons.org/trello" width="20" height="20" alt="Trello" title="Trello" /></a>  <a href="https://workspace.google.com/products/calendar/"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/google-calendar.svg" width="20" height="20" alt="Google Calendar" title="Google Calendar" /></a> |
141
+ | **Databases and Data Platforms** | <a href="https://www.postgresql.org"><img src="https://cdn.simpleicons.org/postgresql" width="20" height="20" alt="PostgreSQL" title="PostgreSQL" /></a>  <a href="https://www.mongodb.com"><img src="https://cdn.simpleicons.org/mongodb" width="20" height="20" alt="MongoDB" title="MongoDB" /></a>  <a href="https://redis.io"><img src="https://cdn.simpleicons.org/redis" width="20" height="20" alt="Redis" title="Redis" /></a> <a href="https://upstash.com"><img src="https://cdn.simpleicons.org/upstash" width="20" height="20" alt="Upstash Redis" title="Upstash Redis" /></a>  <a href="https://lancedb.com"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/lancedb.png" width="20" height="20" alt="LanceDB" title="LanceDB" /></a>  <a href="https://qdrant.tech"><img src="https://cdn.simpleicons.org/qdrant" width="20" height="20" alt="Qdrant" title="Qdrant" /></a>  <a href="https://www.trychroma.com"><img src="https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/svg/chroma.svg" width="31" height="20" alt="Chroma" title="Chroma" /></a>  <a href="https://mem0.ai"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/mem0.svg" width="20" height="20" alt="Mem0" title="Mem0" /></a>  <a href="https://huggingface.co/datasets"><img src="https://cdn.simpleicons.org/huggingface" width="20" height="20" alt="Hugging Face Datasets" title="Hugging Face Datasets" /></a>  <a href="https://huggingface.co/models"><img src="https://cdn.simpleicons.org/huggingface" width="20" height="20" alt="Hugging Face Models" title="Hugging Face Models" /></a>  <a href="https://huggingface.co/spaces"><img src="https://cdn.simpleicons.org/huggingface" width="20" height="20" alt="Hugging Face Spaces" title="Hugging Face Spaces" /></a>  <a href="https://docs.databricks.com/aws/en/volumes/"><img src="https://cdn.simpleicons.org/databricks" width="20" height="20" alt="Databricks Volumes" title="Databricks Volumes" /></a>  <a href="https://dify.ai"><img src="https://cdn.simpleicons.org/dify" width="20" height="20" alt="Dify" title="Dify" /></a> |
142
+ | **Observability** | <a href="https://langfuse.com"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/langfuse-logo.svg" width="20" height="20" alt="Langfuse" title="Langfuse" /></a>  <a href="https://www.jaegertracing.io"><img src="https://cdn.simpleicons.org/jaeger" width="20" height="20" alt="Jaeger" title="Jaeger" /></a> |
143
+ | **Local and Remote** | <a href="https://en.wikipedia.org/wiki/Random-access_memory"><img src="https://api.iconify.design/lucide/memory-stick.svg?color=%23888888" width="20" height="20" alt="RAM" title="RAM" /></a>  <a href="https://en.wikipedia.org/wiki/File_system"><img src="https://api.iconify.design/lucide/hard-drive.svg?color=%23888888" width="20" height="20" alt="Disk" title="Disk" /></a>  <a href="https://developer.mozilla.org/en-US/docs/Web/API/File_System_API/Origin_private_file_system"><img src="https://api.iconify.design/lucide/folder-lock.svg?color=%23888888" width="20" height="20" alt="OPFS" title="OPFS" /></a>  <a href="https://en.wikipedia.org/wiki/Secure_Shell"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/ssh-logo.svg" width="20" height="20" alt="SSH" title="SSH" /></a> |
144
+
145
+ Agents reach it through the Python and TypeScript SDKs, the `mirage` CLI, or a real
146
+ mountpoint over FUSE and FSKit, then work it with the unix tools they already know,
147
+ like `ls`, `grep`, `find` and `jq`.
148
+
149
+ ## Virtual Command Line Tool
150
+
151
+ These command line tools are virtualized: [Mirage](https://www.strukto.ai/mirage) answers `git`, `slack` or `ntn`
152
+ itself, so an agent drives the service without that program being installed on the
153
+ machine. Each one mimics the real tool, so an agent that knows the CLI needs nothing
154
+ new. Because they are virtual, the same tool can be installed more than once under
155
+ different names, each with its own credentials, so every agent gets exactly the
156
+ accounts it is given.
157
+
158
+ | | CLIs |
159
+ | ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
160
+ | **Code** | <a href="https://git-scm.com"><img src="https://cdn.simpleicons.org/git" width="20" height="20" alt="git" title="git" /></a>  <a href="https://cli.github.com"><img src="https://cdn.simpleicons.org/github/181717/e6edf3" width="20" height="20" alt="gh" title="gh" /></a> |
161
+ | **Communication** | <a href="https://slack.com"><img src="https://api.iconify.design/logos/slack-icon.svg" width="20" height="20" alt="slack" title="slack" /></a>  <a href="https://discord.com"><img src="https://cdn.simpleicons.org/discord" width="20" height="20" alt="discord" title="discord" /></a>  <a href="https://github.com/pimalaya/himalaya"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/himalaya.png" width="20" height="20" alt="himalaya" title="himalaya" /></a> |
162
+ | **Work and Data** | <a href="https://linear.app"><img src="https://cdn.simpleicons.org/linear" width="20" height="20" alt="linear" title="linear" /></a>  <a href="https://www.notion.so"><img src="https://cdn.simpleicons.org/notion/000000/e6edf3" width="20" height="20" alt="ntn" title="ntn" /></a>  <a href="https://workspace.google.com"><img src="https://cdn.simpleicons.org/google" width="20" height="20" alt="gws" title="gws" /></a>  <a href="https://huggingface.co"><img src="https://cdn.simpleicons.org/huggingface" width="20" height="20" alt="hf" title="hf" /></a> |
163
+
164
+ ## Virtual Runtime
165
+
166
+ Runtimes are virtualized the same way, and not only for coding languages. Any
167
+ command on the line can be redirected to a configured runtime, so Python might
168
+ run in-process with [Monty](https://pydantic.dev/articles/pydantic-monty) while
169
+ another command, say `kubectl`, is sent to a remote machine over SSH. Which runtime
170
+ serves a given line can be decided by a
171
+ [scripted runtime router](https://docs.mirage.strukto.ai/home/policy/route-policy).
172
+
173
+ | | Runtimes |
174
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
175
+ | **Python** | <a href="https://pydantic.dev/articles/pydantic-monty"><img src="https://cdn.simpleicons.org/pydantic" width="20" height="20" alt="Monty" title="Monty" /></a>  <a href="https://wasi.dev"><img src="https://cdn.simpleicons.org/webassembly" width="20" height="20" alt="WASI CPython on wasmtime" title="WASI CPython on wasmtime" /></a>  <a href="https://pyodide.org"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/pyodide.svg" width="56" height="20" alt="Pyodide" title="Pyodide" /></a>  <a href="https://pypi.org/project/sandlock/"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/sandlock-logo.svg" width="20" height="20" alt="sandlock" title="sandlock" /></a>  <a href="https://www.python.org"><img src="https://cdn.simpleicons.org/python" width="20" height="20" alt="Host CPython" title="Host CPython" /></a> |
176
+ | **JavaScript** | <a href="https://docs.mirage.strukto.ai/home/setup/runtime/javascript"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/quickjs.png" width="20" height="20" alt="QuickJS, serving node and js" title="QuickJS, serving node and js" /></a> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript"><img src="https://cdn.simpleicons.org/javascript" width="20" height="20" alt="JavaScript" title="JavaScript" /></a> <a href="https://www.typescriptlang.org"><img src="https://cdn.simpleicons.org/typescript" width="20" height="20" alt="TypeScript" title="TypeScript" /></a> |
177
+ | **Sandboxes** | <a href="https://www.docker.com"><img src="https://cdn.simpleicons.org/docker" width="20" height="20" alt="Docker" title="Docker" /></a>  <a href="https://e2b.dev"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/e2b-logo.svg" width="20" height="20" alt="E2B" title="E2B" /></a>  <a href="https://www.daytona.io"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/daytona-logo.svg" width="20" height="20" alt="Daytona" title="Daytona" /></a>  <a href="https://smolmachines.com"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/smolvm-logo.svg" width="20" height="20" alt="smolVM" title="smolVM" /></a> <a href="https://github.com/apple/container"><img src="https://cdn.simpleicons.org/apple/000000/e6edf3" width="20" height="20" alt="Apple Container" title="Apple Container" /></a>  <a href="https://en.wikipedia.org/wiki/Secure_Shell"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/docs/images/ssh-logo.svg" width="20" height="20" alt="SSH" title="SSH" /></a> |
178
+
179
+ ## Security
180
+
181
+ A profile decides what a session may run and what it may see. Commands are governed
182
+ by customizable `allow`, `ask` and `deny` rules, and paths by `hide` and `show`, so a
183
+ hidden file is not merely unreadable but absent from the filesystem the agent sees.
184
+ For anything those rules cannot express, a profile can name a policy script that runs
185
+ at the gate on every command and answers allow, deny or ask itself, though like every
186
+ rule it can only restrict and never grant. Separately, a host can register its own
187
+ policies on the [policy engine](https://docs.mirage.strukto.ai/home/policy/policies), an
188
+ ordered stack the workspace consults on every command, VFS op and session write. See
189
+ the [policy docs](https://docs.mirage.strukto.ai/home/policy/overview).
190
+
191
+ ## Authentication
192
+
193
+ Credentials and authentication integrate with the stores secrets already live in,
194
+ including AWS Secrets Manager, 1Password, Auth0 and dotenv, so an environment variable
195
+ in Mirage can resolve straight to a credential held in one of them.
196
+
197
+ | | Sources |
198
+ | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
199
+ | **Built in** | <a href="https://en.wikipedia.org/wiki/Environment_variable"><img src="https://raw.githubusercontent.com/strukto-ai/mirage/main/assets/icons/terminal.svg" width="20" height="20" alt="Environment" title="Environment" /></a> <a href="https://www.dotenv.org"><img src="https://cdn.simpleicons.org/dotenv" width="20" height="20" alt="dotenv" title="dotenv" /></a> <a href="https://aws.amazon.com/secrets-manager/"><img src="https://api.iconify.design/logos/aws-secrets-manager.svg" width="20" height="20" alt="AWS Secrets Manager" title="AWS Secrets Manager" /></a> |
200
+ | **Custom** | <a href="https://1password.com"><img src="https://cdn.simpleicons.org/1password" width="20" height="20" alt="1Password" title="1Password" /></a> <a href="https://auth0.com"><img src="https://cdn.simpleicons.org/auth0" width="20" height="20" alt="Auth0" title="Auth0" /></a> |
201
+
202
+ ## Installation
203
+
204
+ - **Python** ≥ 3.12 for the `mirage-ai` package and the `mirage` CLI
205
+ - **Node.js** 22.20+ on Node 22, 24.12+ on Node 24, or 25+ for the TypeScript SDK
206
+
207
+ ### Python
208
+
209
+ ```bash
210
+ uv add mirage-ai # installs the `mirage` library and the `mirage` CLI binary
211
+ uv add 'mirage-ai[openai]' # OpenAI Agents adapter; each agent framework is an extra
212
+ ```
213
+
214
+ ### TypeScript
215
+
216
+ ```bash
217
+ npm install @struktoai/mirage-node # Node.js servers and CLIs
218
+ npm install @struktoai/mirage-browser # browser / edge runtimes
219
+ npm install @struktoai/mirage-vercel # Vercel AI adapter; each agent framework has its own package
220
+ ```
221
+
222
+ Both runtime packages pull in `@struktoai/mirage-core` automatically.
223
+
224
+ ### CLI
225
+
226
+ ```bash
227
+ npm install -g @struktoai/mirage-cli
228
+ # or
229
+ uvx --from mirage-ai mirage
230
+ # or
231
+ npx @struktoai/mirage-cli
232
+ ```
233
+
234
+ To get started, see the quickstarts for
235
+ [Python](https://docs.mirage.strukto.ai/python/quickstart),
236
+ [TypeScript](https://docs.mirage.strukto.ai/typescript/quickstart) and the
237
+ [CLI](https://docs.mirage.strukto.ai/home/access/cli).
238
+
239
+ ## Scriptable Policy
240
+
241
+ A profile can name policy scripts for what its rules cannot express. A script
242
+ reads the command as JSON, can open the files it names, and prints a deny, an
243
+ ask or nothing. This one disables `rm`, and a Python script whose code
244
+ deletes files:
245
+
246
+ ```python
247
+ import json, os
248
+
249
+ ctx = json.loads(os.environ["MIRAGE_POLICY_CTX"])
250
+
251
+
252
+ def deletes(path):
253
+ try:
254
+ code = open(path).read()
255
+ except OSError:
256
+ return False
257
+ return any(call in code for call in ("os.remove", "os.unlink", "shutil.rmtree"))
258
+
259
+
260
+ if ctx["command"] == "rm" or (
261
+ ctx["command"].startswith("python") and any(deletes(p) for p in ctx["paths"])
262
+ ):
263
+ print(json.dumps({"kind": "deny", "reason": "deleting files is disabled"}))
264
+ ```
265
+
266
+ Register it in a profile, here to run on Monty before every command:
267
+
268
+ ```python
269
+ ws = Workspace(
270
+ {"/s3": (S3VFS(S3Config(bucket="my-bucket")), MountMode.WRITE)},
271
+ profiles={
272
+ "analyst": {
273
+ "policy": {
274
+ "pre_command": [{"script": ScriptSource(Path("guard.py").read_text()), "runtime": "monty"}],
275
+ },
276
+ },
277
+ },
278
+ profile="analyst",
279
+ )
280
+ ```
281
+
282
+ ```console
283
+ $ cat /s3/clean.py
284
+ import os
285
+ os.remove("/s3/report.txt")
286
+ $ rm /s3/report.txt
287
+ rm: Permission denied
288
+ $ python3 /s3/clean.py
289
+ python3: Permission denied
290
+ ```
291
+
292
+ See [policy scripts](https://docs.mirage.strukto.ai/home/policy/scripts) for
293
+ the other stages a script can answer at.
294
+
295
+ ## Embedded Terminal
296
+
297
+ Most of the time an agent does not need a sandbox, only a terminal-like
298
+ interface, and Mirage embeds one in an application server. Each terminal is a
299
+ Mirage session with its own working directory, environment and history, and Python
300
+ runs in-process on Monty, so a terminal starts with no container or VM. Here
301
+ it is in Express; the FastAPI version is in the
302
+ [docs](https://docs.mirage.strukto.ai/home/examples/embedded-terminal).
303
+
304
+ ```bash
305
+ npm install @struktoai/mirage-node @pydantic/monty express
306
+ ```
307
+
308
+ ```ts
309
+ import express from 'express'
310
+ import { MontyRuntime, MountMode, RAMVFS, Workspace } from '@struktoai/mirage-node'
311
+
312
+ const ws = new Workspace(
313
+ { '/work': new RAMVFS() },
314
+ { mode: MountMode.EXEC, runtimes: [new MontyRuntime({ captures: ['python', 'python3'] })] },
315
+ )
316
+ const app = express()
317
+ app.use(express.json())
318
+
319
+ app.post('/sessions/:id', (req, res) => {
320
+ ws.createSession(req.params.id)
321
+ res.sendStatus(201)
322
+ })
323
+
324
+ app.post('/sessions/:id/run', async (req, res) => {
325
+ const r = await ws.shell(req.body.command, { sessionId: req.params.id })
326
+ res.json({ stdout: r.stdoutText, stderr: r.stderrText, exitCode: r.exitCode })
327
+ })
328
+
329
+ app.listen(3000, '127.0.0.1')
330
+ ```
331
+
332
+ ## Contributors
333
+
334
+ Thanks to everyone who has contributed to Mirage.
335
+
336
+ <a href="https://github.com/strukto-ai/mirage/graphs/contributors">
337
+ <img src="https://contrib.rocks/image?repo=strukto-ai/mirage" alt="Mirage contributors" />
338
+ </a>
@@ -0,0 +1,16 @@
1
+ import { BetaRunnableTool } from '@anthropic-ai/sdk/lib/tools/BetaRunnableTool';
2
+ import { MirageToolOperationsOptions } from '@struktoai/mirage-core/workspace/tools/tool_operations';
3
+ import { Workspace } from '@struktoai/mirage-core/workspace/workspace/workspace';
4
+
5
+ /**
6
+ * The agent toolset's file and shell tools, run in a Mirage session, for a
7
+ * self-hosted environment's `new EnvironmentWorker({ tools })`: `bash`,
8
+ * `read`, `write`, `edit`, `glob` and `grep` answer the agent's calls
9
+ * through the session's own tools, so its profile, mounts and policies
10
+ * apply. A tool every call of which the profile would refuse is left out. A
11
+ * relative path resolves against the session's working directory, as
12
+ * `bash` sees it.
13
+ */
14
+ declare function mirageTools(workspace: Workspace, options?: MirageToolOperationsOptions): BetaRunnableTool[];
15
+
16
+ export { mirageTools };
package/dist/index.js ADDED
@@ -0,0 +1,152 @@
1
+ // src/tools.ts
2
+ import { betaTool } from "@anthropic-ai/sdk/helpers/beta/json-schema";
3
+ import { ToolError } from "@anthropic-ai/sdk/lib/tools/ToolError";
4
+ import {
5
+ MirageToolOperations
6
+ } from "@struktoai/mirage-core/workspace/tools/tool_operations";
7
+ import { Session } from "@struktoai/mirage-core/workspace/workspace/workspace";
8
+ function answer(result) {
9
+ const text = result.content.map((c) => c.text).join("");
10
+ if (result.isError === true) throw new ToolError(text);
11
+ return text;
12
+ }
13
+ function mirageTools(workspace, options = {}) {
14
+ const session = new Session(workspace, options.sessionId ?? null);
15
+ const ops = options.staleWriteProtection === false ? new MirageToolOperations(session, false) : session.tools;
16
+ const tools = [
17
+ [
18
+ "shell",
19
+ betaTool({
20
+ name: "bash",
21
+ description: "Run a command in the Mirage session.",
22
+ inputSchema: {
23
+ type: "object",
24
+ properties: {
25
+ command: { type: "string" },
26
+ restart: { type: "boolean" },
27
+ timeout_ms: { type: "integer" }
28
+ }
29
+ },
30
+ run: async ({ command, restart, timeout_ms }) => {
31
+ if (restart === true) {
32
+ throw new ToolError(
33
+ "bash: restart is not supported; the Mirage session keeps its working directory and variables"
34
+ );
35
+ }
36
+ if (command === void 0 || command === "") {
37
+ throw new ToolError("bash: command is required");
38
+ }
39
+ const signal = timeout_ms === void 0 ? void 0 : AbortSignal.timeout(timeout_ms);
40
+ const timedOut = new ToolError(`bash: timed out after ${String(timeout_ms)} ms`);
41
+ let result;
42
+ try {
43
+ result = await ops.call("shell", { command }, signal);
44
+ } catch (err) {
45
+ if (signal?.aborted === true) throw timedOut;
46
+ throw err;
47
+ }
48
+ if (signal?.aborted === true) throw timedOut;
49
+ return answer(result);
50
+ }
51
+ })
52
+ ],
53
+ [
54
+ "read",
55
+ betaTool({
56
+ name: "read",
57
+ description: "Read a file in the Mirage session.",
58
+ inputSchema: {
59
+ type: "object",
60
+ properties: {
61
+ file_path: { type: "string" },
62
+ view_range: { type: "array", items: { type: "integer" } }
63
+ },
64
+ required: ["file_path"]
65
+ },
66
+ run: async ({ file_path, view_range }) => {
67
+ const args = { path: file_path };
68
+ if (view_range !== void 0 && view_range.length > 0) {
69
+ const [first, last] = view_range;
70
+ if (view_range.length !== 2 || first === void 0 || last === void 0) {
71
+ throw new ToolError("read: view_range must be [start_line, end_line]");
72
+ }
73
+ const start = Math.max(0, first - 1);
74
+ args.offset = start;
75
+ if (last > 0) args.limit = Math.max(1, last - start);
76
+ }
77
+ return answer(await ops.call("read", args));
78
+ }
79
+ })
80
+ ],
81
+ [
82
+ "write",
83
+ betaTool({
84
+ name: "write",
85
+ description: "Write a file in the Mirage session.",
86
+ inputSchema: {
87
+ type: "object",
88
+ properties: { file_path: { type: "string" }, content: { type: "string" } },
89
+ required: ["file_path", "content"]
90
+ },
91
+ run: async ({ file_path, content }) => answer(await ops.call("write", { path: file_path, content }))
92
+ })
93
+ ],
94
+ [
95
+ "edit",
96
+ betaTool({
97
+ name: "edit",
98
+ description: "Replace text in a file in the Mirage session.",
99
+ inputSchema: {
100
+ type: "object",
101
+ properties: {
102
+ file_path: { type: "string" },
103
+ old_string: { type: "string" },
104
+ new_string: { type: "string" },
105
+ replace_all: { type: "boolean" }
106
+ },
107
+ required: ["file_path", "old_string", "new_string"]
108
+ },
109
+ run: async ({ file_path, old_string, new_string, replace_all }) => answer(
110
+ await ops.call("edit", {
111
+ path: file_path,
112
+ old_string,
113
+ new_string,
114
+ replace_all: replace_all === true
115
+ })
116
+ )
117
+ })
118
+ ],
119
+ [
120
+ "glob",
121
+ betaTool({
122
+ name: "glob",
123
+ description: "List files matching a glob pattern in the Mirage session.",
124
+ inputSchema: {
125
+ type: "object",
126
+ properties: { pattern: { type: "string" }, path: { type: "string" } },
127
+ required: ["pattern"]
128
+ },
129
+ run: async ({ pattern, path }) => answer(await ops.call("glob", { pattern, path: path ?? "." }))
130
+ })
131
+ ],
132
+ [
133
+ "grep",
134
+ betaTool({
135
+ name: "grep",
136
+ description: "Search file contents in the Mirage session.",
137
+ inputSchema: {
138
+ type: "object",
139
+ properties: { pattern: { type: "string" }, path: { type: "string" } },
140
+ required: ["pattern"]
141
+ },
142
+ run: async ({ pattern, path }) => answer(await ops.call("grep", { pattern, path: path ?? "." }))
143
+ })
144
+ ]
145
+ ];
146
+ const names = ops.names();
147
+ return tools.filter(([name]) => names.includes(name)).map(([, tool]) => tool);
148
+ }
149
+ export {
150
+ mirageTools
151
+ };
152
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tools.ts"],"sourcesContent":["// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========\n\nimport { betaTool } from '@anthropic-ai/sdk/helpers/beta/json-schema'\nimport type { BetaRunnableTool } from '@anthropic-ai/sdk/lib/tools/BetaRunnableTool'\nimport { ToolError } from '@anthropic-ai/sdk/lib/tools/ToolError'\nimport {\n MirageToolOperations,\n type MirageToolOperationsOptions,\n type ToolResult,\n} from '@struktoai/mirage-core/workspace/tools/tool_operations'\nimport type { Workspace } from '@struktoai/mirage-core/workspace/workspace/workspace'\nimport { Session } from '@struktoai/mirage-core/workspace/workspace/workspace'\n\nfunction answer(result: ToolResult): string {\n const text = result.content.map((c) => c.text).join('')\n if (result.isError === true) throw new ToolError(text)\n return text\n}\n\n/**\n * The agent toolset's file and shell tools, run in a Mirage session, for a\n * self-hosted environment's `new EnvironmentWorker({ tools })`: `bash`,\n * `read`, `write`, `edit`, `glob` and `grep` answer the agent's calls\n * through the session's own tools, so its profile, mounts and policies\n * apply. A tool every call of which the profile would refuse is left out. A\n * relative path resolves against the session's working directory, as\n * `bash` sees it.\n */\nexport function mirageTools(\n workspace: Workspace,\n options: MirageToolOperationsOptions = {},\n): BetaRunnableTool[] {\n const session = new Session(workspace, options.sessionId ?? null)\n const ops =\n options.staleWriteProtection === false\n ? new MirageToolOperations(session, false)\n : session.tools\n const tools: [string, BetaRunnableTool][] = [\n [\n 'shell',\n betaTool({\n name: 'bash',\n description: 'Run a command in the Mirage session.',\n inputSchema: {\n type: 'object',\n properties: {\n command: { type: 'string' },\n restart: { type: 'boolean' },\n timeout_ms: { type: 'integer' },\n },\n },\n run: async ({ command, restart, timeout_ms }) => {\n if (restart === true) {\n throw new ToolError(\n 'bash: restart is not supported; the Mirage session keeps its working directory and variables',\n )\n }\n if (command === undefined || command === '') {\n throw new ToolError('bash: command is required')\n }\n const signal = timeout_ms === undefined ? undefined : AbortSignal.timeout(timeout_ms)\n const timedOut = new ToolError(`bash: timed out after ${String(timeout_ms)} ms`)\n let result: ToolResult\n try {\n result = await ops.call('shell', { command }, signal)\n } catch (err) {\n if (signal?.aborted === true) throw timedOut\n throw err\n }\n if (signal?.aborted === true) throw timedOut\n return answer(result)\n },\n }),\n ],\n [\n 'read',\n betaTool({\n name: 'read',\n description: 'Read a file in the Mirage session.',\n inputSchema: {\n type: 'object',\n properties: {\n file_path: { type: 'string' },\n view_range: { type: 'array', items: { type: 'integer' } },\n },\n required: ['file_path'],\n },\n run: async ({ file_path, view_range }) => {\n const args: Record<string, string | number> = { path: file_path }\n if (view_range !== undefined && view_range.length > 0) {\n const [first, last] = view_range\n if (view_range.length !== 2 || first === undefined || last === undefined) {\n throw new ToolError('read: view_range must be [start_line, end_line]')\n }\n const start = Math.max(0, first - 1)\n args.offset = start\n if (last > 0) args.limit = Math.max(1, last - start)\n }\n return answer(await ops.call('read', args))\n },\n }),\n ],\n [\n 'write',\n betaTool({\n name: 'write',\n description: 'Write a file in the Mirage session.',\n inputSchema: {\n type: 'object',\n properties: { file_path: { type: 'string' }, content: { type: 'string' } },\n required: ['file_path', 'content'],\n },\n run: async ({ file_path, content }) =>\n answer(await ops.call('write', { path: file_path, content })),\n }),\n ],\n [\n 'edit',\n betaTool({\n name: 'edit',\n description: 'Replace text in a file in the Mirage session.',\n inputSchema: {\n type: 'object',\n properties: {\n file_path: { type: 'string' },\n old_string: { type: 'string' },\n new_string: { type: 'string' },\n replace_all: { type: 'boolean' },\n },\n required: ['file_path', 'old_string', 'new_string'],\n },\n run: async ({ file_path, old_string, new_string, replace_all }) =>\n answer(\n await ops.call('edit', {\n path: file_path,\n old_string,\n new_string,\n replace_all: replace_all === true,\n }),\n ),\n }),\n ],\n [\n 'glob',\n betaTool({\n name: 'glob',\n description: 'List files matching a glob pattern in the Mirage session.',\n inputSchema: {\n type: 'object',\n properties: { pattern: { type: 'string' }, path: { type: 'string' } },\n required: ['pattern'],\n },\n run: async ({ pattern, path }) =>\n answer(await ops.call('glob', { pattern, path: path ?? '.' })),\n }),\n ],\n [\n 'grep',\n betaTool({\n name: 'grep',\n description: 'Search file contents in the Mirage session.',\n inputSchema: {\n type: 'object',\n properties: { pattern: { type: 'string' }, path: { type: 'string' } },\n required: ['pattern'],\n },\n run: async ({ pattern, path }) =>\n answer(await ops.call('grep', { pattern, path: path ?? '.' })),\n }),\n ],\n ]\n const names = ops.names()\n return tools.filter(([name]) => names.includes(name)).map(([, tool]) => tool)\n}\n"],"mappings":"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","names":[]}
package/package.json CHANGED
@@ -1,6 +1,59 @@
1
1
  {
2
2
  "name": "@struktoai/mirage-claude-managed-agents",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.8",
4
+ "description": "Make a Mirage workspace the self-hosted environment of an agent on Claude Managed Agents",
5
+ "keywords": [
6
+ "mirage",
7
+ "claude-managed-agents",
8
+ "ai-agents",
9
+ "virtual-filesystem"
10
+ ],
11
+ "homepage": "https://github.com/strukto-ai/mirage#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/strukto-ai/mirage/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/strukto-ai/mirage.git",
18
+ "directory": "typescript/packages/claude-managed-agents"
19
+ },
20
+ "license": "Apache-2.0",
21
+ "author": "Zecheng Zhang <zecheng@strukto.ai>",
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "type": "module",
26
+ "engines": {
27
+ "node": "^22.20 || ^24.12 || >=25"
28
+ },
29
+ "main": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "dependencies": {
41
+ "@struktoai/mirage-core": "0.0.8"
42
+ },
43
+ "peerDependencies": {
44
+ "@anthropic-ai/sdk": ">=0.124.0 <2"
45
+ },
46
+ "devDependencies": {
47
+ "@anthropic-ai/sdk": "^1.3.0",
48
+ "@types/node": "^22.0.0",
49
+ "tsup": "^8.5.0",
50
+ "typescript": "^6.0.0",
51
+ "vitest": "^4.1.12",
52
+ "@struktoai/mirage-node": "0.0.8"
53
+ },
54
+ "scripts": {
55
+ "build": "tsup --config ../../tsup.base.config.ts",
56
+ "test": "vitest run",
57
+ "typecheck": "tsc --noEmit"
58
+ }
6
59
  }