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
@@ -16,23 +16,160 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { lstat } from 'node:fs/promises';
20
- import { join, parse } from 'node:path';
19
+ import { constants as fsConstants } from 'node:fs';
20
+ import { access, lstat, open } from 'node:fs/promises';
21
+ import { join, parse, resolve } from 'node:path';
22
+ import { execGitText } from './git-exec.js';
23
+ /**
24
+ * True means Git recognized an entry, not that every repository operation will
25
+ * succeed. False requires exhausting the ancestors; ambiguous failures throw.
26
+ */
21
27
  export async function hasEnclosingGitEntry(path) {
22
- let current = path;
28
+ // The git probes below anchor on entry directories, so the walk needs an
29
+ // absolute path: a relative parent would ask Git to resolve -C against the
30
+ // child's inherited cwd, which may be deleted or unsearchable.
31
+ let current = resolve(path);
23
32
  while (true) {
33
+ const gitPath = join(current, '.git');
34
+ let entryStat;
24
35
  try {
25
- await lstat(join(current, '.git'));
26
- return true;
36
+ entryStat = await lstat(gitPath);
27
37
  }
28
38
  catch (error) {
29
39
  const code = error.code;
30
40
  if (code !== 'ENOENT' && code !== 'ENOTDIR')
31
41
  throw error;
32
42
  }
43
+ if (entryStat && (await isGitEntry(gitPath, entryStat, current !== path))) {
44
+ return true;
45
+ }
46
+ // Git skips invalid ancestor directories, but gitfiles can stop discovery.
33
47
  const parent = parse(current).dir;
34
48
  if (parent === current)
35
49
  return false;
36
50
  current = parent;
37
51
  }
38
52
  }
53
+ async function isGitEntry(gitPath, before, ancestor) {
54
+ try {
55
+ // Validate the exact entry: discovery could hide a broken own marker by
56
+ // finding an outer repository instead.
57
+ await assertGitEntry(gitPath);
58
+ return true;
59
+ }
60
+ catch (error) {
61
+ if (!ancestor || !before.isDirectory() || error.code !== 128) {
62
+ throw error;
63
+ }
64
+ }
65
+ // Preserve Git's format verdict, but only after auditing its recognition
66
+ // inputs. Repeat the probe inside the snapshot checks rather than applying
67
+ // a stale rejection to metadata that may have been repaired or replaced.
68
+ const snapshot = await assertGitDirectoryReadable(gitPath, before);
69
+ let recognized = true;
70
+ try {
71
+ await assertGitEntry(gitPath);
72
+ }
73
+ catch (error) {
74
+ if (error.code !== 128)
75
+ throw error;
76
+ recognized = false;
77
+ }
78
+ for (const [path, stat] of snapshot) {
79
+ assertUnchanged(path, stat, await statIfPresent(path));
80
+ }
81
+ return recognized;
82
+ }
83
+ async function assertGitEntry(gitPath) {
84
+ // Let Git interpret directories and gitfiles, including linked worktrees. -C
85
+ // only chooses where Git starts; --resolve-git-dir judges gitPath itself.
86
+ // Anchor on the directory containing the entry (lstat proved it exists)
87
+ // instead of the host's ambient cwd, which may have been deleted or made
88
+ // unsearchable since the process started.
89
+ await execGitText(parse(gitPath).dir, ['rev-parse', '--resolve-git-dir', gitPath], {
90
+ maxBuffer: 64 * 1024,
91
+ timeoutMs: 3_000,
92
+ });
93
+ }
94
+ /**
95
+ * Audit the ordinary directory layout recognized by Git's is_git_directory:
96
+ * HEAD is read (at most 255 bytes), and objects/refs require search permission.
97
+ * Missing members and wrong ordinary-file/directory types are format failures;
98
+ * permission, read and unexpected filesystem errors must still surface.
99
+ * Failed probes involving indirection remain unclassified: success for valid
100
+ * worktrees/symlinks is handled by Git above, not by this fallback.
101
+ */
102
+ async function assertGitDirectoryReadable(gitPath, before) {
103
+ await access(gitPath, fsConstants.R_OK | fsConstants.X_OK);
104
+ const snapshot = new Map([[gitPath, before]]);
105
+ const commonPath = join(gitPath, 'commondir');
106
+ const commonStat = await statIfPresent(commonPath);
107
+ if (commonStat || process.env.GIT_OBJECT_DIRECTORY !== undefined) {
108
+ throw new Error(`Cannot classify Git metadata with redirected storage: ${gitPath}`);
109
+ }
110
+ snapshot.set(commonPath, commonStat);
111
+ for (const name of ['HEAD', 'objects', 'refs']) {
112
+ const path = join(gitPath, name);
113
+ const stat = await statIfPresent(path);
114
+ snapshot.set(path, stat);
115
+ if (!stat)
116
+ continue;
117
+ if (stat.isDirectory()) {
118
+ await access(path, fsConstants.R_OK | fsConstants.X_OK);
119
+ }
120
+ else if (stat.isFile()) {
121
+ await access(path, fsConstants.R_OK);
122
+ if (name === 'HEAD')
123
+ await assertHeadReadable(path, stat);
124
+ }
125
+ else {
126
+ throw new Error(`Cannot classify Git metadata with special file: ${path}`);
127
+ }
128
+ }
129
+ return snapshot;
130
+ }
131
+ async function assertHeadReadable(path, before) {
132
+ // Do not follow a replacement symlink or block opening a replacement FIFO.
133
+ const file = await open(path, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
134
+ try {
135
+ assertUnchanged(path, before, await file.stat());
136
+ const buffer = Buffer.alloc(255);
137
+ let offset = 0;
138
+ while (offset < buffer.length) {
139
+ const { bytesRead } = await file.read(buffer, offset, buffer.length - offset, offset);
140
+ if (bytesRead === 0)
141
+ break;
142
+ offset += bytesRead;
143
+ }
144
+ assertUnchanged(path, before, await file.stat());
145
+ }
146
+ finally {
147
+ await file.close();
148
+ }
149
+ }
150
+ async function statIfPresent(path) {
151
+ try {
152
+ // lstat distinguishes a dangling symlink from a missing member. ENOTDIR
153
+ // here means a parent changed, not that the member was simply absent.
154
+ return await lstat(path);
155
+ }
156
+ catch (error) {
157
+ if (error.code !== 'ENOENT')
158
+ throw error;
159
+ return undefined;
160
+ }
161
+ }
162
+ function assertUnchanged(path, before, after) {
163
+ if (!before && !after)
164
+ return;
165
+ if (!before ||
166
+ !after ||
167
+ before.dev !== after.dev ||
168
+ before.ino !== after.ino ||
169
+ before.mode !== after.mode ||
170
+ before.size !== after.size ||
171
+ before.mtimeMs !== after.mtimeMs ||
172
+ before.ctimeMs !== after.ctimeMs) {
173
+ throw new Error(`Git metadata changed during discovery: ${path}`);
174
+ }
175
+ }
@@ -490,6 +490,15 @@ const SESSION_LINK_COLUMNS = [
490
490
  * derivation changes.
491
491
  */
492
492
  const TRIGGER_MAINTAINED_TABLES = new Set(['session_catalog_projection']);
493
+ // These are database-local ordering keys, not portable identities or references.
494
+ // Keep this semantic policy explicit: other sequence columns belong to Sessions,
495
+ // invocations or streams and must retain their values. A schema-derived test in
496
+ // session-bundle-policy.test.ts fails when a copied table keyed by a single
497
+ // INTEGER column is neither listed here nor allow-listed there.
498
+ const LOCAL_SEQUENCE_COLUMNS = new Map([
499
+ ['tool_journal_events', 'journal_seq'],
500
+ ['message_admissions', 'sequence'],
501
+ ]);
493
502
  const PORTABLE_GLOBAL_TABLES = new Set([
494
503
  'operational_schema_migrations',
495
504
  'session_metadata_schema',
@@ -974,29 +983,55 @@ function mergeBundleDatabase(lease, bundleDatabasePath) {
974
983
  target.exec('DETACH DATABASE bundle');
975
984
  }
976
985
  }
986
+ /**
987
+ * The tables an import copies from the database attached as `bundle`, in the
988
+ * order it copies them.
989
+ *
990
+ * The merge writes exactly these, and a schema-derived test reads the same
991
+ * list, so the two cannot disagree about which tables are copied.
992
+ */
993
+ export function listSessionBundleMergeTables(target) {
994
+ const tables = target
995
+ .prepare("SELECT name FROM bundle.sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name")
996
+ .all();
997
+ const merged = [];
998
+ for (const row of tables) {
999
+ const name = row.name;
1000
+ if (typeof name !== 'string' ||
1001
+ PORTABLE_GLOBAL_TABLES.has(name) ||
1002
+ TRIGGER_MAINTAINED_TABLES.has(name)) {
1003
+ continue;
1004
+ }
1005
+ // Mirror the export's own classification instead of trusting that it
1006
+ // ran: a table with no Session column and no referential rule describes
1007
+ // the WORKSPACE, and the target has its own. The export empties those,
1008
+ // so in practice this inserts nothing -- but an import that depends on
1009
+ // the other side having tidied up is one bundle away from writing a
1010
+ // workspace singleton into somebody else's workspace.
1011
+ if (!describesASession(target, name))
1012
+ continue;
1013
+ const localSequenceColumn = LOCAL_SEQUENCE_COLUMNS.get(name);
1014
+ merged.push(localSequenceColumn === undefined ? { name } : { name, localSequenceColumn });
1015
+ }
1016
+ return merged;
1017
+ }
977
1018
  function mergeAttachedBundle(target) {
978
1019
  {
979
1020
  {
980
- const tables = target
981
- .prepare("SELECT name FROM bundle.sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name")
982
- .all();
983
- for (const row of tables) {
984
- const name = row.name;
985
- if (typeof name !== 'string' ||
986
- PORTABLE_GLOBAL_TABLES.has(name) ||
987
- TRIGGER_MAINTAINED_TABLES.has(name)) {
988
- continue;
1021
+ for (const table of listSessionBundleMergeTables(target)) {
1022
+ const quoted = quoteIdentifier(table.name);
1023
+ const localSequence = table.localSequenceColumn;
1024
+ if (localSequence) {
1025
+ const columns = target.prepare(`PRAGMA bundle.table_info(${quoted})`).all()
1026
+ .filter((column) => column.name !== localSequence)
1027
+ .map((column) => quoteIdentifier(column.name))
1028
+ .join(', ');
1029
+ // Let SQLite allocate target-local values while retaining source order.
1030
+ target.exec(`INSERT INTO main.${quoted} (${columns}) SELECT ${columns} FROM bundle.${quoted} ORDER BY ${quoteIdentifier(localSequence)}`);
1031
+ }
1032
+ else {
1033
+ target.exec(`INSERT INTO main.${quoted} SELECT * FROM bundle.${quoted}`);
989
1034
  }
990
- // Mirror the export's own classification instead of trusting that it
991
- // ran: a table with no Session column and no referential rule describes
992
- // the WORKSPACE, and the target has its own. The export empties those,
993
- // so in practice this inserts nothing -- but an import that depends on
994
- // the other side having tidied up is one bundle away from writing a
995
- // workspace singleton into somebody else's workspace.
996
- if (!describesASession(target, name))
997
- continue;
998
- const quoted = quoteIdentifier(name);
999
- target.exec(`INSERT INTO main.${quoted} SELECT * FROM bundle.${quoted}`);
1000
1035
  }
1001
1036
  // An archived Session arrives with the archive time (or no time) of the
1002
1037
  // machine it left. Archive retention counts from that time, so an import
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maka-agent",
3
- "version": "0.2.0-dev.76.20261009",
3
+ "version": "0.2.0-dev.78.20261010",
4
4
  "description": "Apache Maka (Incubating) developer snapshot; not an Apache release.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -12,7 +12,7 @@
12
12
  "managedRuntimeHostUpdateCompatibility": 1
13
13
  },
14
14
  "engines": {
15
- "node": ">=22.19.0"
15
+ "node": "^22.19.0 || >=24.0.0"
16
16
  },
17
17
  "repository": {
18
18
  "type": "git",