maka-agent 0.2.0-dev.34.20260915 → 0.2.0-dev.36.20260915

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 (62) hide show
  1. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  2. package/node_modules/@maka/core/dist/model-metadata.generated.js +175 -116
  3. package/node_modules/@maka/core/dist/models-dev-projection.js +1 -0
  4. package/node_modules/@maka/core/dist/provider-registry.js +17 -0
  5. package/node_modules/@maka/eval/dist/harbor-maka-subject.js +13 -3
  6. package/node_modules/@maka/eval/dist/maka-artifacts.js +28 -14
  7. package/node_modules/@maka/eval/dist/maka-subject.js +28 -3
  8. package/node_modules/@maka/eval/harbor/relay_agent.py +42 -2
  9. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +0 -1
  10. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +40 -53
  11. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +28 -47
  12. package/node_modules/@maka/runtime/dist/builtin-tools.js +20 -12
  13. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -2
  14. package/node_modules/@maka/runtime/dist/provider-error-classification.js +29 -38
  15. package/node_modules/@maka/runtime/dist/runtime-kernel.js +1 -0
  16. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +144 -77
  17. package/node_modules/@maka/runtime/node_modules/@ai-sdk/code-mode/dist/run-code-mode.js +6 -19
  18. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +28 -4
  19. package/node_modules/@maka/runtime-host/dist/client/connection.js +20 -2
  20. package/node_modules/@maka/runtime-host/dist/client/hosted-execution-target.js +27 -6
  21. package/node_modules/@maka/runtime-host/dist/client/hosted-execution.js +10 -28
  22. package/node_modules/@maka/runtime-host/dist/client/startup-error.js +1 -1
  23. package/node_modules/@maka/runtime-host/dist/client/wait-for-ready.js +1 -1
  24. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +7 -6
  25. package/node_modules/@maka/runtime-host/dist/execution-candidate-main.js +8 -1
  26. package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +1 -11
  27. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +2 -2
  28. package/node_modules/@maka/runtime-host/dist/protocol/codec.js +11 -0
  29. package/node_modules/@maka/runtime-host/dist/protocol/index.js +1 -1
  30. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +10 -2
  31. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +65 -0
  32. package/node_modules/@maka/runtime-host/dist/server/execution-candidate.js +4 -1
  33. package/node_modules/@maka/runtime-host/dist/server/execution-composition-factory.js +9 -3
  34. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +13 -2
  35. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +3 -15
  36. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +9 -4
  37. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +1 -2
  38. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +4 -1
  39. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +1 -0
  40. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +945 -0
  41. package/node_modules/@maka/storage/dist/agent-run-store.js +3 -923
  42. package/node_modules/@maka/storage/dist/artifact-store.js +63 -7
  43. package/node_modules/@maka/storage/dist/execution-persistence-provider.js +54 -0
  44. package/node_modules/@maka/storage/dist/execution-stores.js +182 -59
  45. package/node_modules/@maka/storage/dist/goal-authority.js +39 -8
  46. package/node_modules/@maka/storage/dist/graph-control-values.js +126 -0
  47. package/node_modules/@maka/storage/dist/interaction-store-contract.js +231 -0
  48. package/node_modules/@maka/storage/dist/interaction-store.js +62 -217
  49. package/node_modules/@maka/storage/dist/local-execution-persistence.js +80 -0
  50. package/node_modules/@maka/storage/dist/message-admission-store.js +5 -3
  51. package/node_modules/@maka/storage/dist/root-authority.js +4 -0
  52. package/node_modules/@maka/{eval/dist/maka-runtime-policy.js → storage/dist/runtime-event-store-contract.js} +1 -24
  53. package/node_modules/@maka/storage/dist/runtime-partial-values.js +114 -0
  54. package/node_modules/@maka/storage/dist/session-store-contract.js +61 -0
  55. package/node_modules/@maka/storage/dist/session-store-values.js +342 -0
  56. package/node_modules/@maka/storage/dist/session-store.js +7 -351
  57. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +4 -185
  58. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +23 -135
  59. package/node_modules/@maka/storage/dist/storage-writer-composition.js +2 -3
  60. package/node_modules/@maka/storage/dist/tool-commit-validation.js +111 -0
  61. package/node_modules/@maka/storage/package.json +1 -0
  62. package/package.json +1 -1
@@ -139,13 +139,11 @@ function assertSourceSize(source, maxBytes) {
139
139
  }
140
140
  }
141
141
  function createCodeModeSource(js, toolNames) {
142
- const bindings = Object.fromEntries(
143
- toolNames.map((toolName, index) => [toolName, `__codeMode.tool${index}`])
144
- );
145
- const bindingSource = Object.entries(bindings).map(([name, reference]) => `${JSON.stringify(name)}:${reference}`).join(",");
146
- return `const __codeModeBindings={${bindingSource}};const tools=new Proxy(Object.create(null),{get(_target,name){const binding=__codeModeBindings[name];return typeof binding==="function"?(input)=>binding(input):(input)=>__codeMode.missing(String(name),input);}});const __codeModeResult=await(async()=>{
147
- ${js}
148
- })();if(__codeModeResult===undefined)return undefined;return JSON.parse(JSON.stringify(__codeModeResult));`;
142
+ // Expose only the active catalog: unknown names must not look callable.
143
+ const bindingSource = toolNames
144
+ .map((name, index) => `[${JSON.stringify(name)}]:(input)=>__codeMode.tool${index}(input)`)
145
+ .join(",");
146
+ return `const tools=Object.freeze({__proto__:null,${bindingSource}});const __codeModeResult=await(async()=>{\n${js}\n})();if(__codeModeResult===undefined)return undefined;return JSON.parse(JSON.stringify(__codeModeResult));`;
149
147
  }
150
148
  function createHostFunctions({
151
149
  codeModeErrors,
@@ -165,14 +163,6 @@ function createHostFunctions({
165
163
  toolName
166
164
  });
167
165
  }
168
- group.missing = async (toolName, toolInput) => await invokeCodeModeTool({
169
- codeModeErrors,
170
- input,
171
- outerToolCallId,
172
- policy,
173
- toolInput,
174
- toolName: String(toolName)
175
- });
176
166
  return { __codeMode: group };
177
167
  }
178
168
  async function invokeCodeModeTool({
@@ -404,7 +394,7 @@ function toPendingInterruptions({
404
394
  interruptId: `${toolCallId}:interrupt`,
405
395
  toolName,
406
396
  toolCallId,
407
- input: interruption.hostFunctionName === "__codeMode.missing" ? interruption.arguments[1] : interruption.arguments[0],
397
+ input: interruption.arguments[0],
408
398
  payload: assertInterruptPayload(interruption.payload)
409
399
  };
410
400
  });
@@ -419,9 +409,6 @@ function interruptionIndex(interruptionId) {
419
409
  return Number(match[1]);
420
410
  }
421
411
  function toolNameForInterruption(interruption, toolNames) {
422
- if (interruption.hostFunctionName === "__codeMode.missing") {
423
- return String(interruption.arguments[0]);
424
- }
425
412
  const match = /^__codeMode\.tool(\d+)$/u.exec(interruption.hostFunctionName);
426
413
  const toolName = match === null ? void 0 : toolNames[Number(match[1])];
427
414
  if (toolName === void 0) {
@@ -17,7 +17,7 @@
17
17
  * under the License.
18
18
  */
19
19
  import { randomUUID } from 'node:crypto';
20
- import { prepareStorageRootControlDirectory, resolveStorageRoot, } from '@maka/storage/root-authority';
20
+ import { prepareStorageRootControlDirectory, resolveStorageRoot, StorageRootAuthorityError, } from '@maka/storage/root-authority';
21
21
  import { readStateRootCompositionBinding } from '@maka/storage/state-root-composition';
22
22
  import { performance } from 'node:perf_hooks';
23
23
  import { requireClientInstanceId, requireHostCompositionId, validateProtocolRange, } from '../protocol/index.js';
@@ -27,7 +27,10 @@ import { isPermanentCandidateStartupFailure, } from '../candidate-startup-failur
27
27
  import { clearCandidateStartupDiagnostic, selectCandidateStartupDiagnostic, } from '../control/startup-diagnostic.js';
28
28
  import { decodeRuntimeHostManagedLaunchClaim, readRuntimeHostManagedDeploymentConfig, runtimeHostManagedLaunchRejection, RuntimeHostManagedDeploymentError, } from '../operator/managed-deployment.js';
29
29
  import { abortable, waitForRuntimeHostReady } from './wait-for-ready.js';
30
- const DEFAULT_ELECTION_DEADLINE_MS = 45_000;
30
+ // Candidate readiness includes the Windows named-pipe ACL helper, whose
31
+ // fail-closed ceiling is 60s. Leave enough room for election and connection
32
+ // bookkeeping after that helper returns.
33
+ const DEFAULT_ELECTION_DEADLINE_MS = 75_000;
31
34
  const DEFAULT_BACKOFF_MIN_MS = 20;
32
35
  const DEFAULT_BACKOFF_MAX_MS = 250;
33
36
  const MIN_CANDIDATE_INTERVAL_MS = 250;
@@ -73,6 +76,12 @@ export async function connectOwnedRuntimeHostWithDependencies(input, dependencie
73
76
  launch ??= dependencies.launchCandidate({
74
77
  ...candidate,
75
78
  idleGraceMs: 0,
79
+ // Proxy passwords belong in the child environment, never process arguments.
80
+ env: {
81
+ MAKA_HOSTED_INITIALIZATION: input.initialization
82
+ ? JSON.stringify(input.initialization)
83
+ : '',
84
+ },
76
85
  });
77
86
  return launch;
78
87
  },
@@ -101,10 +110,19 @@ export async function connectOwnedRuntimeHostWithDependencies(input, dependencie
101
110
  }
102
111
  return { kind: 'connected', connection: ownedConnection, host };
103
112
  }
104
- catch {
113
+ catch (error) {
105
114
  await connection?.close().catch(() => undefined);
106
115
  releaseOwnedLaunch(launch);
107
- return { kind: 'failed', reason: 'host_unresponsive' };
116
+ const code = error instanceof StorageRootAuthorityError ? error.code : 'internal_startup_failure';
117
+ const cause = error instanceof Error ? error.cause : undefined;
118
+ const causeCode = cause instanceof Error && 'code' in cause && typeof cause.code === 'string'
119
+ ? cause.code
120
+ : undefined;
121
+ return {
122
+ kind: 'failed',
123
+ reason: 'startup_failed',
124
+ detail: `${code}${causeCode && /^[A-Z0-9_]{1,64}$/.test(causeCode) ? ` (${causeCode})` : ''}`,
125
+ };
108
126
  }
109
127
  }
110
128
  function releaseOwnedLaunch(launch) {
@@ -155,6 +173,7 @@ export async function connectOrSpawnRuntimeHostWithDependencies(input, dependenc
155
173
  const candidateLaunches = new Set();
156
174
  let sawEndpointConnected = false;
157
175
  let lastRegistration;
176
+ let lastConnectionFailure;
158
177
  let latestCandidate;
159
178
  const observations = {
160
179
  totalResults: 0,
@@ -184,6 +203,9 @@ export async function connectOrSpawnRuntimeHostWithDependencies(input, dependenc
184
203
  electionDeadline: deadline,
185
204
  });
186
205
  const observed = recordElectionResult(result, observations);
206
+ if (result.kind === 'unavailable' && result.connectionFailure) {
207
+ lastConnectionFailure = result.connectionFailure;
208
+ }
187
209
  if (observed.registration)
188
210
  lastRegistration = observed.registration;
189
211
  if (observed.endpointConnected)
@@ -351,6 +373,7 @@ export async function connectOrSpawnRuntimeHostWithDependencies(input, dependenc
351
373
  sawEndpointConnected,
352
374
  observations,
353
375
  lastRegistration,
376
+ lastConnectionFailure,
354
377
  latestCandidate,
355
378
  }),
356
379
  };
@@ -418,6 +441,7 @@ function createElectionDiagnostic(input) {
418
441
  candidateLaunches: input.candidateLaunches,
419
442
  sawEndpointConnected: input.sawEndpointConnected,
420
443
  observations: { ...input.observations },
444
+ ...(input.lastConnectionFailure ? { lastConnectionFailure: input.lastConnectionFailure } : {}),
421
445
  ...(input.lastRegistration
422
446
  ? {
423
447
  lastRegistration: {
@@ -749,6 +749,7 @@ function finalizeConnectRuntimeHostResult(result) {
749
749
  kind: 'unavailable',
750
750
  reason: result.reason,
751
751
  ...(result.registration ? { registration: result.registration } : {}),
752
+ ...(result.connectionFailure ? { connectionFailure: result.connectionFailure } : {}),
752
753
  };
753
754
  }
754
755
  return result;
@@ -778,7 +779,12 @@ export async function connectResolvedRuntimeHost(input) {
778
779
  if (error instanceof RuntimeHostRegistrationError && error.code === 'invalid_registration') {
779
780
  return { kind: 'unavailable', reason: 'invalid_registration', endpointConnected: false };
780
781
  }
781
- return { kind: 'unavailable', reason: 'connect_failed', endpointConnected: false };
782
+ return {
783
+ kind: 'unavailable',
784
+ reason: 'connect_failed',
785
+ endpointConnected: false,
786
+ connectionFailure: connectionFailure('registration', error),
787
+ };
782
788
  }
783
789
  if (!registration) {
784
790
  return { kind: 'unavailable', reason: 'not_registered', endpointConnected: false };
@@ -810,6 +816,7 @@ export async function connectResolvedRuntimeHost(input) {
810
816
  reason: 'connect_failed',
811
817
  endpointConnected: false,
812
818
  registration,
819
+ connectionFailure: { phase: 'connect', code: 'ETIMEDOUT' },
813
820
  };
814
821
  }
815
822
  let transport;
@@ -825,6 +832,7 @@ export async function connectResolvedRuntimeHost(input) {
825
832
  reason: 'connect_failed',
826
833
  endpointConnected: false,
827
834
  registration,
835
+ connectionFailure: connectionFailure('connect', error),
828
836
  };
829
837
  }
830
838
  const handshakeDeadline = phaseDeadline(handshakeTimeoutMs, input.electionDeadline);
@@ -1143,7 +1151,7 @@ function openTransport(path, timeoutMs, exhaustsElection) {
1143
1151
  socket.destroy();
1144
1152
  reject(exhaustsElection
1145
1153
  ? new ElectionDeadlineElapsedError()
1146
- : new Error('Timed out connecting to Runtime Host'));
1154
+ : Object.assign(new Error('Timed out connecting to Runtime Host'), { code: 'ETIMEDOUT' }));
1147
1155
  }, timeoutMs);
1148
1156
  const onConnect = () => {
1149
1157
  const transport = new FramedTransport(socket);
@@ -1164,6 +1172,16 @@ function openTransport(path, timeoutMs, exhaustsElection) {
1164
1172
  socket.once('error', onError);
1165
1173
  });
1166
1174
  }
1175
+ function connectionFailure(phase, error) {
1176
+ const cause = error instanceof RuntimeHostRegistrationError ? error.cause : error;
1177
+ const code = cause instanceof Error && 'code' in cause && typeof cause.code === 'string'
1178
+ ? cause.code
1179
+ : undefined;
1180
+ return {
1181
+ phase,
1182
+ ...(code && /^E[A-Z0-9_]{1,63}$/u.test(code) ? { code } : {}),
1183
+ };
1184
+ }
1167
1185
  function requireTimeout(value, label) {
1168
1186
  if (!Number.isSafeInteger(value) || value < 1 || value > 120_000) {
1169
1187
  throw new RangeError(`${label} must be an integer between 1 and 120000`);
@@ -22,12 +22,37 @@ import { abortable } from './wait-for-ready.js';
22
22
  export async function configureHostedExecutionTarget(connection, input, signal) {
23
23
  const before = await abortable(() => readRuntimeHostConnectionCatalog(connection), signal);
24
24
  const target = before.connections.find((candidate) => candidate.slug === input.connectionSlug);
25
+ const onboarding = input.connection;
26
+ if (onboarding && target && target.providerType !== onboarding.providerType) {
27
+ throw new Error('Runtime Host connection provider does not match');
28
+ }
29
+ if (onboarding) {
30
+ const onboardingTarget = target
31
+ ? { kind: 'existing', connectionId: target.connectionId }
32
+ : {
33
+ kind: 'create',
34
+ providerType: onboarding.providerType,
35
+ slug: input.connectionSlug,
36
+ name: input.connectionSlug,
37
+ };
38
+ const saved = await abortable(() => connection.request('connection.onboarding.save', {
39
+ target: onboardingTarget,
40
+ apiKey: onboarding.apiKey,
41
+ baseUrl: input.baseUrl,
42
+ enabledModelIds: [input.model],
43
+ }), signal);
44
+ if (saved.kind !== 'saved')
45
+ throw new Error('Runtime Host connection onboarding failed');
46
+ return {
47
+ connectionId: saved.connection.connectionId,
48
+ connectionSlug: saved.connection.slug,
49
+ };
50
+ }
25
51
  if (!target)
26
52
  throw new Error('Runtime Host connection is unavailable');
27
53
  const baseUrl = new URL(input.baseUrl).toString();
28
54
  const enabledModelIds = [...new Set([...target.enabledModelIds, input.model])];
29
55
  const endpointChanged = canonicalBaseUrl(effectiveBaseUrl(target)) !== baseUrl;
30
- let changed = false;
31
56
  if (endpointChanged || !target.enabled || !target.enabledModelIds.includes(input.model)) {
32
57
  const updated = await abortable(() => connection.request('connection.catalog.update', {
33
58
  expected: { connectionId: target.connectionId, revision: target.revision },
@@ -41,7 +66,6 @@ export async function configureHostedExecutionTarget(connection, input, signal)
41
66
  if (updated.kind !== 'committed') {
42
67
  throw new Error(`Runtime Host connection update was not committed: ${updated.kind}`);
43
68
  }
44
- changed = true;
45
69
  }
46
70
  // Best-effort: a fetch here is how the target picks up wire metadata for a
47
71
  // model the catalog has not described yet, so it is worth trying. It is not
@@ -50,11 +74,9 @@ export async function configureHostedExecutionTarget(connection, input, signal)
50
74
  // in both cases the user's selection still authorizes the model — the
51
75
  // admission check below is what decides.
52
76
  if (endpointChanged || !target.models.some((model) => model.id === input.model)) {
53
- const fetched = await abortable(() => connection.request('connection.models.fetch', {
77
+ await abortable(() => connection.request('connection.models.fetch', {
54
78
  connectionId: target.connectionId,
55
79
  }), signal);
56
- if (fetched.kind === 'committed')
57
- changed = true;
58
80
  }
59
81
  const after = await abortable(() => readRuntimeHostConnectionCatalog(connection), signal);
60
82
  const configured = after.connections.find((candidate) => candidate.connectionId === target.connectionId);
@@ -64,7 +86,6 @@ export async function configureHostedExecutionTarget(connection, input, signal)
64
86
  throw new Error('Runtime Host did not admit the requested model target');
65
87
  }
66
88
  return {
67
- changed,
68
89
  connectionId: configured.connectionId,
69
90
  connectionSlug: configured.slug,
70
91
  };
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID, preservesHostedExecutionEnvironment, RUNTIME_HOST_PROTOCOL_VERSION, } from '../protocol/index.js';
20
20
  import { connectOwnedRuntimeHost } from './connect-or-spawn.js';
21
- import { configureHostedExecutionTarget } from './hosted-execution-target.js';
21
+ import { configureHostedExecutionTarget, } from './hosted-execution-target.js';
22
22
  const defaultDependencies = { connectOwnedRuntimeHost };
23
23
  export async function runHostedExecution(input) {
24
24
  return runHostedExecutionWithDependencies(input, defaultDependencies);
@@ -27,7 +27,8 @@ export async function runHostedExecutionWithDependencies(input, dependencies) {
27
27
  if (input.signal?.aborted) {
28
28
  return indeterminate(input.execution.executionId, 'Hosted execution was cancelled');
29
29
  }
30
- const initial = await dependencies.connectOwnedRuntimeHost({
30
+ const connected = await dependencies.connectOwnedRuntimeHost({
31
+ ...(input.initialization ? { initialization: input.initialization } : {}),
31
32
  rootPath: input.rootPath,
32
33
  protocol: {
33
34
  min: RUNTIME_HOST_PROTOCOL_VERSION,
@@ -36,14 +37,17 @@ export async function runHostedExecutionWithDependencies(input, dependencies) {
36
37
  compositionId: INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID,
37
38
  ...(input.signal ? { signal: input.signal } : {}),
38
39
  });
39
- if (initial.kind !== 'connected') {
40
+ if (connected.kind !== 'connected') {
40
41
  if (input.signal?.aborted) {
41
42
  return indeterminate(input.execution.executionId, 'Hosted execution was cancelled');
42
43
  }
43
- const cause = initial.kind === 'failed' ? initial.reason : initial.kind;
44
+ const cause = connected.kind === 'failed'
45
+ ? connected.reason === 'startup_failed'
46
+ ? connected.detail
47
+ : connected.reason
48
+ : connected.kind;
44
49
  return indeterminate(input.execution.executionId, `Runtime Host did not start: ${cause}`);
45
50
  }
46
- let connected = initial;
47
51
  let projection;
48
52
  try {
49
53
  input.signal?.throwIfAborted();
@@ -56,6 +60,7 @@ export async function runHostedExecutionWithDependencies(input, dependencies) {
56
60
  connectionSlug: target.connectionSlug,
57
61
  model: target.model,
58
62
  baseUrl: input.baseUrl,
63
+ ...(input.connection ? { connection: input.connection } : {}),
59
64
  }, input.signal);
60
65
  exactTarget = {
61
66
  kind: 'explicit',
@@ -63,29 +68,6 @@ export async function runHostedExecutionWithDependencies(input, dependencies) {
63
68
  connectionSlug: configured.connectionSlug,
64
69
  model: target.model,
65
70
  };
66
- if (configured.changed) {
67
- await connected.connection.close().catch(() => undefined);
68
- if (!(await connected.host.settle(input.hostSettlementTimeoutMs ?? 15_000))) {
69
- return indeterminate(input.execution.executionId, 'Runtime Host did not exit cleanly');
70
- }
71
- const reconnected = await dependencies.connectOwnedRuntimeHost({
72
- rootPath: input.rootPath,
73
- protocol: {
74
- min: RUNTIME_HOST_PROTOCOL_VERSION,
75
- max: RUNTIME_HOST_PROTOCOL_VERSION,
76
- },
77
- compositionId: INTERACTIVE_RUNTIME_HOST_COMPOSITION_ID,
78
- ...(input.signal ? { signal: input.signal } : {}),
79
- });
80
- if (reconnected.kind !== 'connected') {
81
- if (input.signal?.aborted) {
82
- return indeterminate(input.execution.executionId, 'Hosted execution was cancelled');
83
- }
84
- const cause = reconnected.kind === 'failed' ? reconnected.reason : reconnected.kind;
85
- return indeterminate(input.execution.executionId, `Runtime Host did not start: ${cause}`);
86
- }
87
- connected = reconnected;
88
- }
89
71
  }
90
72
  projection = await executeHostedExecution(connected.connection, {
91
73
  ...input.execution,
@@ -54,7 +54,7 @@ export function runtimeHostStartupError(reason, diagnostic) {
54
54
  case 'deployment_needs_repair':
55
55
  return new RuntimeHostStartupError(reason, 'The Runtime Host managed deployment could not safely complete or roll back a lifecycle change. Run deployment repair before connecting. Diagnostic code: DEPLOYMENT_NEEDS_REPAIR.');
56
56
  case 'startup_timeout':
57
- return new Error(`No Runtime Host became ready before the startup deadline elapsed${electionDiagnosticSuffix(diagnostic)}. Retry; if this workspace needs longer to open (large workspaces can after an upgrade), set MAKA_RUNTIME_HOST_ELECTION_DEADLINE_MS to allow more time.`);
57
+ return new Error(`Could not connect to a Runtime Host before the startup deadline elapsed${electionDiagnosticSuffix(diagnostic)}. Retry; the Host may still be starting or its local endpoint may be unavailable. If startup needs longer, set MAKA_RUNTIME_HOST_ELECTION_DEADLINE_MS to allow more time.`);
58
58
  case 'host_unresponsive':
59
59
  return new Error(`A Runtime Host was found but did not become ready before the startup deadline elapsed${electionDiagnosticSuffix(diagnostic)}. It may still be opening this workspace (large workspaces can need longer right after an upgrade); retrying once it settles usually succeeds, or set MAKA_RUNTIME_HOST_ELECTION_DEADLINE_MS to allow more time.`);
60
60
  }
@@ -16,7 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export async function waitForRuntimeHostReady(connection, timeoutMs = 45_000, signal) {
19
+ export async function waitForRuntimeHostReady(connection, timeoutMs = 75_000, signal) {
20
20
  if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 120_000) {
21
21
  throw new RangeError('timeoutMs must be an integer between 1 and 120000');
22
22
  }
@@ -32,12 +32,13 @@ const WINDOWS_PIPE_PATH_ENV = 'MAKA_RUNTIME_HOST_PIPE_PATH';
32
32
  // per-connection check, so the call has to succeed and a timeout has to
33
33
  // refuse the endpoint. That makes the budget a question of how long we are
34
34
  // willing to wait, not how long the work should take. Windows PowerShell 5.1
35
- // cold start plus .NET type loading is seconds on a loaded CI runner, and a
36
- // 10s budget killed a healthy run (#3225); keep the ceiling well clear of a
37
- // slow start so it only fires on a genuinely stuck process. Endpoint readiness
38
- // waits on this, so raising it means checking that the waiters still outlast
39
- // it: scripts/windows-runtime-host-local-ipc-trust.ps1 and client/wait-for-ready.ts.
40
- const WINDOWS_PIPE_ACL_TIMEOUT_MS = 30_000;
35
+ // cold start plus .NET type loading is seconds on a loaded CI runner, and both
36
+ // 10s (#3225) and 30s (npm Nightly run 34917337079) budgets have killed healthy
37
+ // hosted runners. Keep a full minute so ordinary runner variance does not
38
+ // refuse a secure endpoint. Endpoint readiness waits on this, so raising it
39
+ // means checking that the waiters still outlast it:
40
+ // scripts/windows-runtime-host-local-ipc-trust.ps1 and client/connect-or-spawn.ts.
41
+ const WINDOWS_PIPE_ACL_TIMEOUT_MS = 60_000;
41
42
  const WINDOWS_PIPE_ACL_DIAGNOSTIC_LIMIT = 1_000;
42
43
  const WINDOWS_PIPE_ACL_STDERR_MAX_BYTES = 4 * 1024;
43
44
  const WINDOWS_PIPE_ACL_SCRIPT = String.raw `
@@ -18,4 +18,11 @@
18
18
  * under the License.
19
19
  */
20
20
  import { runExecutionCandidateEntry } from './candidate-entry.js';
21
- await runExecutionCandidateEntry(process.argv.slice(2), import.meta.url);
21
+ const initialization = process.env.MAKA_HOSTED_INITIALIZATION;
22
+ delete process.env.MAKA_HOSTED_INITIALIZATION;
23
+ await runExecutionCandidateEntry(process.argv.slice(2), import.meta.url, {
24
+ overrideOptions: (options) => ({
25
+ ...options,
26
+ ...(initialization ? { initialization: JSON.parse(initialization) } : {}),
27
+ }),
28
+ });
@@ -16,7 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { requireCount, requireEncodedByteLimit, requireEntityId, requireExactRecord, requireShapedRecord, requireUtf8String, } from './codec.js';
19
+ import { requireCount, requireEncodedByteLimit, requireEntityId, requireExactRecord, requireOpaqueIdentity, requireShapedRecord, requireUtf8String, } from './codec.js';
20
20
  import { invalidProtocolFrame } from './errors.js';
21
21
  import { defineOperation } from './operation-spec.js';
22
22
  export const AGENT_GRAPH_CLIENT_SCHEMA_VERSION = 1;
@@ -786,16 +786,6 @@ function requireBoolean(value, label) {
786
786
  throw invalidProtocolFrame(`Invalid ${label}`);
787
787
  return value;
788
788
  }
789
- function requireOpaqueIdentity(value, label) {
790
- if (typeof value !== 'string' ||
791
- value.length === 0 ||
792
- value.length > 256 ||
793
- value.trim() !== value ||
794
- /[\u0000-\u001f\u007f]/.test(value)) {
795
- throw invalidProtocolFrame(`Invalid ${label}`);
796
- }
797
- return value;
798
- }
799
789
  function requireFingerprint(value, label) {
800
790
  if (typeof value !== 'string' || !/^sha256:[a-f0-9]{64}$/.test(value)) {
801
791
  throw invalidProtocolFrame(`Invalid ${label}`);
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import { TOOL_ACTIVITY_KINDS } from '@maka/core/events';
20
20
  import { decodeInteractionAnswer, projectInteractionFormRequest, } from '@maka/core/interaction';
21
- import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireRecord, requireString, } from './codec.js';
21
+ import { assertExactKeys, requireCount, requireEntityId, requireExactRecord, requireOpaqueIdentity, requireRecord, requireString, } from './codec.js';
22
22
  import { invalidProtocolFrame } from './errors.js';
23
23
  import { defineHostPathOperation, defineOperation } from './operation-spec.js';
24
24
  export const CLIENT_CAPABILITY_MAX_OFFERS = 32;
@@ -305,7 +305,7 @@ export function decodeClientCapabilityHostFrame(value) {
305
305
  arguments: argumentsValue,
306
306
  sessionId: requireEntityId(frame.sessionId, 'sessionId'),
307
307
  turnId: requireEntityId(frame.turnId, 'turnId'),
308
- toolCallId: requireEntityId(frame.toolCallId, 'toolCallId'),
308
+ toolCallId: requireOpaqueIdentity(frame.toolCallId, 'toolCallId'),
309
309
  ...(frame.cwd === undefined ? {} : { cwd: requireString(frame.cwd, 'cwd', 4_096) }),
310
310
  };
311
311
  }
@@ -61,6 +61,17 @@ export function requireEntityId(value, label) {
61
61
  throw invalidProtocolFrame(`Invalid ${label}`);
62
62
  return id;
63
63
  }
64
+ /** Correlation identities are preserved verbatim, not interpreted as entity paths. */
65
+ export function requireOpaqueIdentity(value, label) {
66
+ if (typeof value !== 'string' ||
67
+ value.length === 0 ||
68
+ value.length > 256 ||
69
+ value.trim() !== value ||
70
+ /[\u0000-\u001f\u007f]/.test(value)) {
71
+ throw invalidProtocolFrame(`Invalid ${label}`);
72
+ }
73
+ return value;
74
+ }
64
75
  export function requireCount(value, label) {
65
76
  if (!Number.isSafeInteger(value) || value < 0) {
66
77
  throw invalidProtocolFrame(`Invalid ${label}`);
@@ -62,7 +62,7 @@ export const RUNTIME_HOST_REGISTRATION_SCHEMA_VERSION = 1;
62
62
  export const RUNTIME_HOST_PROTOCOL_VERSION = 0;
63
63
  // Increment when the same protocol version no longer guarantees safe Client-Host
64
64
  // interoperability. Mismatches are rejected before domain commands are admitted.
65
- export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 154;
65
+ export const RUNTIME_HOST_COMPATIBILITY_EPOCH = 156;
66
66
  // 154: External Session import results distinguish committed Sessions from typed source limits.
67
67
  // 153: Sessions may select plugin executors and Plugin Platform queries expose them.
68
68
  // 152: Assistant completions and transcript rows preserve interrupted responses.
@@ -28,15 +28,20 @@ export function decodeWorkHubCoordinationConfigureModelInput(value) {
28
28
  const input = requireExactRecord(value, 'WorkHub model configuration', [
29
29
  'expectedRevision',
30
30
  'modelTarget',
31
+ 'thinkingLevel',
31
32
  ]);
32
33
  const decoded = decodeSessionConfigurationUpdateInput({
33
34
  sessionId: WORKHUB_COORDINATION_SESSION_ID,
34
35
  expectedRevision: input.expectedRevision,
35
- patch: { modelTarget: input.modelTarget },
36
+ patch: {
37
+ modelTarget: input.modelTarget,
38
+ thinkingLevel: input.thinkingLevel,
39
+ },
36
40
  });
37
41
  return {
38
42
  expectedRevision: decoded.expectedRevision,
39
43
  modelTarget: decoded.patch.modelTarget,
44
+ thinkingLevel: decoded.patch.thinkingLevel ?? null,
40
45
  };
41
46
  }
42
47
  export const WORKHUB_COORDINATION_TEXT_MAX_BYTES = 48 * 1024;
@@ -81,7 +86,10 @@ export const WORKHUB_COORDINATION_OPERATION_SPECS = {
81
86
  assertOutputForInput: (input, output) => SESSION_CATALOG_OPERATION_SPECS['session.configuration.update'].assertOutputForInput?.({
82
87
  sessionId: WORKHUB_COORDINATION_SESSION_ID,
83
88
  expectedRevision: input.expectedRevision,
84
- patch: { modelTarget: input.modelTarget },
89
+ patch: {
90
+ modelTarget: input.modelTarget,
91
+ thinkingLevel: input.thinkingLevel,
92
+ },
85
93
  }, output),
86
94
  }),
87
95
  'workhub.coordination.query': defineOperation({
@@ -29,6 +29,8 @@ const JOURNAL_FILE = '.runtime-host-bootstrap.json';
29
29
  const OPENCODE_FREE_SEED_MODEL_IDS = defaultEnabledModelIdsWhenOmitted('opencode-free') ?? [];
30
30
  /** Establishes a usable first target before Runtime Host accepts clients. */
31
31
  export async function ensureBootstrapRuntimePolicy(input) {
32
+ if (input.initialization)
33
+ await initializeHostedPolicy(input.stores, input.initialization);
32
34
  const journalPath = join(input.workspaceRoot, JOURNAL_FILE);
33
35
  const resuming = await readJournal(journalPath);
34
36
  const initialCatalog = await input.stores.connectionCatalog.getSnapshot();
@@ -82,6 +84,69 @@ export async function ensureBootstrapRuntimePolicy(input) {
82
84
  input.onDeferredError?.(error);
83
85
  }
84
86
  }
87
+ async function initializeHostedPolicy(stores, input) {
88
+ if (input.incognito !== true ||
89
+ (input.proxyUrl !== undefined && typeof input.proxyUrl !== 'string')) {
90
+ throw new Error('Invalid hosted initialization');
91
+ }
92
+ let snapshot = await stores.runtimePolicy.getSnapshot();
93
+ if (!snapshot.policy.privacy.incognitoActive) {
94
+ const result = await stores.runtimePolicy.mutate({
95
+ expectedRevision: snapshot.revision,
96
+ operation: { kind: 'set_privacy', value: { incognitoActive: true } },
97
+ });
98
+ if (result.kind !== 'committed')
99
+ throw new Error('Hosted privacy initialization failed');
100
+ snapshot = result.snapshot;
101
+ }
102
+ if (input.proxyUrl === undefined)
103
+ return;
104
+ let proxy;
105
+ let username;
106
+ let password;
107
+ try {
108
+ proxy = new URL(input.proxyUrl);
109
+ if (proxy.protocol !== 'http:' || !proxy.hostname)
110
+ throw new Error();
111
+ username = decodeURIComponent(proxy.username);
112
+ password = decodeURIComponent(proxy.password);
113
+ }
114
+ catch {
115
+ throw new Error('Invalid hosted HTTP proxy');
116
+ }
117
+ const status = await stores.credentialVault.getStatus({
118
+ scope: 'network_proxy',
119
+ kind: 'password',
120
+ });
121
+ if (status.kind === 'connection_not_found')
122
+ throw new Error('Hosted proxy credential unavailable');
123
+ const authenticated = Boolean(proxy.username || proxy.password);
124
+ const networkProxy = {
125
+ ...snapshot.policy.networkProxy,
126
+ enabled: true,
127
+ protocol: 'http',
128
+ host: proxy.hostname,
129
+ port: Number(proxy.port || 80),
130
+ authEnabled: authenticated,
131
+ username,
132
+ bypassList: [],
133
+ autoBypassDomains: [],
134
+ };
135
+ const result = await stores.operations.updateNetworkProxy({
136
+ expectedPolicyRevision: snapshot.revision,
137
+ expectedCredential: status.status.configured
138
+ ? {
139
+ locator: status.status.locator,
140
+ credentialId: status.status.credentialId,
141
+ revision: status.status.revision,
142
+ }
143
+ : null,
144
+ networkProxy,
145
+ credential: authenticated ? { kind: 'replace', secret: password } : { kind: 'delete' },
146
+ });
147
+ if (result.kind !== 'committed')
148
+ throw new Error('Hosted proxy initialization failed');
149
+ }
85
150
  function bootstrapSeeds(environment) {
86
151
  const seeds = [
87
152
  {
@@ -19,5 +19,8 @@
19
19
  import { startInteractiveRuntimeHostCandidate, } from './candidate.js';
20
20
  import { createExecutionRuntimeHostCompositionSource, } from './execution-composition-factory.js';
21
21
  export async function startExecutionRuntimeHostCandidate(options, dependencies = {}) {
22
- return startInteractiveRuntimeHostCandidate(options, (managedConfig) => createExecutionRuntimeHostCompositionSource(managedConfig ? { projectDirectoryRoots: managedConfig.projectDirectoryRoots } : {}, dependencies), dependencies);
22
+ return startInteractiveRuntimeHostCandidate(options, (managedConfig) => createExecutionRuntimeHostCompositionSource({
23
+ ...(managedConfig ? { projectDirectoryRoots: managedConfig.projectDirectoryRoots } : {}),
24
+ ...(options.initialization ? { initialization: options.initialization } : {}),
25
+ }, dependencies), dependencies);
23
26
  }
@@ -16,14 +16,20 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { createExecutionRuntimeHostComposition, } from './execution-composition.js';
20
19
  import { defineInteractiveRuntimeHostComposition, } from './host-composition.js';
21
20
  export async function createExecutionRuntimeHostCompositionSource(options, dependencies = {}) {
22
21
  const compositionOptions = {
22
+ ...(options.initialization ? { initialization: options.initialization } : {}),
23
23
  ...(options.projectDirectoryRoots
24
24
  ? { projectDirectoryRoots: options.projectDirectoryRoots }
25
25
  : {}),
26
26
  };
27
- const createComposition = dependencies.createComposition ?? createExecutionRuntimeHostComposition;
28
- return defineInteractiveRuntimeHostComposition((context) => createComposition(context, compositionOptions));
27
+ return defineInteractiveRuntimeHostComposition(async (context) => {
28
+ // Load the execution graph only after the candidate owns the root and the
29
+ // kernel has published its listener. Cold imports must not hide recovery
30
+ // from connecting clients or delay candidates that lose the owner lock.
31
+ const createComposition = dependencies.createComposition ??
32
+ (await import('./execution-composition.js')).createExecutionRuntimeHostComposition;
33
+ return createComposition(context, compositionOptions);
34
+ });
29
35
  }