maka-agent 0.2.0-dev.76.20261009 → 0.2.0-dev.78.20261010

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 (78) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +3 -3
  3. package/dist/pi-tui-pickers.js +5 -2
  4. package/dist/pi-tui-runner.js +211 -33
  5. package/dist/runtime-host-session-driver.js +91 -13
  6. package/dist/session-catalog-limits.js +22 -0
  7. package/dist/session-driver.js +10 -0
  8. package/dist/tui-copy-catalog.js +15 -0
  9. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  10. package/node_modules/@maka/core/dist/bot-chat-settings.js +3 -0
  11. package/node_modules/@maka/core/dist/bot-events.js +1 -8
  12. package/node_modules/@maka/core/dist/local-memory.js +38 -1
  13. package/node_modules/@maka/core/dist/scheduled-task.js +14 -15
  14. package/node_modules/@maka/core/dist/session.js +3 -0
  15. package/node_modules/@maka/core/dist/text-sanitize.js +8 -3
  16. package/node_modules/@maka/runtime/dist/agent-graph-supervisor-wake.js +115 -17
  17. package/node_modules/@maka/runtime/dist/agent-run.js +11 -0
  18. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +11 -0
  19. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +13 -5
  20. package/node_modules/@maka/runtime/dist/bots/proxied-fetch.js +29 -1
  21. package/node_modules/@maka/runtime/dist/computer-use-observation-text.js +22 -0
  22. package/node_modules/@maka/runtime/dist/conversation-copy-agent-output.js +227 -0
  23. package/node_modules/@maka/runtime/dist/conversation-copy.js +176 -46
  24. package/node_modules/@maka/runtime/dist/file-stable-write.js +15 -3
  25. package/node_modules/@maka/runtime/dist/filesystem-worker/resource-resolver.js +3 -1
  26. package/node_modules/@maka/runtime/dist/model-adapter.js +20 -1
  27. package/node_modules/@maka/runtime/dist/network/proxy-test.js +28 -1
  28. package/node_modules/@maka/runtime/dist/network/scoped-fetch-transport.js +13 -2
  29. package/node_modules/@maka/runtime/dist/owned-child-process.js +209 -0
  30. package/node_modules/@maka/runtime/dist/owned-process-main.js +183 -0
  31. package/node_modules/@maka/runtime/dist/pipe-process-driver.js +19 -25
  32. package/node_modules/@maka/runtime/dist/runtime-kernel.js +216 -8
  33. package/node_modules/@maka/runtime/dist/sandbox-boundary-tool.js +12 -0
  34. package/node_modules/@maka/runtime/dist/session-manager.js +156 -17
  35. package/node_modules/@maka/runtime/dist/shell-exec.js +18 -20
  36. package/node_modules/@maka/runtime/dist/shell-run-manager.js +2 -1
  37. package/node_modules/@maka/runtime/dist/stream-graph-coordinator.js +279 -8
  38. package/node_modules/@maka/runtime/dist/stream-graph-schedule-reconcile.js +209 -37
  39. package/node_modules/@maka/runtime/dist/tool-availability.js +55 -18
  40. package/node_modules/@maka/runtime/dist/tool-call-snapshot.js +142 -0
  41. package/node_modules/@maka/runtime/dist/tool-runtime.js +27 -84
  42. package/node_modules/@maka/runtime/dist/workers/{filesystem-worker.js → filesystem-worker.mjs} +12 -1
  43. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +30 -6
  44. package/node_modules/@maka/runtime-host/dist/client/index.js +1 -1
  45. package/node_modules/@maka/runtime-host/dist/client/reconnect-lifecycle.js +44 -13
  46. package/node_modules/@maka/runtime-host/dist/client/session-catalog-summary.js +6 -0
  47. package/node_modules/@maka/runtime-host/dist/client/wsl-environment.js +4 -0
  48. package/node_modules/@maka/runtime-host/dist/protocol/index.js +5 -1
  49. package/node_modules/@maka/runtime-host/dist/protocol/message.js +1 -13
  50. package/node_modules/@maka/runtime-host/dist/protocol/session-catalog.js +46 -9
  51. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +1 -13
  52. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +1 -13
  53. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +4 -7
  54. package/node_modules/@maka/runtime-host/dist/server/archive-retention-coordinator.js +81 -105
  55. package/node_modules/@maka/runtime-host/dist/server/candidate.js +47 -40
  56. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +87 -67
  57. package/node_modules/@maka/runtime-host/dist/server/execution-service.js +5 -1
  58. package/node_modules/@maka/runtime-host/dist/server/host-maintenance-guards.js +95 -0
  59. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +18 -8
  60. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +32 -3
  61. package/node_modules/@maka/runtime-host/dist/server/project-catalog-coordinator.js +2 -0
  62. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +109 -8
  63. package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +20 -3
  64. package/node_modules/@maka/runtime-host/dist/server/session-background-activity.js +71 -0
  65. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +8 -4
  66. package/node_modules/@maka/runtime-host/dist/server/session-interaction-activity.js +78 -0
  67. package/node_modules/@maka/runtime-host/dist/server/session-retirement-coordinator.js +56 -0
  68. package/node_modules/@maka/runtime-host/dist/server/session-revision-graph-references.js +16 -2
  69. package/node_modules/@maka/runtime-host/dist/server/skill-catalog-coordinator.js +2 -0
  70. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +19 -24
  71. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +74 -19
  72. package/node_modules/@maka/runtime-host/dist/server/workhub-result-coordinator.js +1 -1
  73. package/node_modules/@maka/runtime-host/dist/server/workhub-result-runtime.js +6 -99
  74. package/node_modules/@maka/runtime-host/dist/server/workhub-target-execution-authority.js +14 -126
  75. package/node_modules/@maka/storage/dist/context-offload-store.js +8 -3
  76. package/node_modules/@maka/storage/dist/git-entry.js +142 -5
  77. package/node_modules/@maka/storage/dist/session-bundle-policy.js +54 -19
  78. package/package.json +2 -2
@@ -20,6 +20,7 @@ import { ARCHIVE_RETENTION_DAY_MS, ARCHIVE_RETENTION_HOLD_MS, archiveRetentionCl
20
20
  import { generalizedErrorMessage } from '@maka/core/redaction';
21
21
  import { sessionRevisionFamilyId } from '@maka/core/session';
22
22
  import { RuntimePolicyStoreError } from '@maka/storage/runtime-policy-stores';
23
+ import { HostClockGuard, SettingTickGate } from './host-maintenance-guards.js';
23
24
  /** Revision families a sweep tick may delete. */
24
25
  export const ARCHIVE_RETENTION_FAMILIES_PER_TICK = 8;
25
26
  const CANDIDATE_PAGE = 64;
@@ -56,18 +57,8 @@ export class HostArchiveRetentionCoordinator {
56
57
  #loading;
57
58
  /** Serializes every read-modify-write of the document. */
58
59
  #writes = Promise.resolve();
59
- /** Setting changes in flight; while one is pending a sweep admits and starts nothing. */
60
- #changing = 0;
61
- /** The sweep step running now, which a setting change waits for. */
62
- #ticking;
63
- /**
64
- * The latest Host time observed, in memory only. After a restart the floor
65
- * is `enabledAt`, the last sweep's time and, on every sweep, the newest time
66
- * Session metadata recorded.
67
- */
68
- #observedAt = 0;
69
- /** Whether `#observedAt` is a time this process saw, rather than the persisted floor. */
70
- #observedThisRun = false;
60
+ #clock = new HostClockGuard();
61
+ #tickGate = new SettingTickGate();
71
62
  #pass;
72
63
  #draining = false;
73
64
  constructor(options) {
@@ -85,17 +76,9 @@ export class HostArchiveRetentionCoordinator {
85
76
  if (this.#draining)
86
77
  return false;
87
78
  // A setting change is waiting for this lane; look again shortly.
88
- if (this.#changing > 0)
79
+ if (this.#tickGate.changePending)
89
80
  return true;
90
- const tick = this.#tick();
91
- this.#ticking = tick;
92
- try {
93
- return await tick;
94
- }
95
- finally {
96
- if (this.#ticking === tick)
97
- this.#ticking = undefined;
98
- }
81
+ return this.#tickGate.runTick(() => this.#tick());
99
82
  }
100
83
  async #tick() {
101
84
  const document = await this.#load();
@@ -109,33 +92,30 @@ export class HostArchiveRetentionCoordinator {
109
92
  enabledAt: document.enabledAt,
110
93
  };
111
94
  const now = this.#now();
112
- const previous = this.#observedAt;
113
- const observedThisRun = this.#observedThisRun;
114
- this.#observedAt = Math.max(previous, now);
115
- this.#observedThisRun = true;
116
95
  const deadline = archiveRetentionDeadline(setting.enabledAt, setting.days);
117
96
  const gap = archiveRetentionGapThreshold(setting.days);
118
97
  // A hold ends when its day is over, before or after the deadline alike.
119
98
  let hold = document.latest?.hold;
120
99
  let heartbeatCleared = false;
121
- if (hold && now >= hold.until) {
100
+ if (this.#clock.shouldClearHold(now, hold?.until)) {
122
101
  heartbeatCleared = this.#heartbeatDue(document, now);
123
102
  await this.#clearHold(heartbeatCleared ? now : undefined);
124
103
  hold = undefined;
125
104
  }
126
- // A forward jump is caught even when it lands short of the deadline. A
127
- // running Host measures from what it saw; a fresh process from the
128
- // persisted floor and the newest metadata time, which says when the Host
129
- // last ran: one MAX query, once per process.
130
- const since = observedThisRun
131
- ? previous
132
- : Math.max(previous, (await this.#catalog.readLatestSessionMetadataTime()) ?? 0);
133
- if (now - since > gap)
134
- return this.#hold(since, now);
105
+ const clock = await this.#clock.decideTick({
106
+ now,
107
+ gapThreshold: gap,
108
+ checkBackwards: now > deadline,
109
+ readLatestSessionMetadataTime: () => this.#catalog.readLatestSessionMetadataTime(),
110
+ });
111
+ if (clock.kind === 'hold')
112
+ return this.#hold(clock.since, now);
135
113
  // A Host can run for weeks without writing session metadata. Persist a
136
114
  // coarse heartbeat so a later restart can tell that idle time was spent
137
115
  // while the Host was running, rather than treating it as a clock jump.
138
- const heartbeat = !heartbeatCleared && now >= previous && this.#heartbeatDue(this.#document ?? document, now);
116
+ const heartbeat = !heartbeatCleared &&
117
+ now >= clock.previous &&
118
+ this.#heartbeatDue(this.#document ?? document, now);
139
119
  // Nothing can be eligible before the policy itself is `days` old, and no
140
120
  // candidate is read before then.
141
121
  if (now <= deadline) {
@@ -143,10 +123,7 @@ export class HostArchiveRetentionCoordinator {
143
123
  await this.#heartbeat(now);
144
124
  return false;
145
125
  }
146
- if (now < previous)
147
- return this.#pause(now, heartbeat);
148
- const newest = await this.#catalog.readLatestSessionMetadataTime();
149
- if (newest !== undefined && now < newest)
126
+ if (clock.kind === 'pause')
150
127
  return this.#pause(now, heartbeat);
151
128
  if (hold)
152
129
  return false;
@@ -172,7 +149,7 @@ export class HostArchiveRetentionCoordinator {
172
149
  let stopped = false;
173
150
  for (const row of page) {
174
151
  // Draining or a pending setting change: stop before the next family.
175
- if (this.#draining || this.#changing > 0) {
152
+ if (this.#draining || this.#tickGate.changePending) {
176
153
  stopped = true;
177
154
  break;
178
155
  }
@@ -218,7 +195,7 @@ export class HostArchiveRetentionCoordinator {
218
195
  * it for this pass. Every setting change moves the revision.
219
196
  */
220
197
  async #guard(plan, setting) {
221
- if (this.#changing > 0 || this.#document?.revision !== setting.revision) {
198
+ if (this.#tickGate.changePending || this.#document?.revision !== setting.revision) {
222
199
  return 'ineligible';
223
200
  }
224
201
  if (plan.remove.some(({ header }) => !header.isArchived || header.isFlagged)) {
@@ -227,7 +204,7 @@ export class HostArchiveRetentionCoordinator {
227
204
  // The archive time through the reader `requireArchivedForMs` judges by.
228
205
  const archivedAt = await Promise.all(plan.remove.map(async ({ header }) => (await this.#catalog.readCatalogRecord(header.id)).summary.archivedAt));
229
206
  const now = this.#now();
230
- if (now < this.#observedAt)
207
+ if (this.#clock.isBehind(now))
231
208
  return 'ineligible';
232
209
  // A family is as young as its most recently archived member.
233
210
  const start = Math.max(...archivedAt.map((time) => archiveRetentionClockStart(time, setting.enabledAt)));
@@ -388,74 +365,73 @@ export class HostArchiveRetentionCoordinator {
388
365
  async #set(input) {
389
366
  if (this.#draining)
390
367
  return draining();
391
- this.#changing += 1;
392
- try {
393
- // A family admitted under the current setting finishes, and is recorded,
394
- // before the setting changes; nothing new is admitted meanwhile.
395
- await this.#ticking?.catch(() => undefined);
396
- return await this.#serialized(async () => {
397
- const current = await this.#load();
398
- if (current.revision !== input.expectedRevision) {
368
+ // A family admitted under the current setting finishes and is recorded
369
+ // before this change proceeds; the gate admits no new tick meanwhile.
370
+ return this.#tickGate.runSettingChange(async () => {
371
+ try {
372
+ return await this.#serialized(async () => {
373
+ const current = await this.#load();
374
+ if (current.revision !== input.expectedRevision) {
375
+ return {
376
+ ok: true,
377
+ result: {
378
+ kind: 'revision_conflict',
379
+ expectedRevision: input.expectedRevision,
380
+ actualRevision: current.revision,
381
+ },
382
+ };
383
+ }
384
+ if (current.enabled === input.enabled && current.days === input.days) {
385
+ return {
386
+ ok: true,
387
+ result: { kind: 'committed', setting: settingOf(current) },
388
+ };
389
+ }
390
+ // Any change restarts the clock: enabling, or new days while enabled.
391
+ // A clock behind a time already recorded never backdates the deadline.
392
+ const newest = input.enabled
393
+ ? await this.#catalog.readLatestSessionMetadataTime()
394
+ : undefined;
395
+ const now = this.#now();
396
+ const enabledAt = Math.max(now, this.#clock.observedAt, newest ?? 0);
397
+ this.#clock.recordSettingTime(now);
398
+ const { enabledAt: _previous, latest, ...rest } = current;
399
+ const lastSweep = latest?.lastSweep && withoutPause(latest.lastSweep);
400
+ const nextLatest = {
401
+ ...(input.enabled ? { observedAt: now } : {}),
402
+ ...(lastSweep ? { lastSweep } : {}),
403
+ ...(latest?.lastDeletion ? { lastDeletion: latest.lastDeletion } : {}),
404
+ };
405
+ const next = {
406
+ ...rest,
407
+ revision: current.revision + 1,
408
+ enabled: input.enabled,
409
+ days: input.days,
410
+ ...(input.enabled ? { enabledAt } : {}),
411
+ ...(Object.keys(nextLatest).length > 0 ? { latest: nextLatest } : {}),
412
+ };
413
+ await this.#write(next);
414
+ this.#pass = undefined;
415
+ return { ok: true, result: { kind: 'committed', setting: settingOf(next) } };
416
+ });
417
+ }
418
+ catch (error) {
419
+ if (error instanceof RuntimePolicyStoreError && error.code === 'commit_outcome_unknown') {
399
420
  return {
400
- ok: true,
401
- result: {
402
- kind: 'revision_conflict',
403
- expectedRevision: input.expectedRevision,
404
- actualRevision: current.revision,
421
+ ok: false,
422
+ error: {
423
+ code: 'commit_outcome_unknown',
424
+ message: 'Retention setting commit outcome is unknown',
405
425
  },
406
426
  };
407
427
  }
408
- if (current.enabled === input.enabled && current.days === input.days) {
409
- return { ok: true, result: { kind: 'committed', setting: settingOf(current) } };
410
- }
411
- // Any change restarts the clock: enabling, or new days while enabled.
412
- // A clock behind a time already recorded never backdates the deadline.
413
- const newest = input.enabled
414
- ? await this.#catalog.readLatestSessionMetadataTime()
415
- : undefined;
416
- const now = this.#now();
417
- const enabledAt = Math.max(now, this.#observedAt, newest ?? 0);
418
- this.#observedAt = Math.max(this.#observedAt, now);
419
- this.#observedThisRun = true;
420
- const { enabledAt: _previous, latest, ...rest } = current;
421
- const lastSweep = latest?.lastSweep && withoutPause(latest.lastSweep);
422
- const nextLatest = {
423
- ...(input.enabled ? { observedAt: now } : {}),
424
- ...(lastSweep ? { lastSweep } : {}),
425
- ...(latest?.lastDeletion ? { lastDeletion: latest.lastDeletion } : {}),
426
- };
427
- const next = {
428
- ...rest,
429
- revision: current.revision + 1,
430
- enabled: input.enabled,
431
- days: input.days,
432
- ...(input.enabled ? { enabledAt } : {}),
433
- ...(Object.keys(nextLatest).length > 0 ? { latest: nextLatest } : {}),
434
- };
435
- await this.#write(next);
436
- this.#pass = undefined;
437
- return { ok: true, result: { kind: 'committed', setting: settingOf(next) } };
438
- });
439
- }
440
- catch (error) {
441
- if (error instanceof RuntimePolicyStoreError && error.code === 'commit_outcome_unknown') {
428
+ reportFailure('save', error);
442
429
  return {
443
430
  ok: false,
444
- error: {
445
- code: 'commit_outcome_unknown',
446
- message: 'Retention setting commit outcome is unknown',
447
- },
431
+ error: { code: 'persistence_failed', message: 'Retention setting could not be saved' },
448
432
  };
449
433
  }
450
- reportFailure('save', error);
451
- return {
452
- ok: false,
453
- error: { code: 'persistence_failed', message: 'Retention setting could not be saved' },
454
- };
455
- }
456
- finally {
457
- this.#changing -= 1;
458
- }
434
+ });
459
435
  }
460
436
  #update(change) {
461
437
  return this.#serialized(async () => this.#write(change(await this.#load())));
@@ -498,7 +474,7 @@ export class HostArchiveRetentionCoordinator {
498
474
  }
499
475
  document = DISABLED;
500
476
  }
501
- this.#observedAt = Math.max(this.#observedAt, document.enabledAt ?? 0, document.latest?.observedAt ?? 0, document.latest?.lastSweep?.at ?? 0, document.latest?.hold?.detectedAt ?? 0);
477
+ this.#clock.seed(document.enabledAt ?? 0, document.latest?.observedAt ?? 0, document.latest?.lastSweep?.at ?? 0, document.latest?.hold?.detectedAt ?? 0);
502
478
  this.#document = document;
503
479
  return document;
504
480
  }
@@ -33,44 +33,51 @@ export async function startInteractiveRuntimeHostCandidate(options, createCompos
33
33
  if (!ownership)
34
34
  return { kind: 'loser' };
35
35
  const { owner, managedConfig } = ownership;
36
- try {
37
- const composition = await createComposition(managedConfig);
38
- const loadedKernel = await kernelModule;
39
- if (loadedKernel.kind === 'failed')
40
- throw loadedKernel.error;
41
- const { RuntimeHostKernel } = loadedKernel.module;
42
- const websocket = managedConfig?.listeners.websocket;
43
- const accessAuthority = websocket
44
- ? await import('./access-authority.js').then(({ openRuntimeHostAccessAuthority }) => openRuntimeHostAccessAuthority(owner.controlDirectory))
45
- : undefined;
46
- const host = await RuntimeHostKernel.start({
47
- owner,
48
- lifecycleMode: 'ephemeral',
49
- initialConnectionTimeoutMs: options.initialConnectionTimeoutMs,
50
- idleGraceMs: options.idleGraceMs,
51
- handshakeTimeoutMs: options.handshakeTimeoutMs,
52
- generation: options.generation,
53
- composition,
54
- ...(options.initialClientAdmission
55
- ? { initialClientAdmission: options.initialClientAdmission }
56
- : {}),
57
- ...(accessAuthority ? { accessAuthority } : {}),
58
- ...(websocket && accessAuthority
59
- ? {
60
- listenerSetFactory: async (input) => {
61
- const { startRuntimeHostAuthenticatedListenerSet } = await import('./listener-set.js');
62
- return startRuntimeHostAuthenticatedListenerSet(input, {
63
- websocket: { ...websocket, accessAuthority },
64
- });
65
- },
66
- }
67
- : {}),
68
- });
69
- return { kind: 'winner', host };
70
- }
71
- catch (error) {
72
- if (!owner.closed)
73
- await owner.close();
74
- throw error;
75
- }
36
+ const prepared = await (async () => {
37
+ try {
38
+ const composition = await createComposition(managedConfig);
39
+ const loadedKernel = await kernelModule;
40
+ if (loadedKernel.kind === 'failed')
41
+ throw loadedKernel.error;
42
+ const websocket = managedConfig?.listeners.websocket;
43
+ // Keep this the last fallible step: once opened, the authority passes
44
+ // straight to Kernel.start, which owns its cleanup.
45
+ const accessAuthority = websocket
46
+ ? await import('./access-authority.js').then(({ openRuntimeHostAccessAuthority }) => openRuntimeHostAccessAuthority(owner.controlDirectory))
47
+ : undefined;
48
+ const kernelOptions = {
49
+ owner,
50
+ lifecycleMode: 'ephemeral',
51
+ initialConnectionTimeoutMs: options.initialConnectionTimeoutMs,
52
+ idleGraceMs: options.idleGraceMs,
53
+ handshakeTimeoutMs: options.handshakeTimeoutMs,
54
+ generation: options.generation,
55
+ composition,
56
+ ...(options.initialClientAdmission
57
+ ? { initialClientAdmission: options.initialClientAdmission }
58
+ : {}),
59
+ ...(accessAuthority ? { accessAuthority } : {}),
60
+ ...(websocket && accessAuthority
61
+ ? {
62
+ listenerSetFactory: async (input) => {
63
+ const { startRuntimeHostAuthenticatedListenerSet } = await import('./listener-set.js');
64
+ return startRuntimeHostAuthenticatedListenerSet(input, {
65
+ websocket: { ...websocket, accessAuthority },
66
+ });
67
+ },
68
+ }
69
+ : {}),
70
+ };
71
+ return { Kernel: loadedKernel.module.RuntimeHostKernel, options: kernelOptions };
72
+ }
73
+ catch (error) {
74
+ if (!owner.closed)
75
+ await owner.close();
76
+ throw error;
77
+ }
78
+ })();
79
+ // Kernel owns cleanup from here, including retaining the owner until process
80
+ // termination when startup cleanup exceeds its deadline.
81
+ const host = await prepared.Kernel.start(prepared.options);
82
+ return { kind: 'winner', host };
76
83
  }