@agentproto/adapter-mastracode-inprocess 0.2.0 → 0.2.2
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 +202 -21
- package/dist/index.mjs +5 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.mjs
CHANGED
|
@@ -179,13 +179,15 @@ var mastracodeInprocess = defineAgentCli({
|
|
|
179
179
|
},
|
|
180
180
|
models: {
|
|
181
181
|
default: "anthropic/claude-sonnet-4-5",
|
|
182
|
+
// Anthropic is no longer advertised as a pickable escalation — only the
|
|
183
|
+
// adapter's own default Claude model stays listed (repointing the default
|
|
184
|
+
// is out of scope). The extra Sonnet + gateway dupe are dropped from the
|
|
185
|
+
// menu; the free-form `model` option still accepts any id.
|
|
182
186
|
allowed: [
|
|
183
187
|
"anthropic/claude-sonnet-4-5",
|
|
184
|
-
"anthropic/claude-sonnet-4-6",
|
|
185
188
|
"openai/gpt-5.1",
|
|
186
189
|
"openai/gpt-5.1-mini",
|
|
187
|
-
"google/gemini-2.5-flash"
|
|
188
|
-
"openrouter/anthropic/claude-sonnet-4-6"
|
|
190
|
+
"google/gemini-2.5-flash"
|
|
189
191
|
],
|
|
190
192
|
env: {
|
|
191
193
|
anthropic: "ANTHROPIC_API_KEY",
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqDA,IAAM,YAAA,GAAe,4BAAA;AAErB,IAAM,qBAAA,uBAA4B,GAAA,CAAI,CAAC,OAAO,KAAA,EAAO,QAAA,EAAU,MAAA,EAAQ,OAAO,CAAC,CAAA;AAC/E,IAAM,kCAAkB,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,MAAA,EAAQ,MAAM,CAAC,CAAA;AAEzD,SAAS,qBAAA,GAAgC;AACvC,EAAA,OAAO,QAAQ,GAAA,CAAI,eAAA,IAAmB,IAAA,CAAK,OAAA,IAAW,aAAa,CAAA;AACrE;AAMA,SAAS,kBAAA,GAA6B;AACpC,EAAA,OAAO,IAAA,CAAK,qBAAA,EAAsB,EAAG,sBAAA,EAAwB,YAAY,CAAA;AAC3E;AAmBA,SAAS,sBAAA,GAAiC;AACxC,EAAA,OAAO,IAAA,CAAK,qBAAA,EAAsB,EAAG,sBAAA,EAAwB,MAAM,CAAA;AACrE;AAEA,SAAS,eAAe,SAAA,EAA6D;AACnF,EAAA,MAAM,GAAA,GAAM,SAAA,CAAU,OAAA,CAAQ,GAAG,CAAA;AACjC,EAAA,IAAI,GAAA,IAAO,CAAA,IAAK,GAAA,KAAQ,SAAA,CAAU,SAAS,CAAA,EAAG;AAC5C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,oDAAoD,SAAS,CAAA,iGAAA;AAAA,KAE/D;AAAA,EACF;AACA,EAAA,OAAO,EAAE,UAAA,EAAY,SAAA,CAAU,KAAA,CAAM,CAAA,EAAG,GAAG,CAAA,EAAG,QAAA,EAAU,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":"index.mjs","sourcesContent":["/**\n * `AgentCliClient` implementation wrapping Mastra Code's in-process SDK\n * (`mastracode` / `mastracode/headless`) instead of spawning a subprocess.\n *\n * ## Why a composite sessionId\n *\n * A single Mastra Code `AgentController` instance auto-binds a *fresh*\n * session to whatever thread `session.thread` currently points at, and\n * (empirically verified against mastracode 0.27.0 / @mastra/core 1.48.0)\n * `runMC()` only rebinds that pointer when `thread.id` / `thread.continueLatest`\n * is explicitly passed. Two unrelated conversations that share both a\n * `cwd` and this arm's dedicated storage file would otherwise silently\n * land on the SAME thread — Mastra Code resolves the initial thread by\n * `resourceId`, and every conversation was defaulting to the same one.\n *\n * The fix (also verified live): pass a distinct `resourceId` to `runMC()`\n * per *conversation*, not per process and not globally via\n * `MASTRA_RESOURCE_ID` (a global env var would race across concurrent\n * in-process conversations in the same daemon). A fresh conversation\n * mints a random resourceId; a resumed one must reuse the EXACT\n * resourceId the thread was created under, because `session.thread.list()`\n * — which `runMC`'s thread-by-id resolution calls internally — is scoped\n * to the session's current resourceId by default. So this arm's public\n * `sessionId` is `\"<resourceId>:<threadId>\"`, and resume splits it back\n * apart. This composite format is this arm's own implementation detail;\n * hosts only ever need to persist and echo back whatever string\n * `sessionId` returns, per the generic AgentCliClient contract.\n *\n * Cross-process resume (kill the process, start a new one, reattach via\n * the same composite sessionId against the same dedicated storage file)\n * has been verified to preserve conversation memory end-to-end.\n */\n\nimport { randomUUID } from \"node:crypto\"\nimport { homedir } from \"node:os\"\nimport { join, dirname } from \"node:path\"\nimport { mkdirSync } from \"node:fs\"\nimport { createMastraCode } from \"mastracode\"\nimport { runMC, type MCRun } from \"mastracode/headless\"\nimport {\n mapMastraEvent,\n createMastraMapperState,\n toFileBasedMcpServers,\n type AgentCliClient,\n type AgentCliConnectOptions,\n type AgentCliHandle,\n type StreamEvent,\n} from \"@agentproto/driver-agent-cli\"\n\n/** Env var carrying a manifest `modes[].env` patch through to `send()` —\n * there's no argv for a `proprietary` arm to append `bin_args_append`\n * to, so mode selection travels the one channel `composeSpawn` already\n * threads through for every protocol: env. See `../MASTRACODE-INPROCESS.md`. */\nconst MODE_ENV_KEY = \"AGENTPROTO_MASTRACODE_MODE\"\n\nconst VALID_THINKING_LEVELS = new Set([\"off\", \"low\", \"medium\", \"high\", \"xhigh\"])\nconst VALID_RUN_MODES = new Set([\"build\", \"plan\", \"fast\"])\n\nfunction resolveAgentprotoHome(): string {\n return process.env.AGENTPROTO_HOME ?? join(homedir(), \".agentproto\")\n}\n\n/** Dedicated per-machine storage — NOT the ambient global mastracode\n * default (which is shared across every mastracode invocation on the\n * host, subprocess or not). Isolating it here means this arm's threads\n * never collide with a developer's own interactive `mastracode` usage. */\nfunction resolveStoragePath(): string {\n return join(resolveAgentprotoHome(), \"mastracode-inprocess\", \"storage.db\")\n}\n\n/** Dedicated, empty home directory so Mastra Code's global config\n * discovery (`~/.claude/skills`, `~/.mastracode/{hooks,commands,skills}`,\n * `~/.agents/skills`) does not implicitly inherit the operator's own\n * personal Claude Code / Mastra Code setup.\n *\n * KNOWN LIMITATION (verified against 0.27.0, not assumed): passing\n * `homeDir` at the top level of `MastraCodeConfig` is NOT sufficient —\n * `createMastraCodeAgentController` resolves `homeDir` for hooks/plugin\n * wiring but does not copy it into `initialState`, and the workspace's\n * skill-path builder reads `state.homeDir`, falling back to the real\n * `os.homedir()` when that's unset. Both `homeDir` AND\n * `initialState: { homeDir }` must be passed for the override to\n * actually reach skill discovery. This does not affect a target repo's\n * own PROJECT-LOCAL `.claude/skills` (relative to `cwd`) — that's the\n * repo's own content, not the operator's personal config, and is\n * intentionally left reachable (mirrors the ACP arm reading a target\n * repo's own `.claude/settings.json`). */\nfunction resolveIsolatedHomeDir(): string {\n return join(resolveAgentprotoHome(), \"mastracode-inprocess\", \"home\")\n}\n\nfunction parseSessionId(sessionId: string): { resourceId: string; threadId: string } {\n const idx = sessionId.indexOf(\":\")\n if (idx <= 0 || idx === sessionId.length - 1) {\n throw new Error(\n `mastracode-inprocess: malformed resumeSessionId '${sessionId}' — expected ` +\n `\"<resourceId>:<threadId>\", the format this arm's own sessionId getter produces.`,\n )\n }\n return { resourceId: sessionId.slice(0, idx), threadId: sessionId.slice(idx + 1) }\n}\n\n/** Narrow shape of `createMastraCode`'s resolved return value this arm\n * actually uses — kept local (not re-exported from `mastracode`) so this\n * file only depends on what it reads. */\ninterface MastraCodeHandle {\n controller: { destroy(): Promise<void> }\n session: {\n thread: { getId(): string | null }\n mode: { get(): string; switch(args: { modeId: string }): Promise<void> }\n }\n /** Present when `bootLocalAgentController` builds an MCP manager (i.e.\n * MCP servers were configured). `createMastraCode` does NOT initialize\n * it automatically — verified against mastracode's own headless CLI\n * entrypoint (`runMCCli` in `dist/chunk-HADE25EX.cjs`), which explicitly\n * calls `mcpManager.initInBackground()` itself right after boot, before\n * running any prompt. Skipping this step (as an earlier version of this\n * arm did) leaves `mcpServers` connected-but-never-initialized: the\n * config is accepted, but no MCP tools ever reach the agent's toolset. */\n mcpManager?: {\n hasServers(): boolean\n initInBackground(): Promise<unknown>\n }\n}\n\nexport function createAgentCliClient(definition: AgentCliHandle): AgentCliClient {\n let handle: MastraCodeHandle | undefined\n let resourceId: string | undefined\n let threadId: string | undefined\n let connectEnv: Record<string, string> = {}\n let connectModel: string | undefined\n let connectEffort: string | undefined\n const pendingByTurn = new Map<string, MCRun>()\n\n return {\n get sessionId(): string | undefined {\n return resourceId && threadId ? `${resourceId}:${threadId}` : undefined\n },\n\n async connect(opts: AgentCliConnectOptions): Promise<void> {\n const isolatedHome = resolveIsolatedHomeDir()\n const storagePath = resolveStoragePath()\n mkdirSync(isolatedHome, { recursive: true })\n mkdirSync(dirname(storagePath), { recursive: true })\n\n handle = (await createMastraCode({\n cwd: opts.cwd,\n homeDir: isolatedHome,\n initialState: { homeDir: isolatedHome },\n disablePlugins: true,\n storage: { backend: \"libsql\", url: `file:${storagePath}`, isRemote: false },\n ...(opts.mcpServers?.length\n ? { mcpServers: toFileBasedMcpServers(opts.mcpServers) }\n : {}),\n })) as unknown as MastraCodeHandle\n\n // `createMastraCode` builds the MCP manager but does not initialize\n // it — mirror mastracode's own headless CLI (`runMCCli`), which\n // explicitly awaits this before running any prompt. Without it, MCP\n // servers are configured but never connected, so their tools never\n // reach the agent. Best-effort: a failed MCP connection shouldn't\n // fail the whole session (matches the CLI's own warn-and-continue).\n if (handle.mcpManager?.hasServers()) {\n try {\n await handle.mcpManager.initInBackground()\n } catch {\n // Best-effort — the session still starts on its non-MCP tools.\n }\n }\n\n connectEnv = opts.env\n connectModel = opts.model\n connectEffort = opts.effort\n\n if (opts.resumeSessionId) {\n ;({ resourceId, threadId } = parseSessionId(opts.resumeSessionId))\n } else {\n resourceId = `agentproto-mastracode-inprocess-${randomUUID()}`\n threadId = undefined\n }\n },\n\n async send(turnId: string, message: unknown): Promise<void> {\n if (!handle || !resourceId) {\n throw new Error(\"mastracode-inprocess: send() called before connect()\")\n }\n const prompt = extractPromptText(message)\n\n const requestedMode = connectEnv[MODE_ENV_KEY]\n if (requestedMode && VALID_RUN_MODES.has(requestedMode)) {\n if (handle.session.mode.get() !== requestedMode) {\n await handle.session.mode.switch({ modeId: requestedMode })\n }\n }\n\n const thinkingLevel =\n connectEffort && VALID_THINKING_LEVELS.has(connectEffort)\n ? (connectEffort as \"off\" | \"low\" | \"medium\" | \"high\" | \"xhigh\")\n : undefined\n\n const run = runMC({\n controller: handle.controller as never,\n session: handle.session as never,\n prompt,\n resourceId,\n thread: threadId ? { id: threadId } : undefined,\n ...(connectModel ? { model: connectModel } : {}),\n ...(thinkingLevel ? { thinkingLevel } : {}),\n ...(definition.session?.max_turns\n ? { maxTurns: definition.session.max_turns }\n : {}),\n })\n pendingByTurn.set(turnId, run)\n },\n\n async *events(): AsyncIterable<StreamEvent> {\n const run = Array.from(pendingByTurn.values()).at(-1)\n if (!run) return\n const state = createMastraMapperState()\n for await (const evt of run) {\n // Track the thread id live from in-band events, synchronously\n // with the loop that's about to map+yield them — no race against\n // `run.result` resolving on a separate microtask.\n if (evt.type === \"thread_created\") threadId = evt.thread.id\n else if (evt.type === \"thread_changed\") threadId = evt.threadId\n const sid = resourceId && threadId ? `${resourceId}:${threadId}` : \"\"\n const mapped = mapMastraEvent(\n evt as unknown as Record<string, unknown>,\n sid,\n [],\n state,\n )\n if (mapped) yield mapped\n }\n // Fallback for the (unverified) case where a fresh thread's first\n // binding happens inside `sendMessage()` without an in-band\n // `thread_created`/`thread_changed` event — `result.threadId` is\n // always populated once the run settles, so this is authoritative\n // even if the loop above never fired.\n const result = await run.result\n if (result.threadId) threadId = result.threadId\n },\n\n async cancel(turnId: string): Promise<void> {\n pendingByTurn.get(turnId)?.abort()\n },\n\n async close(): Promise<void> {\n await handle?.controller.destroy()\n },\n }\n}\n\nfunction extractPromptText(message: unknown): string {\n if (typeof message === \"string\") return message\n if (Array.isArray(message)) {\n return (message as Array<Record<string, unknown>>)\n .filter(b => b.type === \"text\" && typeof b.text === \"string\")\n .map(b => b.text as string)\n .join(\"\\n\")\n }\n if (message !== null && typeof message === \"object\") {\n const m = message as Record<string, unknown>\n if (typeof m.text === \"string\") return m.text\n }\n return JSON.stringify(message)\n}\n","/**\n * @agentproto/adapter-mastracode-inprocess — AIP-45 adapter for Mastra Code,\n * driven in-process via the `mastracode` / `mastracode/headless` SDK\n * instead of spawning a subprocess.\n *\n * This is a `protocol: \"proprietary\"` manifest: `createAgentCliRuntime`\n * skips the subprocess spawn entirely for this protocol and instead\n * dynamic-imports `adapter` (this very package) and calls its exported\n * `createAgentCliClient(definition)` factory — see\n * `createProprietaryProtocolArm` in `@agentproto/driver-agent-cli`. The\n * factory itself lives in `./client.ts`; this file only builds and\n * exports the manifest handle.\n *\n * import { mastracodeInprocess, mastracodeInprocessRuntime } from \"@agentproto/adapter-mastracode-inprocess\"\n * const session = await mastracodeInprocessRuntime().start()\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n *\n * Why a separate package from `@agentproto/adapter-mastracode` (the\n * `print` arm) rather than a second export of it — see\n * MASTRACODE-INPROCESS.md.\n */\n\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\n\nexport const mastracodeInprocess: AgentCliHandle = defineAgentCli({\n name: \"Mastra Code (in-process)\",\n id: \"mastracode-inprocess\",\n description:\n \"Mastra Code terminal coding agent driven in-process via the `mastracode` SDK \" +\n \"(createMastraCode + runMC) instead of spawning the CLI as a subprocess. Same \" +\n \"underlying agent as @agentproto/adapter-mastracode, no child process.\",\n version: \"0.1.0\",\n // No binary is ever spawned for a proprietary arm — `bin` is required by\n // the AIP-45 schema regardless, so this is a documented placeholder\n // rather than a real executable. `createAgentCliRuntime` checks\n // `protocol === \"proprietary\"` and never reads this field.\n bin: \"in-process\",\n install: [{ method: \"npm\", package: \"@agentproto/adapter-mastracode-inprocess\" }],\n version_check: {\n cmd: \"npm view mastracode version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n // Matches this package's pinned `mastracode` dependency (see package.json).\n range: \">=0.27.0\",\n timeout_ms: 15_000,\n },\n auth: {\n state: {\n env: [\n \"ANTHROPIC_API_KEY\",\n \"OPENAI_API_KEY\",\n \"OPENROUTER_API_KEY\",\n \"GOOGLE_GENERATIVE_AI_API_KEY\",\n ],\n },\n },\n sandbox: {\n model: \"in-process\",\n note:\n \"Runs inside the host process — there is no subprocess boundary to sandbox. \" +\n \"File and shell tool access is whatever Mastra Code's own tool policy grants \" +\n \"for this session, with the host process's OS permissions (not a separately \" +\n \"confined child). Storage and home dir ARE isolated per MASTRACODE-INPROCESS.md \" +\n \"so this arm's sessions never collide with a developer's own interactive \" +\n \"mastracode usage, but that isolation is not a security sandbox.\",\n },\n protocol: \"proprietary\",\n adapter: \"@agentproto/adapter-mastracode-inprocess\",\n session: {\n mode: \"resumable\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n models: {\n default: \"anthropic/claude-sonnet-4-5\",\n allowed: [\n \"anthropic/claude-sonnet-4-5\",\n \"anthropic/claude-sonnet-4-6\",\n \"openai/gpt-5.1\",\n \"openai/gpt-5.1-mini\",\n \"google/gemini-2.5-flash\",\n \"openrouter/anthropic/claude-sonnet-4-6\",\n ],\n env: {\n anthropic: \"ANTHROPIC_API_KEY\",\n openai: \"OPENAI_API_KEY\",\n openrouter: \"OPENROUTER_API_KEY\",\n google: \"GOOGLE_GENERATIVE_AI_API_KEY\",\n },\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: true,\n file_io: true,\n multimodal: false,\n // The composite \"<resourceId>:<threadId>\" sessionId round-trips through\n // `client.ts`'s connect(resumeSessionId) and has been verified to\n // recall prior-turn context across a fresh process (see README.md).\n resumable: true,\n bidirectional: false,\n },\n // Mode selection has no argv to append to (no spawn) — modes patch the\n // one channel `composeSpawn` threads through for every protocol\n // regardless: env. `client.ts` reads `AGENTPROTO_MASTRACODE_MODE` off\n // the composed env and switches the live session's mode before send().\n modes: [\n {\n id: \"default\",\n description: \"Default headless mode. Mastra Code defaults to build mode when omitted.\",\n },\n {\n id: \"plan\",\n description:\n \"Plan-only mode — analyze architecture and propose implementation plans before writing code.\",\n env: { AGENTPROTO_MASTRACODE_MODE: \"plan\" },\n },\n {\n id: \"build\",\n description:\n \"Build mode — file edits and shell commands use Mastra Code's configured permissions.\",\n env: { AGENTPROTO_MASTRACODE_MODE: \"build\" },\n },\n {\n id: \"fast\",\n description: \"Fast mode — lower-latency answers and small edits.\",\n env: { AGENTPROTO_MASTRACODE_MODE: \"fast\" },\n },\n ],\n // `model`/`effort` here are the two ids `createAgentCliRuntime` always\n // reads off `config.options` for the generic model/effort passthrough\n // (see `define-agent-cli.ts`) — declaring them is what lets a host pass\n // `agent_start({ model, effort })` without composeSpawn rejecting the\n // config as an unknown option. Both travel to `client.ts`'s connect()\n // directly (not via bin_args/env), so no `bin_args_template`/`env` patch\n // is declared on either.\n options: [\n {\n id: \"model\",\n type: \"string\",\n description:\n \"Provider/model override for this operator binding (e.g. `anthropic/claude-sonnet-4-5`).\",\n },\n {\n id: \"effort\",\n type: \"enum\",\n enum: [\"off\", \"low\", \"medium\", \"high\", \"xhigh\"],\n description:\n \"Thinking level, mapped 1:1 to Mastra Code's `thinkingLevel` run option.\",\n },\n ],\n continuation: {\n default: \"none\",\n supported: [\"none\", \"transcript\", \"native-resume\"],\n },\n metadata: {\n proprietary: {\n checked: \"2026-07-02\",\n result:\n \"Verified in-process against mastracode 0.27.0 / @mastra/core 1.48.0: a turn \" +\n \"returns real streamed content, and cross-process resume (kill the process, \" +\n \"start a fresh one, reattach via the composite sessionId) recalls prior-turn \" +\n \"context. See MASTRACODE-INPROCESS.md for the composite sessionId format.\",\n },\n },\n tags: [\"mastracode\", \"mastra\", \"proprietary\", \"in-process\", \"agent-runtime\", \"coding\"],\n})\n\nexport function mastracodeInprocessRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(mastracodeInprocess)\n}\n\nexport { createAgentCliClient } from \"./client.js\"\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client.ts","../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAqDA,IAAM,YAAA,GAAe,4BAAA;AAErB,IAAM,qBAAA,uBAA4B,GAAA,CAAI,CAAC,OAAO,KAAA,EAAO,QAAA,EAAU,MAAA,EAAQ,OAAO,CAAC,CAAA;AAC/E,IAAM,kCAAkB,IAAI,GAAA,CAAI,CAAC,OAAA,EAAS,MAAA,EAAQ,MAAM,CAAC,CAAA;AAEzD,SAAS,qBAAA,GAAgC;AACvC,EAAA,OAAO,QAAQ,GAAA,CAAI,eAAA,IAAmB,IAAA,CAAK,OAAA,IAAW,aAAa,CAAA;AACrE;AAMA,SAAS,kBAAA,GAA6B;AACpC,EAAA,OAAO,IAAA,CAAK,qBAAA,EAAsB,EAAG,sBAAA,EAAwB,YAAY,CAAA;AAC3E;AAmBA,SAAS,sBAAA,GAAiC;AACxC,EAAA,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9C,WAAA,EACE;AAAA;AACJ,GACF;AAAA,EACA,YAAA,EAAc;AAAA,IACZ,OAAA,EAAS,MAAA;AAAA,IACT,SAAA,EAAW,CAAC,MAAA,EAAQ,YAAA,EAAc,eAAe;AAAA,GACnD;AAAA,EACA,QAAA,EAAU;AAAA,IACR,WAAA,EAAa;AAAA,MACX,OAAA,EAAS,YAAA;AAAA,MACT,MAAA,EACE;AAAA;AAIJ,GACF;AAAA,EACA,MAAM,CAAC,YAAA,EAAc,UAAU,aAAA,EAAe,YAAA,EAAc,iBAAiB,QAAQ;AACvF,CAAC;AAEM,SAAS,0BAAA,GAA8C;AAC5D,EAAA,OAAO,sBAAsB,mBAAmB,CAAA;AAClD","file":"index.mjs","sourcesContent":["/**\n * `AgentCliClient` implementation wrapping Mastra Code's in-process SDK\n * (`mastracode` / `mastracode/headless`) instead of spawning a subprocess.\n *\n * ## Why a composite sessionId\n *\n * A single Mastra Code `AgentController` instance auto-binds a *fresh*\n * session to whatever thread `session.thread` currently points at, and\n * (empirically verified against mastracode 0.27.0 / @mastra/core 1.48.0)\n * `runMC()` only rebinds that pointer when `thread.id` / `thread.continueLatest`\n * is explicitly passed. Two unrelated conversations that share both a\n * `cwd` and this arm's dedicated storage file would otherwise silently\n * land on the SAME thread — Mastra Code resolves the initial thread by\n * `resourceId`, and every conversation was defaulting to the same one.\n *\n * The fix (also verified live): pass a distinct `resourceId` to `runMC()`\n * per *conversation*, not per process and not globally via\n * `MASTRA_RESOURCE_ID` (a global env var would race across concurrent\n * in-process conversations in the same daemon). A fresh conversation\n * mints a random resourceId; a resumed one must reuse the EXACT\n * resourceId the thread was created under, because `session.thread.list()`\n * — which `runMC`'s thread-by-id resolution calls internally — is scoped\n * to the session's current resourceId by default. So this arm's public\n * `sessionId` is `\"<resourceId>:<threadId>\"`, and resume splits it back\n * apart. This composite format is this arm's own implementation detail;\n * hosts only ever need to persist and echo back whatever string\n * `sessionId` returns, per the generic AgentCliClient contract.\n *\n * Cross-process resume (kill the process, start a new one, reattach via\n * the same composite sessionId against the same dedicated storage file)\n * has been verified to preserve conversation memory end-to-end.\n */\n\nimport { randomUUID } from \"node:crypto\"\nimport { homedir } from \"node:os\"\nimport { join, dirname } from \"node:path\"\nimport { mkdirSync } from \"node:fs\"\nimport { createMastraCode } from \"mastracode\"\nimport { runMC, type MCRun } from \"mastracode/headless\"\nimport {\n mapMastraEvent,\n createMastraMapperState,\n toFileBasedMcpServers,\n type AgentCliClient,\n type AgentCliConnectOptions,\n type AgentCliHandle,\n type StreamEvent,\n} from \"@agentproto/driver-agent-cli\"\n\n/** Env var carrying a manifest `modes[].env` patch through to `send()` —\n * there's no argv for a `proprietary` arm to append `bin_args_append`\n * to, so mode selection travels the one channel `composeSpawn` already\n * threads through for every protocol: env. See `../MASTRACODE-INPROCESS.md`. */\nconst MODE_ENV_KEY = \"AGENTPROTO_MASTRACODE_MODE\"\n\nconst VALID_THINKING_LEVELS = new Set([\"off\", \"low\", \"medium\", \"high\", \"xhigh\"])\nconst VALID_RUN_MODES = new Set([\"build\", \"plan\", \"fast\"])\n\nfunction resolveAgentprotoHome(): string {\n return process.env.AGENTPROTO_HOME ?? join(homedir(), \".agentproto\")\n}\n\n/** Dedicated per-machine storage — NOT the ambient global mastracode\n * default (which is shared across every mastracode invocation on the\n * host, subprocess or not). Isolating it here means this arm's threads\n * never collide with a developer's own interactive `mastracode` usage. */\nfunction resolveStoragePath(): string {\n return join(resolveAgentprotoHome(), \"mastracode-inprocess\", \"storage.db\")\n}\n\n/** Dedicated, empty home directory so Mastra Code's global config\n * discovery (`~/.claude/skills`, `~/.mastracode/{hooks,commands,skills}`,\n * `~/.agents/skills`) does not implicitly inherit the operator's own\n * personal Claude Code / Mastra Code setup.\n *\n * KNOWN LIMITATION (verified against 0.27.0, not assumed): passing\n * `homeDir` at the top level of `MastraCodeConfig` is NOT sufficient —\n * `createMastraCodeAgentController` resolves `homeDir` for hooks/plugin\n * wiring but does not copy it into `initialState`, and the workspace's\n * skill-path builder reads `state.homeDir`, falling back to the real\n * `os.homedir()` when that's unset. Both `homeDir` AND\n * `initialState: { homeDir }` must be passed for the override to\n * actually reach skill discovery. This does not affect a target repo's\n * own PROJECT-LOCAL `.claude/skills` (relative to `cwd`) — that's the\n * repo's own content, not the operator's personal config, and is\n * intentionally left reachable (mirrors the ACP arm reading a target\n * repo's own `.claude/settings.json`). */\nfunction resolveIsolatedHomeDir(): string {\n return join(resolveAgentprotoHome(), \"mastracode-inprocess\", \"home\")\n}\n\nfunction parseSessionId(sessionId: string): { resourceId: string; threadId: string } {\n const idx = sessionId.indexOf(\":\")\n if (idx <= 0 || idx === sessionId.length - 1) {\n throw new Error(\n `mastracode-inprocess: malformed resumeSessionId '${sessionId}' — expected ` +\n `\"<resourceId>:<threadId>\", the format this arm's own sessionId getter produces.`,\n )\n }\n return { resourceId: sessionId.slice(0, idx), threadId: sessionId.slice(idx + 1) }\n}\n\n/** Narrow shape of `createMastraCode`'s resolved return value this arm\n * actually uses — kept local (not re-exported from `mastracode`) so this\n * file only depends on what it reads. */\ninterface MastraCodeHandle {\n controller: { destroy(): Promise<void> }\n session: {\n thread: { getId(): string | null }\n mode: { get(): string; switch(args: { modeId: string }): Promise<void> }\n }\n /** Present when `bootLocalAgentController` builds an MCP manager (i.e.\n * MCP servers were configured). `createMastraCode` does NOT initialize\n * it automatically — verified against mastracode's own headless CLI\n * entrypoint (`runMCCli` in `dist/chunk-HADE25EX.cjs`), which explicitly\n * calls `mcpManager.initInBackground()` itself right after boot, before\n * running any prompt. Skipping this step (as an earlier version of this\n * arm did) leaves `mcpServers` connected-but-never-initialized: the\n * config is accepted, but no MCP tools ever reach the agent's toolset. */\n mcpManager?: {\n hasServers(): boolean\n initInBackground(): Promise<unknown>\n }\n}\n\nexport function createAgentCliClient(definition: AgentCliHandle): AgentCliClient {\n let handle: MastraCodeHandle | undefined\n let resourceId: string | undefined\n let threadId: string | undefined\n let connectEnv: Record<string, string> = {}\n let connectModel: string | undefined\n let connectEffort: string | undefined\n const pendingByTurn = new Map<string, MCRun>()\n\n return {\n get sessionId(): string | undefined {\n return resourceId && threadId ? `${resourceId}:${threadId}` : undefined\n },\n\n async connect(opts: AgentCliConnectOptions): Promise<void> {\n const isolatedHome = resolveIsolatedHomeDir()\n const storagePath = resolveStoragePath()\n mkdirSync(isolatedHome, { recursive: true })\n mkdirSync(dirname(storagePath), { recursive: true })\n\n handle = (await createMastraCode({\n cwd: opts.cwd,\n homeDir: isolatedHome,\n initialState: { homeDir: isolatedHome },\n disablePlugins: true,\n storage: { backend: \"libsql\", url: `file:${storagePath}`, isRemote: false },\n ...(opts.mcpServers?.length\n ? { mcpServers: toFileBasedMcpServers(opts.mcpServers) }\n : {}),\n })) as unknown as MastraCodeHandle\n\n // `createMastraCode` builds the MCP manager but does not initialize\n // it — mirror mastracode's own headless CLI (`runMCCli`), which\n // explicitly awaits this before running any prompt. Without it, MCP\n // servers are configured but never connected, so their tools never\n // reach the agent. Best-effort: a failed MCP connection shouldn't\n // fail the whole session (matches the CLI's own warn-and-continue).\n if (handle.mcpManager?.hasServers()) {\n try {\n await handle.mcpManager.initInBackground()\n } catch {\n // Best-effort — the session still starts on its non-MCP tools.\n }\n }\n\n connectEnv = opts.env\n connectModel = opts.model\n connectEffort = opts.effort\n\n if (opts.resumeSessionId) {\n ;({ resourceId, threadId } = parseSessionId(opts.resumeSessionId))\n } else {\n resourceId = `agentproto-mastracode-inprocess-${randomUUID()}`\n threadId = undefined\n }\n },\n\n async send(turnId: string, message: unknown): Promise<void> {\n if (!handle || !resourceId) {\n throw new Error(\"mastracode-inprocess: send() called before connect()\")\n }\n const prompt = extractPromptText(message)\n\n const requestedMode = connectEnv[MODE_ENV_KEY]\n if (requestedMode && VALID_RUN_MODES.has(requestedMode)) {\n if (handle.session.mode.get() !== requestedMode) {\n await handle.session.mode.switch({ modeId: requestedMode })\n }\n }\n\n const thinkingLevel =\n connectEffort && VALID_THINKING_LEVELS.has(connectEffort)\n ? (connectEffort as \"off\" | \"low\" | \"medium\" | \"high\" | \"xhigh\")\n : undefined\n\n const run = runMC({\n controller: handle.controller as never,\n session: handle.session as never,\n prompt,\n resourceId,\n thread: threadId ? { id: threadId } : undefined,\n ...(connectModel ? { model: connectModel } : {}),\n ...(thinkingLevel ? { thinkingLevel } : {}),\n ...(definition.session?.max_turns\n ? { maxTurns: definition.session.max_turns }\n : {}),\n })\n pendingByTurn.set(turnId, run)\n },\n\n async *events(): AsyncIterable<StreamEvent> {\n const run = Array.from(pendingByTurn.values()).at(-1)\n if (!run) return\n const state = createMastraMapperState()\n for await (const evt of run) {\n // Track the thread id live from in-band events, synchronously\n // with the loop that's about to map+yield them — no race against\n // `run.result` resolving on a separate microtask.\n if (evt.type === \"thread_created\") threadId = evt.thread.id\n else if (evt.type === \"thread_changed\") threadId = evt.threadId\n const sid = resourceId && threadId ? `${resourceId}:${threadId}` : \"\"\n const mapped = mapMastraEvent(\n evt as unknown as Record<string, unknown>,\n sid,\n [],\n state,\n )\n if (mapped) yield mapped\n }\n // Fallback for the (unverified) case where a fresh thread's first\n // binding happens inside `sendMessage()` without an in-band\n // `thread_created`/`thread_changed` event — `result.threadId` is\n // always populated once the run settles, so this is authoritative\n // even if the loop above never fired.\n const result = await run.result\n if (result.threadId) threadId = result.threadId\n },\n\n async cancel(turnId: string): Promise<void> {\n pendingByTurn.get(turnId)?.abort()\n },\n\n async close(): Promise<void> {\n await handle?.controller.destroy()\n },\n }\n}\n\nfunction extractPromptText(message: unknown): string {\n if (typeof message === \"string\") return message\n if (Array.isArray(message)) {\n return (message as Array<Record<string, unknown>>)\n .filter(b => b.type === \"text\" && typeof b.text === \"string\")\n .map(b => b.text as string)\n .join(\"\\n\")\n }\n if (message !== null && typeof message === \"object\") {\n const m = message as Record<string, unknown>\n if (typeof m.text === \"string\") return m.text\n }\n return JSON.stringify(message)\n}\n","/**\n * @agentproto/adapter-mastracode-inprocess — AIP-45 adapter for Mastra Code,\n * driven in-process via the `mastracode` / `mastracode/headless` SDK\n * instead of spawning a subprocess.\n *\n * This is a `protocol: \"proprietary\"` manifest: `createAgentCliRuntime`\n * skips the subprocess spawn entirely for this protocol and instead\n * dynamic-imports `adapter` (this very package) and calls its exported\n * `createAgentCliClient(definition)` factory — see\n * `createProprietaryProtocolArm` in `@agentproto/driver-agent-cli`. The\n * factory itself lives in `./client.ts`; this file only builds and\n * exports the manifest handle.\n *\n * import { mastracodeInprocess, mastracodeInprocessRuntime } from \"@agentproto/adapter-mastracode-inprocess\"\n * const session = await mastracodeInprocessRuntime().start()\n * for await (const evt of session.send({ role: \"user\", content: \"...\" })) {\n * console.log(evt)\n * }\n * await session.close()\n *\n * Why a separate package from `@agentproto/adapter-mastracode` (the\n * `print` arm) rather than a second export of it — see\n * MASTRACODE-INPROCESS.md.\n */\n\nimport {\n createAgentCliRuntime,\n defineAgentCli,\n type AgentCliHandle,\n type AgentCliRuntime,\n} from \"@agentproto/driver-agent-cli\"\n\nexport const mastracodeInprocess: AgentCliHandle = defineAgentCli({\n name: \"Mastra Code (in-process)\",\n id: \"mastracode-inprocess\",\n description:\n \"Mastra Code terminal coding agent driven in-process via the `mastracode` SDK \" +\n \"(createMastraCode + runMC) instead of spawning the CLI as a subprocess. Same \" +\n \"underlying agent as @agentproto/adapter-mastracode, no child process.\",\n version: \"0.1.0\",\n // No binary is ever spawned for a proprietary arm — `bin` is required by\n // the AIP-45 schema regardless, so this is a documented placeholder\n // rather than a real executable. `createAgentCliRuntime` checks\n // `protocol === \"proprietary\"` and never reads this field.\n bin: \"in-process\",\n install: [{ method: \"npm\", package: \"@agentproto/adapter-mastracode-inprocess\" }],\n version_check: {\n cmd: \"npm view mastracode version\",\n parse: \"(\\\\d+\\\\.\\\\d+\\\\.\\\\d+)\",\n // Matches this package's pinned `mastracode` dependency (see package.json).\n range: \">=0.27.0\",\n timeout_ms: 15_000,\n },\n auth: {\n state: {\n env: [\n \"ANTHROPIC_API_KEY\",\n \"OPENAI_API_KEY\",\n \"OPENROUTER_API_KEY\",\n \"GOOGLE_GENERATIVE_AI_API_KEY\",\n ],\n },\n },\n sandbox: {\n model: \"in-process\",\n note:\n \"Runs inside the host process — there is no subprocess boundary to sandbox. \" +\n \"File and shell tool access is whatever Mastra Code's own tool policy grants \" +\n \"for this session, with the host process's OS permissions (not a separately \" +\n \"confined child). Storage and home dir ARE isolated per MASTRACODE-INPROCESS.md \" +\n \"so this arm's sessions never collide with a developer's own interactive \" +\n \"mastracode usage, but that isolation is not a security sandbox.\",\n },\n protocol: \"proprietary\",\n adapter: \"@agentproto/adapter-mastracode-inprocess\",\n session: {\n mode: \"resumable\",\n idle_timeout_ms: 1_800_000,\n context_carryover: true,\n },\n models: {\n default: \"anthropic/claude-sonnet-4-5\",\n // Anthropic is no longer advertised as a pickable escalation — only the\n // adapter's own default Claude model stays listed (repointing the default\n // is out of scope). The extra Sonnet + gateway dupe are dropped from the\n // menu; the free-form `model` option still accepts any id.\n allowed: [\n \"anthropic/claude-sonnet-4-5\",\n \"openai/gpt-5.1\",\n \"openai/gpt-5.1-mini\",\n \"google/gemini-2.5-flash\",\n ],\n env: {\n anthropic: \"ANTHROPIC_API_KEY\",\n openai: \"OPENAI_API_KEY\",\n openrouter: \"OPENROUTER_API_KEY\",\n google: \"GOOGLE_GENERATIVE_AI_API_KEY\",\n },\n },\n capabilities: {\n streaming: true,\n tool_calls: true,\n sub_agents: true,\n file_io: true,\n multimodal: false,\n // The composite \"<resourceId>:<threadId>\" sessionId round-trips through\n // `client.ts`'s connect(resumeSessionId) and has been verified to\n // recall prior-turn context across a fresh process (see README.md).\n resumable: true,\n bidirectional: false,\n },\n // Mode selection has no argv to append to (no spawn) — modes patch the\n // one channel `composeSpawn` threads through for every protocol\n // regardless: env. `client.ts` reads `AGENTPROTO_MASTRACODE_MODE` off\n // the composed env and switches the live session's mode before send().\n modes: [\n {\n id: \"default\",\n description: \"Default headless mode. Mastra Code defaults to build mode when omitted.\",\n },\n {\n id: \"plan\",\n description:\n \"Plan-only mode — analyze architecture and propose implementation plans before writing code.\",\n env: { AGENTPROTO_MASTRACODE_MODE: \"plan\" },\n },\n {\n id: \"build\",\n description:\n \"Build mode — file edits and shell commands use Mastra Code's configured permissions.\",\n env: { AGENTPROTO_MASTRACODE_MODE: \"build\" },\n },\n {\n id: \"fast\",\n description: \"Fast mode — lower-latency answers and small edits.\",\n env: { AGENTPROTO_MASTRACODE_MODE: \"fast\" },\n },\n ],\n // `model`/`effort` here are the two ids `createAgentCliRuntime` always\n // reads off `config.options` for the generic model/effort passthrough\n // (see `define-agent-cli.ts`) — declaring them is what lets a host pass\n // `agent_start({ model, effort })` without composeSpawn rejecting the\n // config as an unknown option. Both travel to `client.ts`'s connect()\n // directly (not via bin_args/env), so no `bin_args_template`/`env` patch\n // is declared on either.\n options: [\n {\n id: \"model\",\n type: \"string\",\n description:\n \"Provider/model override for this operator binding (e.g. `anthropic/claude-sonnet-4-5`).\",\n },\n {\n id: \"effort\",\n type: \"enum\",\n enum: [\"off\", \"low\", \"medium\", \"high\", \"xhigh\"],\n description:\n \"Thinking level, mapped 1:1 to Mastra Code's `thinkingLevel` run option.\",\n },\n ],\n continuation: {\n default: \"none\",\n supported: [\"none\", \"transcript\", \"native-resume\"],\n },\n metadata: {\n proprietary: {\n checked: \"2026-07-02\",\n result:\n \"Verified in-process against mastracode 0.27.0 / @mastra/core 1.48.0: a turn \" +\n \"returns real streamed content, and cross-process resume (kill the process, \" +\n \"start a fresh one, reattach via the composite sessionId) recalls prior-turn \" +\n \"context. See MASTRACODE-INPROCESS.md for the composite sessionId format.\",\n },\n },\n tags: [\"mastracode\", \"mastra\", \"proprietary\", \"in-process\", \"agent-runtime\", \"coding\"],\n})\n\nexport function mastracodeInprocessRuntime(): AgentCliRuntime {\n return createAgentCliRuntime(mastracodeInprocess)\n}\n\nexport { createAgentCliClient } from \"./client.js\"\nexport type { AgentCliHandle, AgentCliRuntime }\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentproto/adapter-mastracode-inprocess",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "@agentproto/adapter-mastracode-inprocess — AIP-45 AGENT-CLI adapter for Mastra Code driven in-process via the `mastracode`/`mastracode/headless` SDK, instead of spawning a subprocess. Implements the `protocol: \"proprietary\"` arm contract directly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentproto",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"url": "https://github.com/agentproto/ts",
|
|
19
19
|
"directory": "adapters/mastracode-inprocess"
|
|
20
20
|
},
|
|
21
|
-
"license": "
|
|
21
|
+
"license": "Apache-2.0",
|
|
22
22
|
"type": "module",
|
|
23
23
|
"main": "dist/index.mjs",
|
|
24
24
|
"module": "dist/index.mjs",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@mastra/core": "1.48.0",
|
|
46
46
|
"mastracode": "0.27.0",
|
|
47
|
-
"@agentproto/driver-agent-cli": "0.
|
|
47
|
+
"@agentproto/driver-agent-cli": "1.0.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/node": "^25.6.2",
|