maka-agent 0.2.0-dev.12.20260901 → 0.2.0-dev.14.20260902

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.
Files changed (105) hide show
  1. package/THIRD_PARTY_NOTICES.txt +2 -2
  2. package/dist/acp/maka-acp-agent.js +6 -3
  3. package/dist/acp/session-registry.js +307 -0
  4. package/dist/acp/stdio-server.js +20 -1
  5. package/dist/cli-core.js +15 -2
  6. package/dist/pi-transcript.js +1 -1
  7. package/dist/pi-tui-layout.js +1 -1
  8. package/dist/pi-tui-mcp-status.js +1 -1
  9. package/dist/pi-tui-runner.js +1 -1
  10. package/dist/runtime-host-access-command.js +37 -4
  11. package/dist/runtime-host-capability-provider-command.js +16 -2
  12. package/dist/runtime-host-cli-context.js +73 -3
  13. package/dist/runtime-host-cli.js +37 -6
  14. package/dist/runtime-host-run-command.js +3 -1
  15. package/dist/runtime-host-update-command.js +59 -31
  16. package/dist/tui-copy-catalog.js +4 -2
  17. package/native/runtime-host-peer/prebuilds/darwin-arm64/maka_runtime_host_peer.node +0 -0
  18. package/native/runtime-host-peer/prebuilds/linux-arm64/maka_runtime_host_peer.node +0 -0
  19. package/native/runtime-host-peer/prebuilds/linux-x64/maka_runtime_host_peer.node +0 -0
  20. package/native/runtime-host-peer/prebuilds/win32-x64/maka_runtime_host_peer.node +0 -0
  21. package/node_modules/@maka/core/dist/attachments.js +12 -0
  22. package/node_modules/@maka/core/dist/connection-error-copy.js +17 -34
  23. package/node_modules/@maka/core/dist/events.js +0 -13
  24. package/node_modules/@maka/core/dist/maka-wordmark.js +23 -0
  25. package/node_modules/@maka/core/dist/model-catalog.js +22 -1
  26. package/node_modules/@maka/core/dist/runtime-event.js +1 -0
  27. package/node_modules/@maka/core/dist/runtime-policy/connection-catalog-codec.js +50 -1
  28. package/node_modules/@maka/core/dist/runtime-policy/credential-vault-codec.js +9 -1
  29. package/node_modules/@maka/core/dist/runtime-policy/model-catalog-entry-codec.js +10 -1
  30. package/node_modules/@maka/core/dist/runtime-policy/policy-codec.js +75 -0
  31. package/node_modules/@maka/core/dist/runtime-policy.js +4 -2
  32. package/node_modules/@maka/core/dist/session.js +1 -0
  33. package/node_modules/@maka/core/dist/settings.js +10 -2
  34. package/node_modules/@maka/core/dist/usage-record-schema.js +11 -1
  35. package/node_modules/@maka/core/package.json +2 -1
  36. package/node_modules/@maka/mcp/dist/index.js +1 -0
  37. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +52 -80
  38. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +178 -140
  39. package/node_modules/@maka/runtime/dist/archive-read-tool.js +26 -5
  40. package/node_modules/@maka/runtime/dist/builtin-tools.js +27 -2
  41. package/node_modules/@maka/runtime/dist/context-budget-policy.js +0 -12
  42. package/node_modules/@maka/runtime/dist/conversation-copy.js +66 -43
  43. package/node_modules/@maka/runtime/dist/durable-tool-result-projection.js +31 -0
  44. package/node_modules/@maka/runtime/dist/history-compact-error.js +10 -2
  45. package/node_modules/@maka/runtime/dist/history-compact-input-fit.js +7 -1
  46. package/node_modules/@maka/runtime/dist/history-compaction.js +13 -22
  47. package/node_modules/@maka/runtime/dist/model-history.js +41 -16
  48. package/node_modules/@maka/runtime/dist/provider-image-overflow-recovery.js +12 -31
  49. package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +3 -0
  50. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +13 -2
  51. package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +3 -6
  52. package/node_modules/@maka/runtime/dist/shell-tools.js +77 -1
  53. package/node_modules/@maka/runtime/dist/tool-availability.js +74 -5
  54. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +333 -52
  55. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +34 -3
  56. package/node_modules/@maka/runtime/dist/tool-runtime.js +12 -0
  57. package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +0 -3
  58. package/node_modules/@maka/runtime-host/dist/client/catalog-reader.js +40 -13
  59. package/node_modules/@maka/runtime-host/dist/client/connection.js +50 -31
  60. package/node_modules/@maka/runtime-host/dist/client/host-profile.js +48 -4
  61. package/node_modules/@maka/runtime-host/dist/client/index.js +2 -2
  62. package/node_modules/@maka/runtime-host/dist/client/owner-connection-code.js +32 -1
  63. package/node_modules/@maka/runtime-host/dist/client/peer-client.js +22 -4
  64. package/node_modules/@maka/runtime-host/dist/operator/access-management-frame.js +10 -1
  65. package/node_modules/@maka/runtime-host/dist/peer-mesh/node.js +56 -12
  66. package/node_modules/@maka/runtime-host/dist/peer-mesh/owner.js +3 -0
  67. package/node_modules/@maka/runtime-host/dist/protocol/configuration.js +55 -9
  68. package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +37 -0
  69. package/node_modules/@maka/runtime-host/dist/protocol/index.js +17 -1
  70. package/node_modules/@maka/runtime-host/dist/protocol/network-proxy.js +1 -7
  71. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +2 -0
  72. package/node_modules/@maka/runtime-host/dist/protocol/runtime-policy.js +48 -1
  73. package/node_modules/@maka/runtime-host/dist/protocol/session-collaboration.js +4 -2
  74. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +2 -12
  75. package/node_modules/@maka/runtime-host/dist/server/access-authority.js +2 -1
  76. package/node_modules/@maka/runtime-host/dist/server/agent-graph-execution-coordinator.js +1 -2
  77. package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +0 -9
  78. package/node_modules/@maka/runtime-host/dist/server/configuration-coordinator.js +20 -1
  79. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +46 -24
  80. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +4 -1
  81. package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +15 -0
  82. package/node_modules/@maka/runtime-host/dist/server/listener-set.js +8 -4
  83. package/node_modules/@maka/runtime-host/dist/server/network-proxy-coordinator.js +0 -1
  84. package/node_modules/@maka/runtime-host/dist/server/peer-listener.js +3 -0
  85. package/node_modules/@maka/runtime-host/dist/server/runtime-policy-coordinator.js +28 -1
  86. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +3 -3
  87. package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +35 -3
  88. package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +16 -0
  89. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +189 -6
  90. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +4 -1
  91. package/node_modules/@maka/storage/dist/settings-store.js +16 -25
  92. package/node_modules/fast-uri/index.js +215 -47
  93. package/node_modules/fast-uri/lib/schemes.js +9 -4
  94. package/node_modules/fast-uri/lib/utils.js +396 -92
  95. package/node_modules/fast-uri/package.json +1 -1
  96. package/node_modules/qs/.github/THREAT_MODEL.md +3 -3
  97. package/node_modules/qs/CHANGELOG.md +15 -0
  98. package/node_modules/qs/README.md +19 -1
  99. package/node_modules/qs/dist/qs.js +21 -21
  100. package/node_modules/qs/eslint.config.mjs +1 -1
  101. package/node_modules/qs/lib/parse.js +3 -4
  102. package/node_modules/qs/lib/stringify.js +23 -8
  103. package/node_modules/qs/lib/utils.js +10 -3
  104. package/node_modules/qs/package.json +4 -4
  105. package/package.json +1 -1
@@ -4108,7 +4108,7 @@ SOFTWARE.
4108
4108
 
4109
4109
  ================================================================================
4110
4110
 
4111
- Package: fast-uri@3.1.5
4111
+ Package: fast-uri@3.1.7
4112
4112
  Declared license: BSD-3-Clause
4113
4113
  Selected license: BSD-3-Clause
4114
4114
  Repository: git+https://github.com/fastify/fast-uri.git
@@ -6483,7 +6483,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
6483
6483
 
6484
6484
  ================================================================================
6485
6485
 
6486
- Package: qs@6.15.3
6486
+ Package: qs@6.16.0
6487
6487
  Declared license: BSD-3-Clause
6488
6488
  Selected license: BSD-3-Clause
6489
6489
  Repository: https://github.com/ljharb/qs.git
@@ -18,10 +18,13 @@
18
18
  */
19
19
  import { agent, methods } from '@agentclientprotocol/sdk';
20
20
  export function createMakaAcpAgent(options) {
21
- return agent({ name: 'maka' }).onRequest(methods.agent.initialize, () => ({
21
+ return agent({ name: 'maka' })
22
+ .onRequest(methods.agent.initialize, () => ({
22
23
  protocolVersion: 1,
23
- agentCapabilities: {},
24
+ agentCapabilities: { sessionCapabilities: { list: {} } },
24
25
  authMethods: [],
25
26
  agentInfo: { name: 'maka', title: 'Maka', version: options.version },
26
- }));
27
+ }))
28
+ .onRequest(methods.agent.session.new, ({ params }) => options.sessionRegistry.create(params))
29
+ .onRequest(methods.agent.session.list, ({ params }) => options.sessionRegistry.list(params));
27
30
  }
@@ -0,0 +1,307 @@
1
+ /*
2
+ * Licensed to the Apache Software Foundation (ASF) under one
3
+ * or more contributor license agreements. See the NOTICE file
4
+ * distributed with this work for additional information
5
+ * regarding copyright ownership. The ASF licenses this file
6
+ * to you under the Apache License, Version 2.0 (the
7
+ * "License"); you may not use this file except in compliance
8
+ * with the License. You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing,
13
+ * software distributed under the License is distributed on an
14
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ * KIND, either express or implied. See the License for the
16
+ * specific language governing permissions and limitations
17
+ * under the License.
18
+ */
19
+ import { randomUUID } from 'node:crypto';
20
+ import { realpath } from 'node:fs/promises';
21
+ import { isAbsolute, normalize } from 'node:path';
22
+ import { RequestError, } from '@agentclientprotocol/sdk';
23
+ import { readRuntimeHostSessionCatalogPage, RuntimeHostCatalogReadError, RuntimeHostOperationError, RuntimeHostRequestInterruptedError, RuntimeHostSessionCatalogRevisionChangedError, } from '@maka/runtime-host/client';
24
+ import { SESSION_CATALOG_CURSOR_MAX_BYTES, SESSION_CATALOG_CWD_MAX_BYTES, } from '@maka/runtime-host/protocol';
25
+ const ACP_SESSION_CURSOR_MAX_BYTES = 8 * 1024;
26
+ /** Owns all Runtime Host resources associated with one ACP connection. */
27
+ export class AcpSessionRegistry {
28
+ #connect;
29
+ #newSessionId;
30
+ #inFlightOperations = new Set();
31
+ #connection;
32
+ #connectTask;
33
+ #connectAbortController;
34
+ #closing = false;
35
+ #connectionCloseTask;
36
+ #disposeTask;
37
+ constructor(options) {
38
+ this.#connect = options.connect;
39
+ this.#newSessionId = options.newSessionId ?? randomUUID;
40
+ }
41
+ async create(params) {
42
+ this.#assertOpen('session.create');
43
+ validateNewSessionParams(params);
44
+ return this.#track(this.#create(params));
45
+ }
46
+ async list(params) {
47
+ this.#assertOpen('session.catalog.query');
48
+ return this.#track(this.#list(params));
49
+ }
50
+ dispose() {
51
+ this.#closing = true;
52
+ this.#connectAbortController?.abort();
53
+ this.#disposeTask ??= this.#dispose();
54
+ return this.#disposeTask;
55
+ }
56
+ async #create(params) {
57
+ const connection = await this.#getConnection('session.create');
58
+ const sessionId = this.#newSessionId();
59
+ try {
60
+ await connection.request('session.create', {
61
+ sessionId,
62
+ workspace: { kind: 'host_path', path: params.cwd },
63
+ modelTarget: { kind: 'default' },
64
+ });
65
+ }
66
+ catch (error) {
67
+ throw requestErrorFromRuntimeHost(error, 'session.create', { sessionId });
68
+ }
69
+ return { sessionId };
70
+ }
71
+ async #list(params) {
72
+ const cursor = params.cursor == null ? undefined : decodeAcpSessionCursor(params.cursor);
73
+ const requestedCwd = params.cwd == null ? undefined : await normalizeCwd(params.cwd);
74
+ if (cursor && requestedCwd !== undefined && cursor.cwd !== requestedCwd) {
75
+ throw RequestError.invalidParams({ reason: 'cursor_cwd_mismatch' }, 'cursor was created for a different cwd filter');
76
+ }
77
+ const cwd = requestedCwd ?? cursor?.cwd ?? null;
78
+ const connection = await this.#getConnection('session.catalog.query');
79
+ let page;
80
+ try {
81
+ page = await readRuntimeHostSessionCatalogPage(connection, cursor ? { revision: cursor.revision, cursor: cursor.cursor } : undefined);
82
+ }
83
+ catch (error) {
84
+ if (error instanceof RuntimeHostSessionCatalogRevisionChangedError) {
85
+ throw RequestError.invalidParams({ reason: 'stale_cursor' }, 'session catalog changed; restart listing from the first page');
86
+ }
87
+ throw requestErrorFromRuntimeHost(error, 'session.catalog.query');
88
+ }
89
+ const sessions = page.sessions.flatMap((session) => {
90
+ if ('kind' in session || (cwd !== null && session.workspace.hostCwd !== cwd))
91
+ return [];
92
+ const updatedAt = isoTimestamp(session.activityAt);
93
+ return [
94
+ {
95
+ sessionId: session.id,
96
+ cwd: session.workspace.hostCwd,
97
+ title: session.name,
98
+ ...(updatedAt ? { updatedAt } : {}),
99
+ },
100
+ ];
101
+ });
102
+ return {
103
+ sessions,
104
+ ...(page.nextCursor
105
+ ? { nextCursor: encodeAcpSessionCursor({ ...page.nextCursor, cwd }) }
106
+ : {}),
107
+ };
108
+ }
109
+ async #dispose() {
110
+ const connectionClose = this.#closeOwnedConnection();
111
+ await Promise.allSettled([connectionClose]);
112
+ await Promise.allSettled([...this.#inFlightOperations]);
113
+ }
114
+ #closeOwnedConnection() {
115
+ const connection = this.#connection;
116
+ const connectTask = this.#connectTask;
117
+ if (!connection && !connectTask)
118
+ return Promise.resolve();
119
+ this.#connectionCloseTask ??= connection
120
+ ? Promise.resolve().then(() => connection.close())
121
+ : connectTask.then((connected) => connected.close(), () => undefined);
122
+ return this.#connectionCloseTask;
123
+ }
124
+ async #getConnection(operation) {
125
+ this.#assertOpen(operation);
126
+ if (this.#connection)
127
+ return this.#connection;
128
+ let connectController = this.#connectAbortController;
129
+ if (!this.#connectTask) {
130
+ connectController = new AbortController();
131
+ this.#connectAbortController = connectController;
132
+ this.#connectTask = Promise.resolve().then(() => {
133
+ if (this.#closing)
134
+ throw registryClosedError('connect');
135
+ connectController.signal.throwIfAborted();
136
+ return this.#connect(connectController.signal);
137
+ });
138
+ }
139
+ const connectTask = this.#connectTask;
140
+ let connection;
141
+ try {
142
+ connection = await connectTask;
143
+ }
144
+ catch {
145
+ if (this.#connectTask === connectTask)
146
+ this.#connectTask = undefined;
147
+ if (this.#connectAbortController === connectController) {
148
+ this.#connectAbortController = undefined;
149
+ }
150
+ if (this.#closing)
151
+ throw registryClosedError('connect');
152
+ throw RequestError.internalError({
153
+ source: 'runtime_host',
154
+ operation: 'connect',
155
+ code: 'connection_failed',
156
+ }, 'Runtime Host connection failed');
157
+ }
158
+ if (this.#connectAbortController === connectController) {
159
+ this.#connectAbortController = undefined;
160
+ }
161
+ if (this.#closing) {
162
+ await this.#closeOwnedConnection().catch(() => undefined);
163
+ throw registryClosedError('connect');
164
+ }
165
+ this.#connection ??= connection;
166
+ return this.#connection;
167
+ }
168
+ async #track(operation) {
169
+ this.#inFlightOperations.add(operation);
170
+ try {
171
+ return await operation;
172
+ }
173
+ finally {
174
+ this.#inFlightOperations.delete(operation);
175
+ }
176
+ }
177
+ #assertOpen(operation) {
178
+ if (!this.#closing)
179
+ return;
180
+ throw registryClosedError(operation);
181
+ }
182
+ }
183
+ function registryClosedError(operation) {
184
+ return RequestError.internalError({ source: 'runtime_host', operation, code: 'registry_closed' }, 'ACP session registry is closed');
185
+ }
186
+ function validateNewSessionParams(params) {
187
+ assertBoundedAbsoluteCwd(params.cwd);
188
+ if (params.mcpServers.length > 0) {
189
+ throw RequestError.invalidParams({ field: 'mcpServers', reason: 'unsupported' }, 'MCP servers are not supported by this ACP adapter yet');
190
+ }
191
+ if ((params.additionalDirectories?.length ?? 0) > 0) {
192
+ throw RequestError.invalidParams({ field: 'additionalDirectories', reason: 'unsupported' }, 'Additional directories are not supported by this ACP adapter yet');
193
+ }
194
+ }
195
+ function requestErrorFromRuntimeHost(error, operation, extra = {}) {
196
+ const data = { ...runtimeHostErrorData(error, operation), ...extra };
197
+ if (error instanceof RuntimeHostOperationError && error.code === 'invalid_request') {
198
+ return RequestError.invalidParams(data, 'Runtime Host rejected the request');
199
+ }
200
+ return RequestError.internalError(data, 'Runtime Host request failed');
201
+ }
202
+ function runtimeHostErrorData(error, operation) {
203
+ if (error instanceof RuntimeHostOperationError) {
204
+ return {
205
+ source: 'runtime_host',
206
+ operation: error.operation,
207
+ code: error.code,
208
+ };
209
+ }
210
+ if (error instanceof RuntimeHostRequestInterruptedError) {
211
+ return {
212
+ source: 'runtime_host',
213
+ operation: error.operation,
214
+ code: 'request_interrupted',
215
+ reason: error.reason,
216
+ dispatch: error.dispatch,
217
+ };
218
+ }
219
+ if (error instanceof RuntimeHostCatalogReadError) {
220
+ return {
221
+ source: 'runtime_host',
222
+ operation,
223
+ code: 'catalog_read_failure',
224
+ reason: error.reason,
225
+ };
226
+ }
227
+ return { source: 'runtime_host', operation, code: 'internal_failure' };
228
+ }
229
+ function encodeAcpSessionCursor(cursor) {
230
+ const encoded = Buffer.from(JSON.stringify(cursor), 'utf8').toString('base64url');
231
+ if (Buffer.byteLength(encoded, 'utf8') > ACP_SESSION_CURSOR_MAX_BYTES) {
232
+ throw RequestError.internalError({
233
+ source: 'runtime_host',
234
+ operation: 'session.catalog.query',
235
+ code: 'cursor_too_large',
236
+ }, 'Runtime Host cursor cannot be represented safely in ACP');
237
+ }
238
+ return encoded;
239
+ }
240
+ function decodeAcpSessionCursor(encoded) {
241
+ try {
242
+ if (encoded.length === 0 || Buffer.byteLength(encoded, 'utf8') > ACP_SESSION_CURSOR_MAX_BYTES) {
243
+ throw new Error('cursor size is invalid');
244
+ }
245
+ const decoded = Buffer.from(encoded, 'base64url');
246
+ if (decoded.toString('base64url') !== encoded)
247
+ throw new Error('cursor encoding is invalid');
248
+ const value = JSON.parse(decoded.toString('utf8'));
249
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
250
+ throw new Error('cursor body is invalid');
251
+ }
252
+ const record = value;
253
+ if (Object.keys(record).length !== 3 ||
254
+ typeof record.revision !== 'string' ||
255
+ !/^sha256:[0-9a-f]{64}$/.test(record.revision) ||
256
+ typeof record.cursor !== 'string' ||
257
+ record.cursor.length === 0 ||
258
+ Buffer.byteLength(record.cursor, 'utf8') > SESSION_CATALOG_CURSOR_MAX_BYTES ||
259
+ !validCursorCwd(record.cwd)) {
260
+ throw new Error('cursor fields are invalid');
261
+ }
262
+ return {
263
+ revision: record.revision,
264
+ cursor: record.cursor,
265
+ cwd: record.cwd,
266
+ };
267
+ }
268
+ catch {
269
+ throw RequestError.invalidParams({ reason: 'invalid_cursor' }, 'cursor is invalid');
270
+ }
271
+ }
272
+ function validCursorCwd(value) {
273
+ return (value === null ||
274
+ (typeof value === 'string' &&
275
+ isAbsolute(value) &&
276
+ normalize(value) === value &&
277
+ Buffer.byteLength(value, 'utf8') <= SESSION_CATALOG_CWD_MAX_BYTES));
278
+ }
279
+ async function normalizeCwd(cwd) {
280
+ assertBoundedAbsoluteCwd(cwd);
281
+ const lexical = normalize(cwd);
282
+ try {
283
+ return await realpath(lexical);
284
+ }
285
+ catch (error) {
286
+ const code = error.code;
287
+ if (code === 'ENOENT' || code === 'ENOTDIR')
288
+ return lexical;
289
+ throw RequestError.internalError({
290
+ source: 'filesystem',
291
+ operation: 'cwd.realpath',
292
+ code: code ?? 'internal_failure',
293
+ }, 'cwd could not be canonicalized');
294
+ }
295
+ }
296
+ function assertBoundedAbsoluteCwd(cwd) {
297
+ if (!isAbsolute(cwd)) {
298
+ throw RequestError.invalidParams({ field: 'cwd', reason: 'must_be_absolute' }, 'cwd must be an absolute path');
299
+ }
300
+ if (Buffer.byteLength(cwd, 'utf8') > SESSION_CATALOG_CWD_MAX_BYTES) {
301
+ throw RequestError.invalidParams({ field: 'cwd', reason: 'too_large' }, 'cwd exceeds the Runtime Host path limit');
302
+ }
303
+ }
304
+ function isoTimestamp(timestamp) {
305
+ const date = new Date(timestamp);
306
+ return Number.isNaN(date.getTime()) ? undefined : date.toISOString();
307
+ }
@@ -19,7 +19,22 @@
19
19
  import { Readable, Writable } from 'node:stream';
20
20
  import { ndJsonStream } from '@agentclientprotocol/sdk';
21
21
  import { createMakaAcpAgent } from './maka-acp-agent.js';
22
+ import { AcpSessionRegistry } from './session-registry.js';
23
+ import { connectRuntimeHostCliConnection } from '../runtime-host-cli-context.js';
22
24
  export async function runMakaAcpStdioServer(input, dependencies = {}) {
25
+ const sessionRegistry = new AcpSessionRegistry({
26
+ connect: async (signal) => {
27
+ const context = await (dependencies.connectRuntimeHostCliConnection ?? connectRuntimeHostCliConnection)({
28
+ rootPath: input.workspaceRoot,
29
+ clientDataRoot: input.clientDataRoot,
30
+ signal,
31
+ });
32
+ return {
33
+ request: context.connection.request.bind(context.connection),
34
+ close: () => context.close(),
35
+ };
36
+ },
37
+ });
23
38
  const stdin = dependencies.stdin ?? process.stdin;
24
39
  const stdout = dependencies.stdout ?? process.stdout;
25
40
  let stdioError;
@@ -30,7 +45,10 @@ export async function runMakaAcpStdioServer(input, dependencies = {}) {
30
45
  stdout.once('error', recordStdioError);
31
46
  try {
32
47
  const stream = ndJsonStream(Writable.toWeb(stdout), Readable.toWeb(stdin));
33
- const connection = createMakaAcpAgent({ version: input.version }).connect(stream);
48
+ const connection = createMakaAcpAgent({
49
+ version: input.version,
50
+ sessionRegistry,
51
+ }).connect(stream);
34
52
  await connection.closed;
35
53
  if (stdioError) {
36
54
  throw stdioError;
@@ -40,5 +58,6 @@ export async function runMakaAcpStdioServer(input, dependencies = {}) {
40
58
  finally {
41
59
  stdin.off('error', recordStdioError);
42
60
  stdout.off('error', recordStdioError);
61
+ await sessionRegistry.dispose();
43
62
  }
44
63
  }
package/dist/cli-core.js CHANGED
@@ -94,7 +94,7 @@ function helpText(cliCommand) {
94
94
  '',
95
95
  'Commands:',
96
96
  ` ${cliCommand} Start the TUI`,
97
- ` ${cliCommand} --acp Serve ACP v1 over stdio (initialize only; session support in progress)`,
97
+ ` ${cliCommand} --acp Serve ACP v1 over stdio (initialize, session/new, session/list)`,
98
98
  ` ${cliCommand} run ... Run one non-interactive model turn`,
99
99
  ` ${cliCommand} activate ... Run one Cloud Session activation and emit JSONL`,
100
100
  ` ${cliCommand} -p ... Alias for ${cliCommand} run`,
@@ -116,6 +116,7 @@ function helpText(cliCommand) {
116
116
  ` ${cliCommand} runtime-host service reconcile-update [--json]`,
117
117
  ` ${cliCommand} runtime-host access issue --principal <id> --grant <operation>`,
118
118
  ` ${cliCommand} runtime-host access issue --principal <id> --preset <desktop-client|terminal-client>`,
119
+ ` ${cliCommand} runtime-host access connection-code [--name <name>] [--root <path>]`,
119
120
  ` ${cliCommand} runtime-host access list`,
120
121
  ` ${cliCommand} runtime-host access issue --kind capability-provider --principal <id>`,
121
122
  ` ${cliCommand} runtime-host access revoke --credential <id>`,
@@ -251,7 +252,11 @@ export async function runMakaCli(argv = process.argv.slice(2), options = RELEASE
251
252
  }
252
253
  case 'acp': {
253
254
  const { runMakaAcpStdioServer } = await import('./acp/stdio-server.js');
254
- return runMakaAcpStdioServer({ version });
255
+ return runMakaAcpStdioServer({
256
+ workspaceRoot: dataRoots.workspaceRoot,
257
+ clientDataRoot: dataRoots.clientDataRoot,
258
+ version,
259
+ });
255
260
  }
256
261
  case 'runtime-host-serve': {
257
262
  const { runRuntimeHostServiceCli } = await import('./runtime-host-service-command.js');
@@ -591,6 +596,14 @@ export async function runMakaCli(argv = process.argv.slice(2), options = RELEASE
591
596
  currentCredentialFingerprint: command.currentCredentialFingerprint,
592
597
  });
593
598
  }
599
+ case 'runtime-host-access-connection-code': {
600
+ const { runRuntimeHostAccessConnectionCodeCli } = await import('./runtime-host-access-command.js');
601
+ return runRuntimeHostAccessConnectionCodeCli({
602
+ rootPath: command.rootPath ?? dataRoots.workspaceRoot,
603
+ ...(command.expectedRootId ? { expectedRootId: command.expectedRootId } : {}),
604
+ ...(command.name ? { name: command.name } : {}),
605
+ }, command.framed);
606
+ }
594
607
  case 'runtime-host-access-list': {
595
608
  const { runRuntimeHostAccessListCli } = await import('./runtime-host-access-command.js');
596
609
  return runRuntimeHostAccessListCli({
@@ -1383,7 +1383,7 @@ function formatElapsedDuration(elapsedMs) {
1383
1383
  return parts.join(' ');
1384
1384
  }
1385
1385
  const TUI_PENDING_QUEUE_COPY = resolveUiMessageCatalog(defineUiMessageCatalog()(TUI_COPY_RESOURCES['pending-queue']));
1386
- export function renderMakaPiPendingQueue(state, width, platform = process.platform, locale = 'en') {
1386
+ export function renderMakaPiPendingQueue(state, width, platform, locale) {
1387
1387
  if (state.steering.length === 0 && state.followup.length === 0) {
1388
1388
  return [];
1389
1389
  }
@@ -92,7 +92,7 @@ export class MakaActivityStripComponent {
92
92
  export class MakaPendingQueueComponent {
93
93
  state;
94
94
  locale;
95
- constructor(state, locale = 'en') {
95
+ constructor(state, locale) {
96
96
  this.state = state;
97
97
  this.locale = locale;
98
98
  }
@@ -617,7 +617,7 @@ function actionNotice(result, locale) {
617
617
  };
618
618
  }
619
619
  function resultCopy(locale, code) {
620
- return MCP_STATUS_COPY[locale].editor.results[code] ?? code;
620
+ return MCP_STATUS_COPY[locale].editor.results[code];
621
621
  }
622
622
  function confirmAddDocument(draft, locale) {
623
623
  const editor = MCP_STATUS_COPY[locale].editor;
@@ -2797,7 +2797,7 @@ export async function runMakaPiTui(input) {
2797
2797
  state.entries.push({
2798
2798
  kind: 'notice',
2799
2799
  level: 'error',
2800
- text: 'Usage: /copy [all]',
2800
+ text: copyCopy.usage,
2801
2801
  });
2802
2802
  requestRender();
2803
2803
  return;
@@ -16,8 +16,10 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { randomUUID } from 'node:crypto';
20
+ import { hostname } from 'node:os';
19
21
  import { truncateUtf8 } from '@maka/core/diagnostic-log';
20
- import { connectExistingRuntimeHost, consumeAccessCredentialDelivery, } from '@maka/runtime-host/client';
22
+ import { connectExistingRuntimeHost, consumeAccessCredentialDelivery, issueRuntimeHostOwnerConnectionCode, REMOTE_DESKTOP_OWNER_ACCESS_POLICY, } from '@maka/runtime-host/client';
21
23
  import { isOperationKey, REMOTE_OWNER_OPERATION_GRANTS, RUNTIME_HOST_PROTOCOL_VERSION, } from '@maka/runtime-host/protocol';
22
24
  import { readRuntimeHostAccessCredentialMetadata, } from '@maka/runtime-host/server';
23
25
  import { encodeRuntimeHostAccessManagementFrame, RUNTIME_HOST_ACCESS_MANAGEMENT_ERROR_MESSAGE_MAX_BYTES, } from '@maka/runtime-host/operator';
@@ -63,6 +65,36 @@ export async function runRuntimeHostAccessListCli(options, framed = false) {
63
65
  return 1;
64
66
  }
65
67
  }
68
+ export async function runRuntimeHostAccessConnectionCodeCli(options, framed = false) {
69
+ let connection;
70
+ try {
71
+ connection = await connectLocalOwner(options.rootPath, options.expectedRootId);
72
+ const connectionCode = await issueRuntimeHostOwnerConnectionCode({
73
+ rootPath: options.rootPath,
74
+ name: options.name?.trim() || truncateUtf8(hostname(), 128) || 'Runtime Host',
75
+ principalId: `connection-code:${randomUUID()}`,
76
+ client: connection,
77
+ });
78
+ process.stdout.write(framed
79
+ ? encodeRuntimeHostAccessManagementFrame({
80
+ schemaVersion: 1,
81
+ kind: 'result',
82
+ action: 'connection-code',
83
+ connectionCode,
84
+ })
85
+ : `${connectionCode}\n`);
86
+ return 0;
87
+ }
88
+ catch (error) {
89
+ if (!framed)
90
+ throw error;
91
+ writeAccessManagementError('connection-code', error);
92
+ return 1;
93
+ }
94
+ finally {
95
+ await connection?.close();
96
+ }
97
+ }
66
98
  export async function runRuntimeHostAccessPrepareCli(options) {
67
99
  try {
68
100
  const before = await listRuntimeHostAccessCredentials(options);
@@ -146,12 +178,13 @@ export function resolveRuntimeHostAccessIssue(options) {
146
178
  canUseHostPaths: options.canUseHostPaths,
147
179
  };
148
180
  }
149
- const canPublishClientCapabilities = options.preset === 'desktop-client';
150
- const operationGrants = REMOTE_OWNER_OPERATION_GRANTS.filter((operation) => canPublishClientCapabilities || !CLIENT_CAPABILITY_PUBLICATION_OPERATIONS.has(operation));
181
+ if (options.preset === 'desktop-client')
182
+ return REMOTE_DESKTOP_OWNER_ACCESS_POLICY;
183
+ const operationGrants = REMOTE_OWNER_OPERATION_GRANTS.filter((operation) => !CLIENT_CAPABILITY_PUBLICATION_OPERATIONS.has(operation));
151
184
  return {
152
185
  principalKind: 'remote_owner',
153
186
  operationGrants,
154
- canPublishClientCapabilities,
187
+ canPublishClientCapabilities: false,
155
188
  canUseHostPaths: false,
156
189
  };
157
190
  }
@@ -20,7 +20,7 @@ import { createHash } from 'node:crypto';
20
20
  import { readFile } from 'node:fs/promises';
21
21
  import { homedir } from 'node:os';
22
22
  import { dirname, join, resolve } from 'node:path';
23
- import { createCredentialMcpOAuthStorage, McpClientManager } from '@maka/mcp';
23
+ import { createCredentialMcpOAuthStorage, formatMcpDiagnosticText, McpClientManager, } from '@maka/mcp';
24
24
  import { createFileCredentialStore } from '@maka/storage/credential-store';
25
25
  import { normalizeMcpConfig } from '@maka/storage/mcp-config-store';
26
26
  import { connectRemoteRuntimeHost, loadOrCreateRuntimeHostClientInstanceId, remoteRuntimeHostUnavailableError, RuntimeHostPermanentReconnectError, startRuntimeHostCapabilityProviderService, } from '@maka/runtime-host/client';
@@ -93,7 +93,7 @@ export async function runRuntimeHostCapabilityProviderCli(options) {
93
93
  });
94
94
  await runRuntimeHostProcessLifecycle(service, {
95
95
  onReady: () => {
96
- process.stdout.write(`Runtime Host capability provider is connected (${manager.toolSnapshot().tools.length} MCP tools)\n`);
96
+ process.stdout.write(formatRuntimeHostCapabilityProviderReadyMessage(manager));
97
97
  },
98
98
  });
99
99
  return 0;
@@ -142,6 +142,20 @@ async function connectRemoteCapabilityProvider(input) {
142
142
  throw new Error('Runtime Host is draining');
143
143
  }
144
144
  export { createMcpCapabilityProvider } from './mcp-capability-provider.js';
145
+ export function formatRuntimeHostCapabilityProviderReadyMessage(manager) {
146
+ const failures = manager
147
+ .statuses()
148
+ .filter((status) => status.state === 'error' ||
149
+ status.state === 'disconnected' ||
150
+ status.state === 'needs-auth')
151
+ .sort((left, right) => left.serverId.localeCompare(right.serverId));
152
+ const failureSummary = failures.length === 0
153
+ ? ''
154
+ : `; ${failures.length} ${failures.length === 1 ? 'server' : 'servers'} failed: ${failures
155
+ .map((status) => `${formatMcpDiagnosticText(status.serverId)} — ${status.error ?? status.state}`)
156
+ .join('; ')}`;
157
+ return `Runtime Host capability provider is connected (${manager.toolSnapshot().tools.length} MCP tools${failureSummary})\n`;
158
+ }
145
159
  function reportRefreshFailure(error) {
146
160
  const message = error instanceof Error ? error.message : String(error);
147
161
  process.stderr.write(`Runtime Host capability publication refresh failed: ${message}\n`);