maka-agent 0.2.0-dev.42.20260918 → 0.2.0-dev.43.20260919

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 (26) hide show
  1. package/dist/acp/maka-acp-agent.js +17 -6
  2. package/dist/acp/session-event-mapper.js +6 -0
  3. package/dist/acp/session-interactions.js +520 -0
  4. package/dist/acp/session-registry.js +80 -9
  5. package/dist/acp/tool-event-mapper.js +60 -2
  6. package/dist/pi-tui-runner.js +57 -6
  7. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  8. package/node_modules/@maka/core/dist/connection-usage.js +27 -0
  9. package/node_modules/@maka/core/dist/external-session.js +4 -3
  10. package/node_modules/@maka/core/dist/provider-auth.js +9 -1
  11. package/node_modules/@maka/core/dist/skill-locations.js +29 -0
  12. package/node_modules/@maka/core/package.json +2 -0
  13. package/node_modules/@maka/runtime/dist/commandcode-cli-language-model.js +27 -3
  14. package/node_modules/@maka/runtime/dist/connection-usage.js +232 -0
  15. package/node_modules/@maka/runtime/dist/skills-discovery.js +17 -23
  16. package/node_modules/@maka/runtime/package.json +1 -0
  17. package/node_modules/@maka/runtime-host/dist/protocol/connection-effects.js +132 -1
  18. package/node_modules/@maka/runtime-host/dist/protocol/index.js +7 -3
  19. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  20. package/node_modules/@maka/runtime-host/dist/server/connection-effect-coordinator.js +57 -1
  21. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +4 -3
  22. package/node_modules/@maka/storage/dist/codex-session-adapter.js +26 -28
  23. package/node_modules/@maka/storage/dist/runtime-policy/coordinator.js +34 -1
  24. package/node_modules/@maka/storage/dist/runtime-policy-stores.js +2 -0
  25. package/node_modules/@maka/storage/dist/session-store.js +5 -2
  26. package/package.json +1 -1
@@ -16,6 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ import { createHash } from 'node:crypto';
19
20
  import { open, opendir, readdir, realpath, stat } from 'node:fs/promises';
20
21
  import { homedir } from 'node:os';
21
22
  import { basename, join, resolve, sep } from 'node:path';
@@ -29,6 +30,7 @@ const CODEX_ROLLOUT_READ_BYTES = 64 * 1024;
29
30
  const CODEX_ROLLOUT_MAX_RECORD_BYTES = 64 * 1024 * 1024;
30
31
  const CODEX_ROLLOUT_MAX_CONVERTED_BYTES = 256 * 1024 * 1024;
31
32
  const CODEX_ROLLOUT_MAX_MESSAGES = 250_000;
33
+ const CODEX_EPOCH_MS_SQL_FUNCTION = 'maka_codex_epoch_ms';
32
34
  const CODEX_SESSION_ID_PATTERN = /^[A-Za-z0-9_-]{1,128}$/;
33
35
  const CODEX_SUPPORTED_THREAD_SOURCES = ['cli', 'exec', 'vscode', 'atlas', 'chatgpt'];
34
36
  const CODEX_UNSAFE_PATH_CHARS = /[\u0000-\u001F\u007F\u0080-\u009F\u061C\u200B-\u200F\u202A-\u202E\u2060-\u2064\u2066-\u2069\uFEFF]/;
@@ -176,6 +178,7 @@ export class CodexSessionAdapter {
176
178
  try {
177
179
  const sqlite = await import('node:sqlite');
178
180
  db = new sqlite.DatabaseSync(dbPath, { readOnly: true });
181
+ registerCodexEpochNormalization(db);
179
182
  const spec = codexThreadQuery(db, query, undefined, keyset);
180
183
  if (!spec)
181
184
  return undefined;
@@ -707,6 +710,7 @@ async function readCodexThreadRows(dbPath, query, exactId) {
707
710
  const sqlite = await import('node:sqlite');
708
711
  const db = new sqlite.DatabaseSync(dbPath, { readOnly: true });
709
712
  try {
713
+ registerCodexEpochNormalization(db);
710
714
  const spec = codexThreadQuery(db, query, exactId);
711
715
  if (!spec)
712
716
  return undefined;
@@ -753,22 +757,11 @@ function codexThreadQuery(db, query, exactId, keyset) {
753
757
  // No cwd clause. SQLite cannot express the matcher's cross-platform path
754
758
  // equivalence, so the shared matcher remains the only workspace authority.
755
759
  const orderColumns = ['updated_at_ms', 'updated_at', 'created_at_ms', 'created_at'].filter((column) => columns.has(column));
756
- // One authority for the ordering key. It is computed here, selected as
757
- // `sort_key`, and read straight back off the row to build the cursor, so the
758
- // position a cursor names is by construction the position the query ordered
759
- // by. Recomputing it in JS let the two drift on a stored TEXT value: SQL
760
- // keeps the text as the key and orders it above every number, while the JS
761
- // fallback chain skips that column and lands on a different one. A TEXT key
762
- // never satisfies a numeric comparison, so the disagreement did not surface
763
- // as a duplicate — it ended the traversal at that page and dropped every
764
- // Conversation after it without an error. Casting first also keeps the key
765
- // numeric, which is what the cursor's 8-byte encoding requires.
766
- const orderValues = orderColumns.map((column) => {
767
- const numeric = `CAST(${column} AS REAL)`;
768
- return column.endsWith('_ms')
769
- ? numeric
770
- : `(CASE WHEN ${numeric} >= 1000000000000 THEN ${numeric} ELSE ${numeric} * 1000 END)`;
771
- });
760
+ // The same normalizer owns displayed timestamps and this SQL ordering key.
761
+ // Selecting the key with the row then makes the cursor name exactly the
762
+ // position the query used, including ISO text stored in an INTEGER-affinity
763
+ // column.
764
+ const orderValues = orderColumns.map((column) => `${CODEX_EPOCH_MS_SQL_FUNCTION}(${column})`);
772
765
  const orderExpression = orderValues.length > 0 ? `coalesce(${orderValues.join(', ')}, 0)` : '0';
773
766
  if (keyset) {
774
767
  where.push(`(${orderExpression} < ? OR (${orderExpression} = ? AND id < ?))`);
@@ -797,6 +790,9 @@ function finiteNumber(value) {
797
790
  }
798
791
  return undefined;
799
792
  }
793
+ function registerCodexEpochNormalization(db) {
794
+ db.function(CODEX_EPOCH_MS_SQL_FUNCTION, { deterministic: true, directOnly: true }, (value) => normalizeEpochMs(value) ?? null);
795
+ }
800
796
  async function codexStateDbsNewestFirst(codexHome) {
801
797
  try {
802
798
  const root = await realpath(codexHome);
@@ -835,9 +831,10 @@ async function* iterateRolloutFiles(root, archived, relativeRoot = '') {
835
831
  entry.name.startsWith('rollout-') &&
836
832
  entry.name.endsWith('.jsonl')) {
837
833
  try {
834
+ const catalogKey = `${archived ? 'a' : 's'}/${relativePath}`;
838
835
  yield {
839
836
  path,
840
- catalogKey: `${archived ? 'a' : 's'}/${relativePath}`,
837
+ catalogIdentity: createHash('sha256').update(catalogKey).digest('base64url'),
841
838
  mtimeMs: (await stat(path)).mtimeMs,
842
839
  archived,
843
840
  };
@@ -893,23 +890,27 @@ async function nextRolloutCatalogBatch(codexHome, query, keyset, limit, maxCandi
893
890
  return page;
894
891
  }
895
892
  function compareRolloutCandidates(left, right) {
896
- return right.mtimeMs - left.mtimeMs || left.catalogKey.localeCompare(right.catalogKey);
893
+ return right.mtimeMs - left.mtimeMs || left.catalogIdentity.localeCompare(right.catalogIdentity);
897
894
  }
898
895
  function rolloutCandidateIsAfter(candidate, keyset) {
899
896
  return (compareRolloutCandidates(candidate, {
900
897
  mtimeMs: keyset.mtimeMs,
901
- catalogKey: keyset.pathKey,
898
+ catalogIdentity: keyset.pathIdentity,
902
899
  }) > 0);
903
900
  }
904
901
  function candidateKeyset(candidate) {
905
- return { kind: 'filesystem', mtimeMs: candidate.mtimeMs, pathKey: candidate.catalogKey };
902
+ return {
903
+ kind: 'filesystem',
904
+ mtimeMs: candidate.mtimeMs,
905
+ pathIdentity: candidate.catalogIdentity,
906
+ };
906
907
  }
907
908
  function encodeCatalogKeyset(query, keyset) {
908
909
  const queryHash = externalSessionCatalogQueryHash(query);
909
910
  if (keyset.kind === 'database') {
910
911
  return `d:${queryHash}:${Buffer.from(keyset.stateDatabase).toString('base64url')}:${encodeCursorNumber(keyset.sortTimestamp)}:${Buffer.from(keyset.id).toString('base64url')}`;
911
912
  }
912
- return `f:${queryHash}:${encodeCursorNumber(keyset.mtimeMs)}:${Buffer.from(keyset.pathKey).toString('base64url')}`;
913
+ return `f2:${queryHash}:${encodeCursorNumber(keyset.mtimeMs)}:${keyset.pathIdentity}`;
913
914
  }
914
915
  function decodeCatalogKeyset(cursor, query) {
915
916
  if (cursor === undefined)
@@ -935,18 +936,15 @@ function decodeCatalogKeyset(cursor, query) {
935
936
  }
936
937
  return { kind: 'database', stateDatabase, sortTimestamp, id };
937
938
  }
938
- if (parts[0] === 'f') {
939
+ if (parts[0] === 'f2') {
939
940
  if (parts.length !== 4)
940
941
  throw new ExternalSessionCatalogCursorError();
941
942
  const mtimeMs = decodeCursorNumber(parts[2]);
942
- const encodedPathKey = parts[3];
943
- const pathKey = Buffer.from(encodedPathKey, 'base64url').toString('utf8');
944
- if (Buffer.byteLength(pathKey, 'utf8') > 320 ||
945
- Buffer.from(pathKey).toString('base64url') !== encodedPathKey ||
946
- !/^[as]\/[^\u0000-\u001f\u007f]+$/.test(pathKey)) {
943
+ const pathIdentity = parts[3];
944
+ if (!/^[A-Za-z0-9_-]{43}$/.test(pathIdentity)) {
947
945
  throw new ExternalSessionCatalogCursorError();
948
946
  }
949
- return { kind: 'filesystem', mtimeMs, pathKey };
947
+ return { kind: 'filesystem', mtimeMs, pathIdentity };
950
948
  }
951
949
  throw new ExternalSessionCatalogCursorError();
952
950
  }
@@ -1114,6 +1114,29 @@ export class RuntimePolicyCoordinator {
1114
1114
  });
1115
1115
  }));
1116
1116
  }
1117
+ beginConnectionUsage(connectionId) {
1118
+ return this.inLane(async (root) => {
1119
+ const prepared = await this.prepareConnectionOperation(root, connectionId, 'read_usage');
1120
+ if (prepared.kind !== 'ready')
1121
+ return prepared;
1122
+ const ticket = this.issueTicket('connection_usage', connectionUsageSemanticBasis(prepared));
1123
+ return deepFreeze({
1124
+ kind: 'ready',
1125
+ ticket: ticket,
1126
+ connection: structuredClone(prepared.connection),
1127
+ secretMaterial: prepared.secretMaterial,
1128
+ networkProxy: structuredClone(prepared.networkProxy),
1129
+ });
1130
+ });
1131
+ }
1132
+ /**
1133
+ * Read-only counterpart of `completeConnectionTest`: nothing was written, so
1134
+ * there is no catalog state to revalidate — the ticket is simply spent.
1135
+ */
1136
+ async completeConnectionUsage(ticket) {
1137
+ const claimed = this.claimTicket(ticket, 'connection_usage');
1138
+ await this.completeClaimedTicket(claimed, async () => undefined);
1139
+ }
1117
1140
  async prepareConnectionOperation(root, connectionId, action) {
1118
1141
  const catalog = await this.catalog.read(root);
1119
1142
  const connection = findConnection(catalog, { connectionId });
@@ -1574,6 +1597,9 @@ function connectionTestSemanticBasis(prepared) {
1574
1597
  model: connectionTestModelBasis(prepared.connection),
1575
1598
  };
1576
1599
  }
1600
+ function connectionUsageSemanticBasis(prepared) {
1601
+ return { kind: 'connection_usage', ...commonSemanticConnectionBasis(prepared) };
1602
+ }
1577
1603
  function isCanonicalConnectionTestModel(connection, modelId) {
1578
1604
  const basis = connectionTestModelBasis(connection);
1579
1605
  // Either source admits: testing a discovered model before enabling it is the
@@ -1681,7 +1707,14 @@ function assertConnectionIsWritable(connection) {
1681
1707
  }
1682
1708
  }
1683
1709
  function ticketLabel(kind) {
1684
- return kind === 'model_fetch' ? 'model fetch' : 'connection test';
1710
+ switch (kind) {
1711
+ case 'model_fetch':
1712
+ return 'model fetch';
1713
+ case 'connection_test':
1714
+ return 'connection test';
1715
+ case 'connection_usage':
1716
+ return 'connection usage';
1717
+ }
1685
1718
  }
1686
1719
  function networkProxyCredentialLocator() {
1687
1720
  return { scope: 'network_proxy', kind: 'password' };
@@ -127,6 +127,8 @@ function createWriterFacade(coordinator) {
127
127
  completeConnectionOnboarding: (ticket, input) => coordinator.completeConnectionOnboarding(ticket, input),
128
128
  beginConnectionTest: (connectionId, modelId) => coordinator.beginConnectionTest(connectionId, modelId),
129
129
  completeConnectionTest: (ticket, result) => coordinator.completeConnectionTest(ticket, result),
130
+ beginConnectionUsage: (connectionId) => coordinator.beginConnectionUsage(connectionId),
131
+ completeConnectionUsage: (ticket) => coordinator.completeConnectionUsage(ticket),
130
132
  },
131
133
  };
132
134
  freezeFacade(stores);
@@ -68,8 +68,9 @@ class SqliteSessionStore {
68
68
  externalOrigin,
69
69
  transcriptLedgerVersion: 0,
70
70
  };
71
+ const catalogProjection = projectSessionCatalogMessages(canonicalMessages);
71
72
  options.onCommitStarted?.();
72
- const outcome = await this.metadata.importSession(header, canonicalMessages, projectSessionCatalogMessages(canonicalMessages));
73
+ const outcome = await this.metadata.importSession(header, canonicalMessages, catalogProjection);
73
74
  if (outcome !== 'imported') {
74
75
  throw new Error(`Generated Session id already exists: ${header.id}`);
75
76
  }
@@ -285,6 +286,7 @@ class SqliteSessionStore {
285
286
  async list(filter) {
286
287
  await this.ensureReady();
287
288
  return (await this.metadata.list(filter, 'ordinary'))
289
+ .filter((record) => record.header.transcriptLedgerVersion !== 0)
288
290
  .filter((record) => record.header.conversationCopy?.state !== 'preparing')
289
291
  .map((record) => toCatalogSummary(record.header, record.lastMessagePreview));
290
292
  }
@@ -393,7 +395,8 @@ class SqliteSessionStore {
393
395
  if (messages.length === 0)
394
396
  return;
395
397
  await this.ensureReady();
396
- await this.metadata.appendMessages(sessionId, messages, projectSessionCatalogMessages(messages));
398
+ const canonicalMessages = messages.map((message) => decodeCanonicalMessage(JSON.parse(JSON.stringify(message))));
399
+ await this.metadata.appendMessages(sessionId, canonicalMessages, projectSessionCatalogMessages(canonicalMessages));
397
400
  for (const listener of this.transcriptChangeListeners)
398
401
  listener(sessionId);
399
402
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "maka-agent",
3
- "version": "0.2.0-dev.42.20260918",
3
+ "version": "0.2.0-dev.43.20260919",
4
4
  "description": "Apache Maka (Incubating) developer snapshot; not an Apache release.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",