akanjs 3.1.0-rc.23 → 3.1.0-rc.24

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.
package/README.ko.md CHANGED
@@ -35,7 +35,7 @@ Claude Code·Codex·Cursor에 등록된 Akan MCP 서버입니다. 워크스페
35
35
 
36
36
  ### 터미널로 시작하기
37
37
 
38
- [Bun](https://bun.sh) `>=1.4.0`이 필요합니다.
38
+ [Bun](https://bun.sh) `>=1.4.4`이 필요합니다.
39
39
 
40
40
  ```bash
41
41
  bunx create-akan-workspace@latest
package/README.md CHANGED
@@ -34,7 +34,7 @@ Akan MCP server registered for Claude Code, Codex and Cursor. Reopen the agent i
34
34
 
35
35
  ### In a terminal
36
36
 
37
- Requires [Bun](https://bun.sh) `>=1.4.0`.
37
+ Requires [Bun](https://bun.sh) `>=1.4.4`.
38
38
 
39
39
  ```bash
40
40
  bunx create-akan-workspace@latest
@@ -302,7 +302,9 @@ export class WsClient {
302
302
  if (Date.now() - this.#lastInboundAt > websocketHeartbeatContract.silenceMs) {
303
303
  this.logger.warn(`WebSocket is silent, reconnecting`);
304
304
  this.#stopHeartbeat();
305
- ws.close();
305
+
306
+ if ("terminate" in ws) (ws as unknown as Bun.WebSocket).terminate();
307
+ else ws.close();
306
308
  return;
307
309
  }
308
310
  ws.send(JSON.stringify(websocketHeartbeatContract.makeRequest()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.1.0-rc.23",
3
+ "version": "3.1.0-rc.24",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -332,13 +332,13 @@
332
332
  },
333
333
  "devDependencies": {
334
334
  "@biomejs/biome": "2.5.14",
335
- "@types/bun": "^1.4.3"
335
+ "@types/bun": "^1.4.4"
336
336
  },
337
337
  "bun": {
338
338
  "platform": "bun"
339
339
  },
340
340
  "engines": {
341
- "bun": ">=1.4.0"
341
+ "bun": ">=1.4.4"
342
342
  },
343
343
  "main": "./index.ts"
344
344
  }
@@ -1,4 +1,5 @@
1
1
  import fs from "node:fs";
2
+ import os from "node:os";
2
3
 
3
4
  export class MemoryLimit {
4
5
  static readonly #cgroupLimitFiles = ["/sys/fs/cgroup/memory.max", "/sys/fs/cgroup/memory/memory.limit_in_bytes"];
@@ -26,6 +27,9 @@ export class MemoryLimit {
26
27
  }
27
28
 
28
29
  static readCgroupBytes(): number | null {
30
+
31
+ const constrained = process.constrainedMemory() ?? 0;
32
+ if (constrained > 0 && constrained < os.totalmem()) return constrained;
29
33
  for (const filePath of MemoryLimit.#cgroupLimitFiles) {
30
34
  try {
31
35
  if (!fs.existsSync(filePath)) continue;
@@ -191,7 +191,8 @@ export class TunnelAgent {
191
191
 
192
192
  if (Date.now() - this.#lastInboundAt > intervalMs * 3) {
193
193
  this.logger.warn(`Tunnel control socket is silent, reconnecting`);
194
- ws.close();
194
+
195
+ (ws as unknown as Bun.WebSocket).terminate();
195
196
  return;
196
197
  }
197
198
  this.#say({ type: "ping", at: Date.now() });
@@ -6,9 +6,9 @@ export type SqliteWriteTurn = () => Promise<void> | null;
6
6
 
7
7
  export const openTurn: SqliteWriteTurn = () => null;
8
8
 
9
- export const waitForTurn = (sql: string, writeTurn: SqliteWriteTurn) => {
9
+ export const waitForTurn = (statement: Statement, writeTurn: SqliteWriteTurn) => {
10
10
 
11
- const writes = !/^\s*select\b/i.test(sql);
11
+ const writes = !(statement.readonly && statement.reader);
12
12
  return async () => {
13
13
  if (!writes) return;
14
14
  for (let turn = writeTurn(); turn; turn = writeTurn()) await turn;
@@ -19,10 +19,9 @@ export class BunSqliteStatement implements AkanSqlStatement {
19
19
  readonly #turn: () => Promise<void>;
20
20
  constructor(
21
21
  private readonly statement: Statement,
22
- sql: string,
23
22
  writeTurn: SqliteWriteTurn = openTurn,
24
23
  ) {
25
- this.#turn = waitForTurn(sql, writeTurn);
24
+ this.#turn = waitForTurn(statement, writeTurn);
26
25
  }
27
26
  async run(...params: unknown[]) {
28
27
  await this.#turn();
@@ -48,7 +47,7 @@ export class BunSqliteClient implements AkanSqlClient {
48
47
  return await this.prepare(sql).run(...values);
49
48
  }
50
49
  prepare(sql: string): AkanSqlStatement {
51
- return new BunSqliteStatement(this.db.query(sql), sql, this.writeTurn);
50
+ return new BunSqliteStatement(this.db.query(sql), this.writeTurn);
52
51
  }
53
52
  async close() {
54
53
  this.db.close();
@@ -3,11 +3,11 @@ import type { AkanSqlClient, AkanSqlStatement } from "../types.d.ts";
3
3
  /** Resolves once a write from the calling context may run; `null` when it may run now. */
4
4
  export type SqliteWriteTurn = () => Promise<void> | null;
5
5
  export declare const openTurn: SqliteWriteTurn;
6
- export declare const waitForTurn: (sql: string, writeTurn: SqliteWriteTurn) => () => Promise<void>;
6
+ export declare const waitForTurn: (statement: Statement, writeTurn: SqliteWriteTurn) => () => Promise<void>;
7
7
  export declare class BunSqliteStatement implements AkanSqlStatement {
8
8
  #private;
9
9
  private readonly statement;
10
- constructor(statement: Statement, sql: string, writeTurn?: SqliteWriteTurn);
10
+ constructor(statement: Statement, writeTurn?: SqliteWriteTurn);
11
11
  run(...params: unknown[]): Promise<import("bun:sqlite").Changes>;
12
12
  get<Row = Record<string, unknown>>(...params: unknown[]): Promise<Row | null>;
13
13
  all<Row = Record<string, unknown>>(...params: unknown[]): Promise<Row[]>;
@@ -61,8 +61,8 @@ export declare const TOOLCHAIN: {
61
61
  };
62
62
  /** The Bun akan-native is tested with, and the lowest it runs on (package.json engines.bun; a test checks it). */
63
63
  readonly bun: {
64
- readonly version: "1.4.3";
65
- readonly min: "1.4.0";
64
+ readonly version: "1.4.4";
65
+ readonly min: "1.4.4";
66
66
  };
67
67
  readonly xcode: {
68
68
  readonly min: "26.0";
@@ -110,7 +110,7 @@ export function pluginFile(plugin: ResolvedPlugin, relativePath: string, what: s
110
110
  function expandSources(plugin: ResolvedPlugin, patterns: string[]): string[] {
111
111
  const files = new Set<string>();
112
112
  for (const pattern of patterns) {
113
- if (!/[*?[{]/.test(pattern)) {
113
+ if (!/[*?[{]|[!@+]\(/.test(pattern)) {
114
114
  files.add(pluginFile(plugin, pattern, "source"));
115
115
  continue;
116
116
  }
@@ -113,7 +113,7 @@ export const TOOLCHAIN = {
113
113
  /** Must match native/desktop/rust-toolchain.toml (a test checks it). wry 0.57 / tao 0.37 need 1.85+. */
114
114
  rust: { version: "1.98.1" },
115
115
  /** The Bun akan-native is tested with, and the lowest it runs on (package.json engines.bun; a test checks it). */
116
- bun: { version: "1.4.3", min: "1.4.0" },
116
+ bun: { version: "1.4.4", min: "1.4.4" },
117
117
  xcode: { min: "26.0" },
118
118
  iosSdk: { min: "26.0" },
119
119
  } as const;
@@ -8,6 +8,10 @@ import { type DesktopContext, defineDesktopPlugin } from "../../../packages/desk
8
8
  import { checkDb, checkName, checkParams, checkSql, columnValue, sqliteCode } from "./common.ts";
9
9
  import type { SqliteSpec, StatementArgs } from "./index.ts";
10
10
 
11
+ function totalChanges(db: Database): number {
12
+ return (db.query("SELECT total_changes() AS n").get() as { n: number }).n;
13
+ }
14
+
11
15
  function mapError(error: unknown): AkanNativeError {
12
16
  if (error instanceof AkanNativeError) return error;
13
17
  const errno = (error as { errno?: unknown })?.errno;
@@ -51,7 +55,7 @@ export function createDesktopSqlite(dir: (ctx: DesktopContext) => string = (ctx)
51
55
  const withStatement = <T>(
52
56
  args: StatementArgs,
53
57
  ctx: DesktopContext,
54
- use: (statement: Statement, values: ReturnType<typeof checkParams>) => T,
58
+ use: (statement: Statement, values: ReturnType<typeof checkParams>, db: Database) => T,
55
59
  ): T => {
56
60
  const db = database(args?.db, ctx);
57
61
  const sql = checkSql(args.sql);
@@ -66,7 +70,7 @@ export function createDesktopSqlite(dir: (ctx: DesktopContext) => string = (ctx)
66
70
  if (statement.paramsCount !== values.length) {
67
71
  throw new AkanNativeError("INVALID_ARGS", `sql expects ${statement.paramsCount} values, got ${values.length}`);
68
72
  }
69
- return use(statement, values);
73
+ return use(statement, values, db);
70
74
  } catch (error) {
71
75
  throw mapError(error);
72
76
  } finally {
@@ -112,9 +116,10 @@ export function createDesktopSqlite(dir: (ctx: DesktopContext) => string = (ctx)
112
116
  return { db: name };
113
117
  },
114
118
  execute: (args, ctx) =>
115
- withStatement(args, ctx, (statement, values) => {
116
- const { changes, lastInsertRowid } = statement.run(...values);
117
- return { changes, lastInsertId: Number(lastInsertRowid) };
119
+ withStatement(args, ctx, (statement, values, db) => {
120
+ const before = totalChanges(db);
121
+ const { lastInsertRowid } = statement.run(...values);
122
+ return { changes: totalChanges(db) - before, lastInsertId: Number(lastInsertRowid) };
118
123
  }),
119
124
  query: (args, ctx) =>
120
125
  withStatement(args, ctx, (statement, values) => {