@sna-sdk/core 0.9.4 → 0.9.5

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.
@@ -13,19 +13,16 @@ process.stdin.on("end", async () => {
13
13
  let apiUrl;
14
14
  if (process.env.SNA_API_URL) {
15
15
  apiUrl = process.env.SNA_API_URL;
16
+ } else if (process.env.SNA_PORT) {
17
+ apiUrl = `http://localhost:${process.env.SNA_PORT}`;
16
18
  } else {
17
19
  const portFile = path.join(process.cwd(), ".sna/sna-api.port");
18
20
  try {
19
21
  const port = fs.readFileSync(portFile, "utf8").trim();
20
22
  apiUrl = `http://localhost:${port}`;
21
23
  } catch {
22
- const snaPort = process.env.SNA_PORT;
23
- if (snaPort) {
24
- apiUrl = `http://localhost:${snaPort}`;
25
- } else {
26
- allow();
27
- return;
28
- }
24
+ allow();
25
+ return;
29
26
  }
30
27
  }
31
28
  const sessionId = process.argv.find((a) => a.startsWith("--session="))?.slice(10) ?? process.env.SNA_SESSION_ID ?? "default";
@@ -59,6 +56,12 @@ function allow() {
59
56
  process.exit(0);
60
57
  }
61
58
  function deny(reason) {
62
- process.stderr.write(reason);
63
- process.exit(2);
59
+ console.log(JSON.stringify({
60
+ hookSpecificOutput: {
61
+ hookEventName: "PreToolUse",
62
+ permissionDecision: "deny",
63
+ permissionDecisionReason: reason
64
+ }
65
+ }));
66
+ process.exit(0);
64
67
  }
@@ -477,11 +477,24 @@ class SessionManager {
477
477
  }
478
478
  /** Kill all sessions. Used during shutdown. */
479
479
  killAll() {
480
+ const pids = [];
480
481
  for (const session of this.sessions.values()) {
481
482
  if (session.process?.alive) {
483
+ const pid = session.process.pid;
482
484
  session.process.kill();
485
+ if (pid) pids.push(pid);
483
486
  }
484
487
  }
488
+ if (pids.length > 0) {
489
+ setTimeout(() => {
490
+ for (const pid of pids) {
491
+ try {
492
+ process.kill(pid, "SIGKILL");
493
+ } catch {
494
+ }
495
+ }
496
+ }, 1e3);
497
+ }
485
498
  }
486
499
  get size() {
487
500
  return this.sessions.size;
@@ -2000,11 +2000,24 @@ var SessionManager = class {
2000
2000
  }
2001
2001
  /** Kill all sessions. Used during shutdown. */
2002
2002
  killAll() {
2003
+ const pids = [];
2003
2004
  for (const session of this.sessions.values()) {
2004
2005
  if (session.process?.alive) {
2006
+ const pid = session.process.pid;
2005
2007
  session.process.kill();
2008
+ if (pid) pids.push(pid);
2006
2009
  }
2007
2010
  }
2011
+ if (pids.length > 0) {
2012
+ setTimeout(() => {
2013
+ for (const pid of pids) {
2014
+ try {
2015
+ process.kill(pid, "SIGKILL");
2016
+ } catch {
2017
+ }
2018
+ }
2019
+ }, 1e3);
2020
+ }
2008
2021
  }
2009
2022
  get size() {
2010
2023
  return this.sessions.size;
@@ -2714,7 +2727,7 @@ try {
2714
2727
  }
2715
2728
  var { port, defaultPermissionMode: permissionMode, model: defaultModel, maxSessions } = getConfig();
2716
2729
  var root = new Hono4();
2717
- root.use("*", cors({ origin: "*", allowMethods: ["GET", "POST", "DELETE", "OPTIONS"] }));
2730
+ root.use("*", cors({ origin: "*", allowMethods: ["GET", "POST", "PATCH", "DELETE", "OPTIONS"] }));
2718
2731
  root.onError((err2, c) => {
2719
2732
  logger.err("err", `${c.req.method} ${new URL(c.req.url).pathname} \u2192 ${err2.message}`);
2720
2733
  return c.json({ status: "error", message: err2.message, stack: err2.stack }, 500);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sna-sdk/core",
3
- "version": "0.9.4",
3
+ "version": "0.9.5",
4
4
  "description": "Skills-Native Application runtime — server, providers, session management, database, and CLI",
5
5
  "type": "module",
6
6
  "bin": {