mastracode 0.27.0-alpha.6 → 0.27.0-alpha.7
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/CHANGELOG.md +89 -0
- package/README.md +123 -0
- package/dist/{acp-GVDPJUYP.cjs → acp-5AMWEFJ3.cjs} +6 -6
- package/dist/{acp-GVDPJUYP.cjs.map → acp-5AMWEFJ3.cjs.map} +1 -1
- package/dist/{acp-EAQUS3AT.js → acp-UBTAGUFO.js} +4 -4
- package/dist/{acp-EAQUS3AT.js.map → acp-UBTAGUFO.js.map} +1 -1
- package/dist/agents/workspace.d.ts +2 -2
- package/dist/agents/workspace.d.ts.map +1 -1
- package/dist/{chunk-BULVNQ2P.cjs → chunk-6HMHCNGR.cjs} +2 -2
- package/dist/chunk-6HMHCNGR.cjs.map +1 -0
- package/dist/{chunk-HZIMBYEM.js → chunk-CBYIU42Y.js} +6 -6
- package/dist/{chunk-HZIMBYEM.js.map → chunk-CBYIU42Y.js.map} +1 -1
- package/dist/{chunk-NB52GKOT.js → chunk-GAPPKMQT.js} +3 -3
- package/dist/{chunk-NB52GKOT.js.map → chunk-GAPPKMQT.js.map} +1 -1
- package/dist/{chunk-Z5EMG7I2.js → chunk-GETSQXPO.js} +2 -2
- package/dist/chunk-GETSQXPO.js.map +1 -0
- package/dist/{chunk-2NKDVAOP.cjs → chunk-P5J7PK3B.cjs} +1493 -137
- package/dist/chunk-P5J7PK3B.cjs.map +1 -0
- package/dist/{chunk-RNIUWUNX.cjs → chunk-SDB3NVRU.cjs} +966 -966
- package/dist/{chunk-RNIUWUNX.cjs.map → chunk-SDB3NVRU.cjs.map} +1 -1
- package/dist/{chunk-22B6MUSN.js → chunk-VTR4E2PD.js} +1391 -53
- package/dist/chunk-VTR4E2PD.js.map +1 -0
- package/dist/{chunk-JEIKVC6A.cjs → chunk-WX46SWL3.cjs} +12 -12
- package/dist/{chunk-JEIKVC6A.cjs.map → chunk-WX46SWL3.cjs.map} +1 -1
- package/dist/cli.cjs +24 -603
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +9 -589
- package/dist/cli.js.map +1 -1
- package/dist/headless/cli.d.ts +42 -0
- package/dist/headless/cli.d.ts.map +1 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.d.ts.map +1 -0
- package/dist/headless/format.d.ts +38 -0
- package/dist/headless/format.d.ts.map +1 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.d.ts.map +1 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.d.ts.map +1 -0
- package/dist/headless/types.d.ts +134 -0
- package/dist/headless/types.d.ts.map +1 -0
- package/dist/headless.cjs +76 -0
- package/dist/headless.cjs.map +1 -0
- package/dist/headless.js +3 -0
- package/dist/headless.js.map +1 -0
- package/dist/index.cjs +47 -7
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/schema.d.ts +15 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/storage-MMPSGE6N.js +3 -0
- package/dist/{storage-OFG4C77R.js.map → storage-MMPSGE6N.js.map} +1 -1
- package/dist/storage-ZNRO3RDU.cjs +24 -0
- package/dist/{storage-RIEW2ZEA.cjs.map → storage-ZNRO3RDU.cjs.map} +1 -1
- package/dist/tui.cjs +19 -19
- package/dist/tui.js +2 -2
- package/dist/utils/project.d.ts +8 -0
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/storage-factory.d.ts +20 -0
- package/dist/utils/storage-factory.d.ts.map +1 -1
- package/package.json +37 -15
- package/dist/chunk-22B6MUSN.js.map +0 -1
- package/dist/chunk-2NKDVAOP.cjs.map +0 -1
- package/dist/chunk-BULVNQ2P.cjs.map +0 -1
- package/dist/chunk-Z5EMG7I2.js.map +0 -1
- package/dist/headless.d.ts +0 -38
- package/dist/headless.d.ts.map +0 -1
- package/dist/storage-OFG4C77R.js +0 -3
- package/dist/storage-RIEW2ZEA.cjs +0 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,94 @@
|
|
|
1
1
|
# mastracode
|
|
2
2
|
|
|
3
|
+
## 0.27.0-alpha.7
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Reworked headless mode into a real programmatic API. You can now run MastraCode from Node/CI code with `runMC({ controller, session, prompt })`, which returns a handle that streams live events as an async-iterable and resolves to a typed result with status, text, usage, tool calls, and an exit code — it never calls `process.exit` or writes to global streams. The CLI is now a thin adapter over the same runner. ([#18680](https://github.com/mastra-ai/mastra/pull/18680))
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createMastraCode, runMC } from 'mastracode';
|
|
11
|
+
|
|
12
|
+
const { controller, session } = await createMastraCode({ settingsPath });
|
|
13
|
+
|
|
14
|
+
const run = runMC({ controller, session, prompt: 'Fix the failing test' });
|
|
15
|
+
for await (const event of run) {
|
|
16
|
+
// optional: react to live progress events
|
|
17
|
+
}
|
|
18
|
+
const result = await run.result;
|
|
19
|
+
process.exitCode = result.exitCode; // 0 success, 1 error/aborted/max-turns, 2 timeout
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Approvals and suspensions are resolved by a pluggable policy (default keeps the previous auto-approve behavior); a built-in `denyPolicy` plus `permissionModeToPolicy` are exported, and a new `--permission-mode {auto|deny}` flag selects between them. A new `--max-turns` flag (and `maxTurns` option) caps assistant turns and reports a `max_turns` status with exit code 1 when the cap is hit mid-task.
|
|
23
|
+
|
|
24
|
+
Breaking changes / migration:
|
|
25
|
+
- Output flags consolidated: the `--format` and `--output-format` flags are replaced by a single `--output` flag with values `human`, `json`, or `jsonl`.
|
|
26
|
+
- Before: `mastracode --prompt "..." --output-format json`
|
|
27
|
+
- After: `mastracode --prompt "..." --output json`
|
|
28
|
+
- Programmatic entry point changed from the old `runHeadless`/`headlessMain` to `runMC` (pure runner) and `runMCCli` (CLI adapter). `runMC` takes an already-built `controller` + `session` from `createMastraCode` and returns a result object instead of only an exit code.
|
|
29
|
+
|
|
30
|
+
- Turned MastraCode Web into a multi-org cloud coding service. When WorkOS auth and a GitHub App are configured, a team can sign in, connect their repos, and run coding agents that branch, commit, push, and open pull requests — all from isolated cloud sandboxes. When the relevant environment variables are absent, the server and UI behave exactly as before (local-path projects, single shared store, no auth UI), so this is fully opt-in. ([#18567](https://github.com/mastra-ai/mastra/pull/18567))
|
|
31
|
+
|
|
32
|
+
**Authentication (WorkOS AuthKit).** Setting `WORKOS_API_KEY` and `WORKOS_CLIENT_ID` protects every route: unauthenticated visitors are redirected to the WorkOS hosted login, signed-in users get an encrypted session, expired sessions bounce back to login, and the sidebar shows the signed-in email with a Sign out button. Users with no WorkOS organization get a personal org bootstrapped on first authenticated use (idempotent, with recovery from partial creations), so personal accounts can use org-scoped features without hand-creating an org.
|
|
33
|
+
|
|
34
|
+
**Org-owned GitHub projects.** With the GitHub App env vars set (`GITHUB_APP_ID`, `GITHUB_APP_PRIVATE_KEY`, `GITHUB_APP_CLIENT_ID`, `GITHUB_APP_CLIENT_SECRET`, `GITHUB_APP_SLUG`, `APP_DATABASE_URL`), users install/connect the app, pick repos they can access, and turn each into a project. The installation and connected repos belong to the WorkOS organization; the same repo can be connected independently by different orgs with no cross-visibility. Each repo is materialized into an isolated cloud sandbox on open — cloned (or pulled) inside the sandbox with a short-lived installation token that never reaches the browser and is scrubbed from the remote afterward.
|
|
35
|
+
|
|
36
|
+
**Cloud coding-agent write-back.** From a connected repo, each user gets their own sandbox, git worktrees, and feature branches. The agent runs against the selected worktree (file edits and commands bind to its path) and can commit, push, and open pull requests via the in-sandbox `gh` CLI, authenticated with short-lived per-operation installation tokens. The sidebar shows a nested project → worktree → conversations tree with a "+ New worktree" affordance; conversations scope per worktree.
|
|
37
|
+
|
|
38
|
+
**Sandbox providers.** A provider is selected automatically: Railway when `RAILWAY_API_TOKEN` is set, otherwise a local provider that runs git directly on the host (single-user local dev only — no tenant isolation). `MASTRACODE_SANDBOX_PROVIDER` overrides explicitly. Idle sandboxes are torn down and re-provisioned on the next open; a per-replica live-sandbox cap (`MASTRACODE_MAX_SANDBOXES`) and a per-user teardown route bound resource use.
|
|
39
|
+
|
|
40
|
+
**Per-(org,user) state isolation.** Agent state (threads, messages, memory, recall vectors) is isolated by the `(organization, user)` pair, each backed by a dedicated libSQL database whose location is derived server-side from a hash of `(orgId, userId)` — never a client-supplied path. By default each tenant gets local libSQL files under `MASTRACODE_TENANT_DB_ROOT`; for hosted deployments, point each tenant at a remote libSQL/Turso database via `MASTRACODE_TENANT_DB_URL_TEMPLATE` (plus optional vector template and auth tokens).
|
|
41
|
+
|
|
42
|
+
**Sandbox isolation hardening.** Commands run in the local sandbox receive only a sanitized allow-list of environment variables (PATH/HOME/locale/git config), so server secrets such as `GITHUB_APP_PRIVATE_KEY`, `WORKOS_API_KEY`, and `APP_DATABASE_URL` are never exposed to code running against an untrusted checkout. Sandbox filesystem write operations (write/append/copy/move/mkdir) now verify the destination's real path — including a symlinked parent directory — stays within the workspace root, preventing a malicious repo's symlink from redirecting writes outside the sandbox.
|
|
43
|
+
|
|
44
|
+
**Multi-replica deployment hardening.** Per-(project,user) git writes are serialized across replicas with Postgres advisory locks (`MASTRACODE_DISTRIBUTED_LOCK`, on by default; requires `APP_DATABASE_URL`). OAuth/install state signing requires a replica-stable secret in multi-replica setups, in-memory tenant stacks are evicted by idle timeout and an LRU cap (`MASTRACODE_TENANT_IDLE_MINUTES`, `MASTRACODE_TENANT_MAX_APPS`), and `MASTRACODE_REQUIRE_REMOTE_TENANT_DB=1` fails startup when no shared remote tenant DB is configured.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Auth + GitHub App (opt-in)
|
|
48
|
+
WORKOS_API_KEY=sk_xxxxxxxx
|
|
49
|
+
WORKOS_CLIENT_ID=client_xxxxxxxx
|
|
50
|
+
GITHUB_APP_ID=123456
|
|
51
|
+
GITHUB_APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----"
|
|
52
|
+
GITHUB_APP_CLIENT_ID=Iv1.xxxxxxxx
|
|
53
|
+
GITHUB_APP_CLIENT_SECRET=xxxxxxxx
|
|
54
|
+
GITHUB_APP_SLUG=your-app-slug
|
|
55
|
+
APP_DATABASE_URL=postgres://user:pass@host:5432/mastracode_web
|
|
56
|
+
|
|
57
|
+
# Multi-replica hosted deployment
|
|
58
|
+
GITHUB_APP_WEBHOOK_SECRET=... # replica-stable state signing
|
|
59
|
+
MASTRACODE_DISTRIBUTED_LOCK=1 # cross-replica git write locks
|
|
60
|
+
MASTRACODE_REQUIRE_REMOTE_TENANT_DB=1 # require shared remote tenant DBs
|
|
61
|
+
MASTRACODE_TENANT_DB_URL_TEMPLATE=libsql://{id}-org.turso.io
|
|
62
|
+
MASTRACODE_TENANT_IDLE_MINUTES=30
|
|
63
|
+
MASTRACODE_TENANT_MAX_APPS=100
|
|
64
|
+
MASTRACODE_MAX_SANDBOXES=50
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Still deferred: collaboration within a project (multiple users sharing one worktree/sandbox/branch), org admin/roles and membership management, and org-level project deletion.
|
|
68
|
+
|
|
69
|
+
- Auto-provision a per-tenant Turso database in deployed MastraCode Web environments. ([#18690](https://github.com/mastra-ai/mastra/pull/18690))
|
|
70
|
+
|
|
71
|
+
Previously, hosting per-`(org, user)` agent state on Turso required each tenant's database to already exist at the URL produced by `MASTRACODE_TENANT_DB_URL_TEMPLATE`. There was no way to create those databases on demand, so the only zero-setup option was server-local libSQL files — which are ephemeral and not shared across replicas.
|
|
72
|
+
|
|
73
|
+
Setting `MASTRACODE_TURSO_PLATFORM_TOKEN` and `MASTRACODE_TURSO_ORG` now enables a third tenant-storage mode: the first time a tenant is seen, its own Turso database is created via the Turso Platform API (idempotent — an "already exists" race recovers the hostname via `databases.get`), a scoped auth token is minted, and the stable database-name/hostname mapping is persisted in the app Postgres (`tenant_databases` table, requires `APP_DATABASE_URL`). All replicas converge on the same database and cold starts never re-create it. Only the durable mapping is stored; the auth token is minted fresh per resolution, so no long-lived credential is persisted.
|
|
74
|
+
|
|
75
|
+
Resolution priority is: explicit `MASTRACODE_TENANT_DB_URL_TEMPLATE` → Turso auto-provisioning → local libSQL files. Turso provisioning also satisfies `MASTRACODE_REQUIRE_REMOTE_TENANT_DB=1`. The `@tursodatabase/api` client is loaded dynamically, so deployments that don't use Turso never pull it in at runtime.
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
MASTRACODE_TURSO_PLATFORM_TOKEN=... # Turso Platform API token
|
|
79
|
+
MASTRACODE_TURSO_ORG=my-org # org that owns provisioned databases
|
|
80
|
+
MASTRACODE_TURSO_GROUP=default # optional group (default "default")
|
|
81
|
+
APP_DATABASE_URL=postgres://... # required for the mapping table
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Patch Changes
|
|
85
|
+
|
|
86
|
+
- Updated dependencies [[`8be63b0`](https://github.com/mastra-ai/mastra/commit/8be63b015fb8d72cea1220f05e7dc3bb997cc249), [`ee14cae`](https://github.com/mastra-ai/mastra/commit/ee14cae244805783bde518a6142de28b744b169c), [`345eecc`](https://github.com/mastra-ai/mastra/commit/345eecce6ba519b5d987f0e10b5de4c8e5734580), [`ee14cae`](https://github.com/mastra-ai/mastra/commit/ee14cae244805783bde518a6142de28b744b169c)]:
|
|
87
|
+
- @mastra/core@1.48.0-alpha.7
|
|
88
|
+
- @mastra/server@1.48.0-alpha.7
|
|
89
|
+
- @mastra/hono@1.5.3-alpha.7
|
|
90
|
+
- @mastra/react@1.2.1-alpha.7
|
|
91
|
+
|
|
3
92
|
## 0.27.0-alpha.6
|
|
4
93
|
|
|
5
94
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -258,6 +258,129 @@ To save plans to a project-local directory instead, set the `MASTRA_PLANS_DIR` e
|
|
|
258
258
|
export MASTRA_PLANS_DIR=.mastracode/plans
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
+
### Web UI: optional auth & GitHub projects
|
|
262
|
+
|
|
263
|
+
The web UI (`mastracode web`) supports optional WorkOS authentication and a GitHub App
|
|
264
|
+
integration. Both are off by default — when their environment variables are absent the web UI
|
|
265
|
+
behaves exactly as before.
|
|
266
|
+
|
|
267
|
+
**WorkOS auth** — when `WORKOS_API_KEY` and `WORKOS_CLIENT_ID` are set, every route requires a
|
|
268
|
+
signed-in user (hosted login + encrypted session):
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
export WORKOS_API_KEY=...
|
|
272
|
+
export WORKOS_CLIENT_ID=...
|
|
273
|
+
export WORKOS_REDIRECT_URI=https://your-host/auth/callback # optional
|
|
274
|
+
export WORKOS_COOKIE_PASSWORD=... # optional (recommended in prod)
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
On first authenticated use, a user with no WorkOS organization is automatically given a personal
|
|
278
|
+
org (the org is created and the user added as a member), so org-scoped features work without
|
|
279
|
+
hand-creating an org in the WorkOS dashboard. The WorkOS API key must be allowed to create
|
|
280
|
+
organizations and memberships; if it isn't, bootstrap fails soft (logged) and the user keeps the
|
|
281
|
+
`organization_required` response.
|
|
282
|
+
|
|
283
|
+
**GitHub projects** — when the GitHub App variables are set _and_ WorkOS auth is enabled,
|
|
284
|
+
signed-in users can install the GitHub App, pick repositories, and turn each repo into a project.
|
|
285
|
+
The tenant boundary is the **WorkOS organization**: the GitHub App installation and the connected
|
|
286
|
+
project (repo) are owned by the org, while each user inside the org gets their own isolated
|
|
287
|
+
sandbox, worktrees, branches, and PRs against that repo. The **same repo can be connected
|
|
288
|
+
independently by different orgs** without ever seeing each other's projects, sandboxes, or state.
|
|
289
|
+
Personal accounts are bootstrapped into a personal org on first use (see above), so they can
|
|
290
|
+
connect GitHub projects too; users always get isolated agent state regardless. Repo and project
|
|
291
|
+
metadata persist in a separate application Postgres (`APP_DATABASE_URL`):
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
export GITHUB_APP_ID=...
|
|
295
|
+
export GITHUB_APP_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----"
|
|
296
|
+
export GITHUB_APP_CLIENT_ID=...
|
|
297
|
+
export GITHUB_APP_CLIENT_SECRET=...
|
|
298
|
+
export GITHUB_APP_SLUG=your-app-slug
|
|
299
|
+
export APP_DATABASE_URL=postgres://user:pass@host:5432/db
|
|
300
|
+
export GITHUB_APP_REDIRECT_URI=https://your-host/auth/github/callback # optional
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
GitHub-backed projects are cloned into an isolated cloud sandbox on open, which requires a
|
|
304
|
+
sandbox provider. Railway is the first supported backend:
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
export RAILWAY_API_TOKEN=...
|
|
308
|
+
export RAILWAY_ENVIRONMENT_ID=...
|
|
309
|
+
export MASTRACODE_SANDBOX_PROVIDER=railway # optional (default when a token is set)
|
|
310
|
+
export MASTRACODE_SANDBOX_WORKDIR=/workspace # optional (path inside the sandbox)
|
|
311
|
+
export MASTRACODE_SANDBOX_IDLE_MINUTES=30 # optional (idle teardown window; default 30)
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
The sandbox template must have `git` and `gh` (the GitHub CLI) installed and outbound network
|
|
315
|
+
access to `github.com`. `gh` is only required to open pull requests; clone/open work without it.
|
|
316
|
+
Idle sandboxes are stopped by the provider after `MASTRACODE_SANDBOX_IDLE_MINUTES`; the next open
|
|
317
|
+
detects the stopped VM and re-provisions automatically.
|
|
318
|
+
Without a sandbox provider, users can still connect GitHub and pick repos, but opening a repo
|
|
319
|
+
project shows a clear "sandbox not configured" error.
|
|
320
|
+
|
|
321
|
+
### Per-(org,user) storage isolation
|
|
322
|
+
|
|
323
|
+
When WorkOS web auth is enabled, the tenant boundary is the **(organization, user)** pair: each
|
|
324
|
+
user in each org operates against their own dedicated libSQL database for all agent state (threads,
|
|
325
|
+
messages, memory, observational memory, recall vectors) — no tenant can read another tenant's data
|
|
326
|
+
at the storage layer. Two users in the same org are isolated, and the same user across two orgs is
|
|
327
|
+
also isolated. The database location is derived server-side from a hash of `(orgId, userId)` (no
|
|
328
|
+
client-supplied paths); users without an org fall back to a user-only key.
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
# Local files (default): one isolated DB dir per tenant under this root
|
|
332
|
+
export MASTRACODE_TENANT_DB_ROOT=~/.mastracode/web/tenants # optional
|
|
333
|
+
|
|
334
|
+
# Or remote libSQL/Turso per tenant ({id} = hashed (orgId, userId)). This mode
|
|
335
|
+
# assumes each tenant DB already exists at the templated URL.
|
|
336
|
+
export MASTRACODE_TENANT_DB_URL_TEMPLATE=libsql://{id}-org.turso.io # optional
|
|
337
|
+
export MASTRACODE_TENANT_VECTOR_URL_TEMPLATE=libsql://{id}-vec-org.turso.io # optional
|
|
338
|
+
export MASTRACODE_TENANT_DB_AUTH_TOKEN=... # optional
|
|
339
|
+
export MASTRACODE_TENANT_VECTOR_AUTH_TOKEN=... # optional
|
|
340
|
+
|
|
341
|
+
# Or auto-provision a Turso database per tenant on first access via the Turso
|
|
342
|
+
# Platform API (no pre-created DBs needed). Requires APP_DATABASE_URL: the
|
|
343
|
+
# stable db-name/hostname mapping is persisted there so replicas converge on
|
|
344
|
+
# one DB and cold starts don't re-create it. A scoped token is minted fresh per
|
|
345
|
+
# resolution, so no long-lived credential is stored.
|
|
346
|
+
export MASTRACODE_TURSO_PLATFORM_TOKEN=... # optional
|
|
347
|
+
export MASTRACODE_TURSO_ORG=my-org # optional
|
|
348
|
+
export MASTRACODE_TURSO_GROUP=default # optional (default "default")
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Resolution priority: explicit `MASTRACODE_TENANT_DB_URL_TEMPLATE` → Turso
|
|
352
|
+
auto-provisioning (when the platform token + org are set) → local libSQL files.
|
|
353
|
+
|
|
354
|
+
When web auth is disabled the server uses a single shared store, exactly as before.
|
|
355
|
+
|
|
356
|
+
### Multi-replica deployment
|
|
357
|
+
|
|
358
|
+
The web server keeps each tenant's Mastra stack in an in-memory cache and serializes per-user git
|
|
359
|
+
write operations. For hosted, multi-replica deployments a few settings make this safe and bounded:
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
# Replica-stable state signing — REQUIRED across replicas. Without an explicit
|
|
363
|
+
# GITHUB_APP_WEBHOOK_SECRET (or WORKOS_COOKIE_PASSWORD) the OAuth/install state
|
|
364
|
+
# is signed with a per-process random key and callbacks fail on other replicas.
|
|
365
|
+
export GITHUB_APP_WEBHOOK_SECRET=...
|
|
366
|
+
|
|
367
|
+
# Cross-replica serialization of per-(project,user) git writes via Postgres
|
|
368
|
+
# advisory locks (default on, requires APP_DATABASE_URL). Set 0 for local dev.
|
|
369
|
+
export MASTRACODE_DISTRIBUTED_LOCK=1
|
|
370
|
+
|
|
371
|
+
# Persist/share tenant DBs across replicas — fail/warn at startup if no remote
|
|
372
|
+
# tenant DB backend (URL template OR Turso auto-provisioning) is configured
|
|
373
|
+
# (local-file DBs don't survive restarts or sharing).
|
|
374
|
+
export MASTRACODE_REQUIRE_REMOTE_TENANT_DB=1
|
|
375
|
+
|
|
376
|
+
# Bound in-memory tenant caches as the team grows.
|
|
377
|
+
export MASTRACODE_TENANT_IDLE_MINUTES=30 # idle eviction window (0 disables)
|
|
378
|
+
export MASTRACODE_TENANT_MAX_APPS=100 # LRU cap on cached stacks (0 disables)
|
|
379
|
+
|
|
380
|
+
# Per-replica cap on concurrently live sandboxes (0 / unset = unlimited).
|
|
381
|
+
export MASTRACODE_MAX_SANDBOXES=50
|
|
382
|
+
```
|
|
383
|
+
|
|
261
384
|
## Architecture
|
|
262
385
|
|
|
263
386
|
```
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var chunk2NKDVAOP_cjs = require('./chunk-2NKDVAOP.cjs');
|
|
4
|
-
var chunkJEIKVC6A_cjs = require('./chunk-JEIKVC6A.cjs');
|
|
5
3
|
var chunkVBH3L4LD_cjs = require('./chunk-VBH3L4LD.cjs');
|
|
4
|
+
var chunkP5J7PK3B_cjs = require('./chunk-P5J7PK3B.cjs');
|
|
5
|
+
var chunkWX46SWL3_cjs = require('./chunk-WX46SWL3.cjs');
|
|
6
6
|
var crypto = require('crypto');
|
|
7
7
|
var stream = require('stream');
|
|
8
8
|
var sdk = require('@agentclientprotocol/sdk');
|
|
@@ -45,7 +45,7 @@ async function acpMain(options) {
|
|
|
45
45
|
};
|
|
46
46
|
let result;
|
|
47
47
|
try {
|
|
48
|
-
result = await
|
|
48
|
+
result = await chunkP5J7PK3B_cjs.createMastraCode({
|
|
49
49
|
unixSocketPubSub: false,
|
|
50
50
|
disableMcp: false,
|
|
51
51
|
disableHooks: false
|
|
@@ -57,7 +57,7 @@ async function acpMain(options) {
|
|
|
57
57
|
{ id: "fast", name: "Fast" }
|
|
58
58
|
];
|
|
59
59
|
const cleanup = async () => {
|
|
60
|
-
|
|
60
|
+
chunkWX46SWL3_cjs.releaseAllThreadLocks();
|
|
61
61
|
const closeSignalsPubSub = signalsPubSub?.close;
|
|
62
62
|
await Promise.allSettled([
|
|
63
63
|
mcpManager?.disconnect(),
|
|
@@ -83,5 +83,5 @@ async function acpMain(options) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
exports.acpMain = acpMain;
|
|
86
|
-
//# sourceMappingURL=acp-
|
|
87
|
-
//# sourceMappingURL=acp-
|
|
86
|
+
//# sourceMappingURL=acp-5AMWEFJ3.cjs.map
|
|
87
|
+
//# sourceMappingURL=acp-5AMWEFJ3.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/acp/server.ts","../src/acp/index.ts"],"names":["Readable","Writable","stream","ndJsonStream","randomUUID","AgentSideConnection","MastraCodeAcpAgent","setAutoApprove","createMastraCode","releaseAllThreadLocks"],"mappings":";;;;;;;;;AAUA,eAAsB,YAAA,CACpB,UAAA,EACA,KAAA,EACA,OAAA,EAC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CAAQ,EAAA,CAAG,WAAW,YAAY,CAAA;AAElC,IAAA,MAAM,YAAA,CAAa,UAAA,EAAY,KAAA,EAAO,OAAO,CAAA;AAAA,EAC/C,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,mBAAA,EAAsB,KAAK;AAAA,CAAI,CAAA;AAEpD,IAAA,OAAA,CAAQ,GAAA,GAAM,kBAAA;AACd,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF","file":"acp-
|
|
1
|
+
{"version":3,"sources":["../src/acp/server.ts","../src/acp/index.ts"],"names":["Readable","Writable","stream","ndJsonStream","randomUUID","AgentSideConnection","MastraCodeAcpAgent","setAutoApprove","createMastraCode","releaseAllThreadLocks"],"mappings":";;;;;;;;;AAUA,eAAsB,YAAA,CACpB,UAAA,EACA,KAAA,EACA,OAAA,EACe;AAEf,EAAA,MAAM,KAAA,GAAQA,eAAA,CAAS,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AAC1C,EAAA,MAAM,MAAA,GAASC,eAAA,CAAS,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA;AAC5C,EAAA,MAAMC,QAAA,GAASC,gBAAA,CAAa,MAAA,EAAQ,KAAK,CAAA;AACzC,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI,KAAA;AAGJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,MAAM,WAAW,aAAA,CAAc;AAAA,MACvC,EAAA,EAAI,CAAA,IAAA,EAAOC,iBAAA,EAAY,CAAA,CAAA;AAAA,MACvB,OAAA,EAAS,CAAA,UAAA,EAAaA,iBAAA,EAAY,CAAA;AAAA,KACnC,CAAA;AACD,IAAA,MAAM,aAAA,GAAgB,OAAA;AAGtB,IAAA,MAAM,UAAA,GAAa,IAAIC,uBAAA,CAAoB,CAAA,IAAA,KAAQ;AACjD,MAAA,KAAA,GAAQ,IAAIC,oCAAA,CAAmB,IAAA,EAAM,UAAA,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KAC7B;AAGA,IAAA,MAAM,UAAU,YAAY;AAC1B,MAAAC,uCAAA,EAAsB;AACtB,MAAA,MAAM,qBAAsB,aAAA,EAAsE,KAAA;AAClG,MAAA,MAAM,QAAQ,UAAA,CAAW;AAAA,QACvB,YAAY,UAAA,EAAW;AAAA,QACvB,UAAA,EAAY,SAAA,EAAU,EAAG,WAAA,EAAY;AAAA,QACrC,YAAY,aAAA,EAAc;AAAA,QAC1B,kBAAA;AAAqB,OACtB,CAAA;AAID,MAAA,OAAA,CAAQ,GAAA,GAAM,kBAAA;AAAA,IAChB,CAAA;AAGA,IAAA,MAAM,eAAe,YAAY;AAC/B,MAAA,MAAM,OAAA,EAAQ;AACd,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB,CAAA;AAEA,IAAA,OAAA,CAAQ,EAAA,CAAG,UAAU,YAAY,CAAA;AACjC,IAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,YAAY,CAAA;AAElC,IAAA,MAAM,YAAA,CAAa,UAAA,EAAY,KAAA,EAAO,OAAO,CAAA;AAAA,EAC/C,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,mBAAA,EAAsB,KAAK;AAAA,CAAI,CAAA;AAEpD,IAAA,OAAA,CAAQ,GAAA,GAAM,kBAAA;AACd,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF","file":"acp-5AMWEFJ3.cjs","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { Readable, Writable } from 'node:stream';\nimport { AgentSideConnection, ndJsonStream } from '@agentclientprotocol/sdk';\nimport type { AgentController, AgentControllerMode, Session } from '@mastra/core/agent-controller';\nimport { MastraCodeAcpAgent } from './agent.js';\n\n/**\n * Run the ACP server over stdio.\n * This sets up the JSON-RPC stream and keeps the process alive until the client disconnects.\n */\nexport async function runAcpServer(\n controller: AgentController,\n modes: AgentControllerMode[],\n cleanup?: () => Promise<void>,\n): Promise<void> {\n // Create the ndJSON stream from stdin/stdout\n const input = Readable.toWeb(process.stdin) as ReadableStream<Uint8Array>;\n const output = Writable.toWeb(process.stdout) as WritableStream<Uint8Array>;\n const stream = ndJsonStream(output, input);\n let session: Session | undefined;\n let agent: MastraCodeAcpAgent | undefined;\n\n // Handle cleanup on disconnect (success or error)\n try {\n session = await controller.createSession({\n id: `acp-${randomUUID()}`,\n ownerId: `acp-owner-${randomUUID()}`,\n });\n const activeSession = session;\n\n // Create the agent-side connection\n const connection = new AgentSideConnection(conn => {\n agent = new MastraCodeAcpAgent(conn, controller, activeSession, modes);\n return agent;\n }, stream);\n\n await connection.closed;\n } finally {\n agent?.dispose();\n session?.thread.detachFromCurrent();\n await session?.thread.clearAndReleaseLock();\n if (cleanup) {\n await cleanup();\n }\n }\n}\n","import type { AgentControllerMode } from '@mastra/core/agent-controller';\n\nimport { createMastraCode } from '../index.js';\nimport { releaseAllThreadLocks } from '../utils/thread-lock.js';\nimport { setAutoApprove } from './event-mapper.js';\nimport { runAcpServer } from './server.js';\n\n/**\n * Entry point for ACP server mode.\n * Initializes mastracode and runs the ACP protocol over stdio.\n */\nexport async function acpMain(options?: { dangerousAutoApprove?: boolean }): Promise<void> {\n if (options?.dangerousAutoApprove) {\n setAutoApprove(true);\n }\n // Redirect console.log to stderr to avoid polluting the JSON-RPC stream on stdout.\n // eslint-disable-next-line no-console\n const originalConsoleLog = console.log;\n // eslint-disable-next-line no-console\n console.log = (...args: unknown[]) => {\n process.stderr.write(args.map(String).join(' ') + '\\n');\n };\n\n let result: Awaited<ReturnType<typeof createMastraCode>> | undefined;\n\n try {\n result = await createMastraCode({\n unixSocketPubSub: false,\n disableMcp: false,\n disableHooks: false,\n });\n\n const { controller, mcpManager, signalsPubSub } = result;\n\n // Default modes (same as createMastraCode defaults)\n const modes: AgentControllerMode[] = [\n { id: 'build', name: 'Build' },\n { id: 'plan', name: 'Plan' },\n { id: 'fast', name: 'Fast' },\n ];\n\n // Cleanup function (mirrors main.ts asyncCleanup)\n const cleanup = async () => {\n releaseAllThreadLocks();\n const closeSignalsPubSub = (signalsPubSub as { close?: () => Promise<void> | void } | undefined)?.close;\n await Promise.allSettled([\n mcpManager?.disconnect(),\n controller?.getMastra()?.stopWorkers(),\n controller?.stopIntervals(),\n closeSignalsPubSub?.(),\n ]);\n\n // Restore console.log\n // eslint-disable-next-line no-console\n console.log = originalConsoleLog;\n };\n\n // Handle signals\n const handleSignal = async () => {\n await cleanup();\n process.exit(0);\n };\n\n process.on('SIGINT', handleSignal);\n process.on('SIGTERM', handleSignal);\n\n await runAcpServer(controller, modes, cleanup);\n } catch (error) {\n process.stderr.write(`[acp] Fatal error: ${error}\\n`);\n // eslint-disable-next-line no-console\n console.log = originalConsoleLog;\n process.exit(1);\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createMastraCode } from './chunk-22B6MUSN.js';
|
|
2
|
-
import { releaseAllThreadLocks } from './chunk-NB52GKOT.js';
|
|
3
1
|
import { setAutoApprove, MastraCodeAcpAgent } from './chunk-IFUIWWGJ.js';
|
|
2
|
+
import { createMastraCode } from './chunk-VTR4E2PD.js';
|
|
3
|
+
import { releaseAllThreadLocks } from './chunk-GAPPKMQT.js';
|
|
4
4
|
import { randomUUID } from 'crypto';
|
|
5
5
|
import { Readable, Writable } from 'stream';
|
|
6
6
|
import { ndJsonStream, AgentSideConnection } from '@agentclientprotocol/sdk';
|
|
@@ -81,5 +81,5 @@ async function acpMain(options) {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export { acpMain };
|
|
84
|
-
//# sourceMappingURL=acp-
|
|
85
|
-
//# sourceMappingURL=acp-
|
|
84
|
+
//# sourceMappingURL=acp-UBTAGUFO.js.map
|
|
85
|
+
//# sourceMappingURL=acp-UBTAGUFO.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/acp/server.ts","../src/acp/index.ts"],"names":[],"mappings":";;;;;;;AAUA,eAAsB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M,qBAAsB,aAAA,EAAsE,KAAA;AAClG,MAAA,MAAM,QAAQ,UAAA,CAAW;AAAA,QACvB,YAAY,UAAA,EAAW;AAAA,QACvB,UAAA,EAAY,SAAA,EAAU,EAAG,WAAA,EAAY;AAAA,QACrC,YAAY,aAAA,EAAc;AAAA,QAC1B,kBAAA;AAAqB,OACtB,CAAA;AAID,MAAA,OAAA,CAAQ,GAAA,GAAM,kBAAA;AAAA,IAChB,CAAA;AAGA,IAAA,MAAM,eAAe,YAAY;AAC/B,MAAA,MAAM,OAAA,EAAQ;AACd,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,IAChB,CAAA;AAEA,IAAA,OAAA,CAAQ,EAAA,CAAG,UAAU,YAAY,CAAA;AACjC,IAAA,OAAA,CAAQ,EAAA,CAAG,WAAW,YAAY,CAAA;AAElC,IAAA,MAAM,YAAA,CAAa,UAAA,EAAY,KAAA,EAAO,OAAO,CAAA;AAAA,EAC/C,SAAS,KAAA,EAAO;AACd,IAAA,OAAA,CAAQ,MAAA,CAAO,KAAA,CAAM,CAAA,mBAAA,EAAsB,KAAK;AAAA,CAAI,CAAA;AAEpD,IAAA,OAAA,CAAQ,GAAA,GAAM,kBAAA;AACd,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EAChB;AACF","file":"acp-UBTAGUFO.js","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { Readable, Writable } from 'node:stream';\nimport { AgentSideConnection, ndJsonStream } from '@agentclientprotocol/sdk';\nimport type { AgentController, AgentControllerMode, Session } from '@mastra/core/agent-controller';\nimport { MastraCodeAcpAgent } from './agent.js';\n\n/**\n * Run the ACP server over stdio.\n * This sets up the JSON-RPC stream and keeps the process alive until the client disconnects.\n */\nexport async function runAcpServer(\n controller: AgentController,\n modes: AgentControllerMode[],\n cleanup?: () => Promise<void>,\n): Promise<void> {\n // Create the ndJSON stream from stdin/stdout\n const input = Readable.toWeb(process.stdin) as ReadableStream<Uint8Array>;\n const output = Writable.toWeb(process.stdout) as WritableStream<Uint8Array>;\n const stream = ndJsonStream(output, input);\n let session: Session | undefined;\n let agent: MastraCodeAcpAgent | undefined;\n\n // Handle cleanup on disconnect (success or error)\n try {\n session = await controller.createSession({\n id: `acp-${randomUUID()}`,\n ownerId: `acp-owner-${randomUUID()}`,\n });\n const activeSession = session;\n\n // Create the agent-side connection\n const connection = new AgentSideConnection(conn => {\n agent = new MastraCodeAcpAgent(conn, controller, activeSession, modes);\n return agent;\n }, stream);\n\n await connection.closed;\n } finally {\n agent?.dispose();\n session?.thread.detachFromCurrent();\n await session?.thread.clearAndReleaseLock();\n if (cleanup) {\n await cleanup();\n }\n }\n}\n","import type { AgentControllerMode } from '@mastra/core/agent-controller';\n\nimport { createMastraCode } from '../index.js';\nimport { releaseAllThreadLocks } from '../utils/thread-lock.js';\nimport { setAutoApprove } from './event-mapper.js';\nimport { runAcpServer } from './server.js';\n\n/**\n * Entry point for ACP server mode.\n * Initializes mastracode and runs the ACP protocol over stdio.\n */\nexport async function acpMain(options?: { dangerousAutoApprove?: boolean }): Promise<void> {\n if (options?.dangerousAutoApprove) {\n setAutoApprove(true);\n }\n // Redirect console.log to stderr to avoid polluting the JSON-RPC stream on stdout.\n // eslint-disable-next-line no-console\n const originalConsoleLog = console.log;\n // eslint-disable-next-line no-console\n console.log = (...args: unknown[]) => {\n process.stderr.write(args.map(String).join(' ') + '\\n');\n };\n\n let result: Awaited<ReturnType<typeof createMastraCode>> | undefined;\n\n try {\n result = await createMastraCode({\n unixSocketPubSub: false,\n disableMcp: false,\n disableHooks: false,\n });\n\n const { controller, mcpManager, signalsPubSub } = result;\n\n // Default modes (same as createMastraCode defaults)\n const modes: AgentControllerMode[] = [\n { id: 'build', name: 'Build' },\n { id: 'plan', name: 'Plan' },\n { id: 'fast', name: 'Fast' },\n ];\n\n // Cleanup function (mirrors main.ts asyncCleanup)\n const cleanup = async () => {\n releaseAllThreadLocks();\n const closeSignalsPubSub = (signalsPubSub as { close?: () => Promise<void> | void } | undefined)?.close;\n await Promise.allSettled([\n mcpManager?.disconnect(),\n controller?.getMastra()?.stopWorkers(),\n controller?.stopIntervals(),\n closeSignalsPubSub?.(),\n ]);\n\n // Restore console.log\n // eslint-disable-next-line no-console\n console.log = originalConsoleLog;\n };\n\n // Handle signals\n const handleSignal = async () => {\n await cleanup();\n process.exit(0);\n };\n\n process.on('SIGINT', handleSignal);\n process.on('SIGTERM', handleSignal);\n\n await runAcpServer(controller, modes, cleanup);\n } catch (error) {\n process.stderr.write(`[acp] Fatal error: ${error}\\n`);\n // eslint-disable-next-line no-console\n console.log = originalConsoleLog;\n process.exit(1);\n }\n}\n"]}
|
|
@@ -3,10 +3,10 @@ import type { Mastra } from '@mastra/core/mastra';
|
|
|
3
3
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
4
4
|
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace';
|
|
5
5
|
export declare function buildSkillPaths(projectPath: string, configDir: string, homeDir?: string): string[];
|
|
6
|
-
export declare function getDynamicWorkspace({ requestContext, mastra }: {
|
|
6
|
+
export declare function getDynamicWorkspace({ requestContext, mastra, }: {
|
|
7
7
|
requestContext: RequestContext;
|
|
8
8
|
mastra?: Mastra;
|
|
9
|
-
}): Workspace<LocalFilesystem, LocalSandbox, undefined
|
|
9
|
+
}): Promise<Workspace<import("@mastra/core/workspace").WorkspaceFilesystem | undefined, import("@mastra/core/workspace").WorkspaceSandbox | undefined, undefined> | Workspace<LocalFilesystem, LocalSandbox, undefined>>;
|
|
10
10
|
/**
|
|
11
11
|
* Resolver for the agent's `goal.tools` config. Builds the request's workspace
|
|
12
12
|
* (same per-request resolution as the agent's own tools) and returns only the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/agents/workspace.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAwB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/agents/workspace.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,EAAwB,MAAM,wBAAwB,CAAC;AAiFxG,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,SAAe,GAAG,MAAM,EAAE,CAgBxG;AAgFD,wBAAsB,mBAAmB,CAAC,EACxC,cAAc,EACd,MAAM,GACP,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,wNA2EA;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,cAAc,EACd,MAAM,GACP,EAAE;IACD,cAAc,EAAE,cAAc,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAclC"}
|
|
@@ -1437,5 +1437,5 @@ exports.getUserId = getUserId;
|
|
|
1437
1437
|
exports.getUserName = getUserName;
|
|
1438
1438
|
exports.getVectorDatabasePath = getVectorDatabasePath;
|
|
1439
1439
|
exports.validateConfigDirName = validateConfigDirName;
|
|
1440
|
-
//# sourceMappingURL=chunk-
|
|
1441
|
-
//# sourceMappingURL=chunk-
|
|
1440
|
+
//# sourceMappingURL=chunk-6HMHCNGR.cjs.map
|
|
1441
|
+
//# sourceMappingURL=chunk-6HMHCNGR.cjs.map
|