@sna-sdk/core 0.9.5 → 0.9.9

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/dist/cli.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { fileURLToPath } from "url";
4
- import chalk from "chalk";
5
4
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
5
  const PACKAGE_ROOT = path.resolve(__dirname, "..");
7
6
  const [, , command] = process.argv;
@@ -14,9 +13,9 @@ switch (command) {
14
13
  break;
15
14
  default:
16
15
  console.log(`
17
- ${chalk.bold("sna")} \u2014 Skills-Native Application core primitives
16
+ sna \u2014 Skills-Native Application core primitives
18
17
 
19
- ${chalk.bold("Usage:")}
18
+ Usage:
20
19
  sna link Create/update .claude/skills symlinks
21
20
  sna install Add sna to package.json and link skills
22
21
  `);
@@ -27,11 +26,11 @@ function cmdLink() {
27
26
  const skillsDir = path.join(claudeDir, "skills");
28
27
  if (!fs.existsSync(skillsDir)) {
29
28
  fs.mkdirSync(skillsDir, { recursive: true });
30
- console.log(chalk.gray(` created .claude/skills/`));
29
+ console.log(` created .claude/skills/`);
31
30
  }
32
31
  const coreSkillsDir = path.join(PACKAGE_ROOT, "skills");
33
32
  if (!fs.existsSync(coreSkillsDir)) {
34
- console.error(chalk.red(` \u2717 sna skills directory not found: ${coreSkillsDir}`));
33
+ console.error(` \u2717 sna skills directory not found: ${coreSkillsDir}`);
35
34
  process.exit(1);
36
35
  }
37
36
  const skills = fs.readdirSync(coreSkillsDir).filter(
@@ -57,33 +56,33 @@ function cmdLink() {
57
56
  }
58
57
  fs.unlinkSync(linkPath);
59
58
  fs.symlinkSync(target, linkPath);
60
- console.log(chalk.cyan(` updated .claude/skills/${skill}/ \u2192 ${target}`));
59
+ console.log(` updated .claude/skills/${skill}/ \u2192 ${target}`);
61
60
  updated++;
62
61
  } else {
63
- console.log(chalk.yellow(` skipped .claude/skills/${skill}/ (not a symlink \u2014 won't overwrite)`));
62
+ console.log(` skipped .claude/skills/${skill}/ (not a symlink \u2014 won't overwrite)`);
64
63
  skipped++;
65
64
  }
66
65
  } else {
67
66
  fs.symlinkSync(target, linkPath);
68
- console.log(chalk.green(` linked .claude/skills/${skill}/ \u2192 ${target}`));
67
+ console.log(` linked .claude/skills/${skill}/ \u2192 ${target}`);
69
68
  linked++;
70
69
  }
71
70
  }
72
71
  console.log();
73
72
  if (linked + updated > 0) {
74
- console.log(chalk.green(`\u2713 ${linked + updated} skill(s) linked`));
73
+ console.log(`\u2713 ${linked + updated} skill(s) linked`);
75
74
  } else {
76
- console.log(chalk.gray(`\u2713 Skills already up to date`));
75
+ console.log(`\u2713 Skills already up to date`);
77
76
  }
78
77
  if (skipped > 0 && linked + updated > 0) {
79
- console.log(chalk.gray(` (${skipped} unchanged)`));
78
+ console.log(` (${skipped} unchanged)`);
80
79
  }
81
80
  }
82
81
  function cmdInstall() {
83
82
  const cwd = process.cwd();
84
83
  const pkgPath = path.join(cwd, "package.json");
85
84
  if (!fs.existsSync(pkgPath)) {
86
- console.error(chalk.red(" \u2717 No package.json found in current directory"));
85
+ console.error(` \u2717 No package.json found in current directory`);
87
86
  process.exit(1);
88
87
  }
89
88
  const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
@@ -94,10 +93,10 @@ function cmdInstall() {
94
93
  pkg.dependencies = pkg.dependencies ?? {};
95
94
  pkg.dependencies["sna"] = `^${version}`;
96
95
  fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
97
- console.log(chalk.green(` added "sna": "^${version}" to dependencies`));
98
- console.log(chalk.gray(` run pnpm install to install`));
96
+ console.log(` added "sna": "^${version}" to dependencies`);
97
+ console.log(` run pnpm install to install`);
99
98
  } else {
100
- console.log(chalk.gray(` sna already in package.json`));
99
+ console.log(` sna already in package.json`);
101
100
  }
102
101
  console.log();
103
102
  cmdLink();
@@ -22,7 +22,8 @@ function resolveClaudePath(cwd) {
22
22
  for (const p of [
23
23
  "/opt/homebrew/bin/claude",
24
24
  "/usr/local/bin/claude",
25
- `${process.env.HOME}/.local/bin/claude`
25
+ `${process.env.HOME}/.local/bin/claude`,
26
+ `${process.env.HOME}/.claude/bin/claude`
26
27
  ]) {
27
28
  try {
28
29
  execSync(`test -x "${p}"`, { stdio: "pipe" });
@@ -31,7 +32,9 @@ function resolveClaudePath(cwd) {
31
32
  }
32
33
  }
33
34
  try {
34
- return execSync(`${SHELL} -l -c "which claude"`, { encoding: "utf8" }).trim();
35
+ const raw = execSync(`${SHELL} -i -l -c "command -v claude" 2>/dev/null`, { encoding: "utf8", timeout: 5e3 }).trim();
36
+ const match = raw.match(/=(.+)/) ?? raw.match(/^(\/\S+)/m);
37
+ return match ? match[1] : raw;
35
38
  } catch {
36
39
  return "claude";
37
40
  }
@@ -1,13 +1,4 @@
1
- declare const tags: {
2
- readonly sna: string;
3
- readonly req: string;
4
- readonly agent: string;
5
- readonly stdin: string;
6
- readonly stdout: string;
7
- readonly route: string;
8
- readonly ws: string;
9
- readonly err: string;
10
- };
1
+ declare const tags: Record<string, string>;
11
2
  type Tag = keyof typeof tags;
12
3
  declare function log(tag: Tag, ...args: unknown[]): void;
13
4
  declare function err(tag: Tag, ...args: unknown[]): void;
@@ -1,4 +1,3 @@
1
- import chalk from "chalk";
2
1
  import fs from "fs";
3
2
  import path from "path";
4
3
  const LOG_PATH = path.join(process.cwd(), ".dev.log");
@@ -6,23 +5,10 @@ try {
6
5
  fs.writeFileSync(LOG_PATH, "");
7
6
  } catch {
8
7
  }
9
- function tsPlain() {
8
+ function ts() {
10
9
  return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false, hour: "2-digit", minute: "2-digit", second: "2-digit" });
11
10
  }
12
- function tsColored() {
13
- return chalk.gray(tsPlain());
14
- }
15
11
  const tags = {
16
- sna: chalk.bold.magenta(" SNA "),
17
- req: chalk.bold.blue(" REQ "),
18
- agent: chalk.bold.cyan(" AGT "),
19
- stdin: chalk.bold.green(" IN "),
20
- stdout: chalk.bold.yellow(" OUT "),
21
- route: chalk.bold.blue(" API "),
22
- ws: chalk.bold.green(" WS "),
23
- err: chalk.bold.red(" ERR ")
24
- };
25
- const tagPlain = {
26
12
  sna: " SNA ",
27
13
  req: " REQ ",
28
14
  agent: " AGT ",
@@ -33,18 +19,18 @@ const tagPlain = {
33
19
  err: " ERR "
34
20
  };
35
21
  function appendFile(tag, args) {
36
- const line = `${tsPlain()} ${tag} ${args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ")}
22
+ const line = `${ts()} ${tag} ${args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ")}
37
23
  `;
38
24
  fs.appendFile(LOG_PATH, line, () => {
39
25
  });
40
26
  }
41
27
  function log(tag, ...args) {
42
- console.log(`${tsColored()} ${tags[tag]}`, ...args);
43
- appendFile(tagPlain[tag], args);
28
+ console.log(`${ts()} ${tags[tag] ?? tag}`, ...args);
29
+ appendFile(tags[tag] ?? tag, args);
44
30
  }
45
31
  function err(tag, ...args) {
46
- console.error(`${tsColored()} ${tags[tag]}`, ...args);
47
- appendFile(tagPlain[tag], args);
32
+ console.error(`${ts()} ${tags[tag] ?? tag}`, ...args);
33
+ appendFile(tags[tag] ?? tag, args);
48
34
  }
49
35
  const logger = { log, err };
50
36
  export {
@@ -2,7 +2,6 @@
2
2
  import { serve } from "@hono/node-server";
3
3
  import { Hono as Hono4 } from "hono";
4
4
  import { cors } from "hono/cors";
5
- import chalk2 from "chalk";
6
5
 
7
6
  // src/server/index.ts
8
7
  import { Hono as Hono3 } from "hono";
@@ -360,7 +359,6 @@ ${xml}
360
359
  }
361
360
 
362
361
  // src/lib/logger.ts
363
- import chalk from "chalk";
364
362
  import fs3 from "fs";
365
363
  import path3 from "path";
366
364
  var LOG_PATH = path3.join(process.cwd(), ".dev.log");
@@ -368,23 +366,10 @@ try {
368
366
  fs3.writeFileSync(LOG_PATH, "");
369
367
  } catch {
370
368
  }
371
- function tsPlain() {
369
+ function ts() {
372
370
  return (/* @__PURE__ */ new Date()).toLocaleTimeString("en-US", { hour12: false, hour: "2-digit", minute: "2-digit", second: "2-digit" });
373
371
  }
374
- function tsColored() {
375
- return chalk.gray(tsPlain());
376
- }
377
372
  var tags = {
378
- sna: chalk.bold.magenta(" SNA "),
379
- req: chalk.bold.blue(" REQ "),
380
- agent: chalk.bold.cyan(" AGT "),
381
- stdin: chalk.bold.green(" IN "),
382
- stdout: chalk.bold.yellow(" OUT "),
383
- route: chalk.bold.blue(" API "),
384
- ws: chalk.bold.green(" WS "),
385
- err: chalk.bold.red(" ERR ")
386
- };
387
- var tagPlain = {
388
373
  sna: " SNA ",
389
374
  req: " REQ ",
390
375
  agent: " AGT ",
@@ -395,18 +380,18 @@ var tagPlain = {
395
380
  err: " ERR "
396
381
  };
397
382
  function appendFile(tag, args) {
398
- const line = `${tsPlain()} ${tag} ${args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ")}
383
+ const line = `${ts()} ${tag} ${args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ")}
399
384
  `;
400
385
  fs3.appendFile(LOG_PATH, line, () => {
401
386
  });
402
387
  }
403
388
  function log(tag, ...args) {
404
- console.log(`${tsColored()} ${tags[tag]}`, ...args);
405
- appendFile(tagPlain[tag], args);
389
+ console.log(`${ts()} ${tags[tag] ?? tag}`, ...args);
390
+ appendFile(tags[tag] ?? tag, args);
406
391
  }
407
392
  function err(tag, ...args) {
408
- console.error(`${tsColored()} ${tags[tag]}`, ...args);
409
- appendFile(tagPlain[tag], args);
393
+ console.error(`${ts()} ${tags[tag] ?? tag}`, ...args);
394
+ appendFile(tags[tag] ?? tag, args);
410
395
  }
411
396
  var logger = { log, err };
412
397
 
@@ -428,7 +413,8 @@ function resolveClaudePath(cwd) {
428
413
  for (const p of [
429
414
  "/opt/homebrew/bin/claude",
430
415
  "/usr/local/bin/claude",
431
- `${process.env.HOME}/.local/bin/claude`
416
+ `${process.env.HOME}/.local/bin/claude`,
417
+ `${process.env.HOME}/.claude/bin/claude`
432
418
  ]) {
433
419
  try {
434
420
  execSync(`test -x "${p}"`, { stdio: "pipe" });
@@ -437,7 +423,9 @@ function resolveClaudePath(cwd) {
437
423
  }
438
424
  }
439
425
  try {
440
- return execSync(`${SHELL} -l -c "which claude"`, { encoding: "utf8" }).trim();
426
+ const raw = execSync(`${SHELL} -i -l -c "command -v claude" 2>/dev/null`, { encoding: "utf8", timeout: 5e3 }).trim();
427
+ const match = raw.match(/=(.+)/) ?? raw.match(/^(\/\S+)/m);
428
+ return match ? match[1] : raw;
441
429
  } catch {
442
430
  return "claude";
443
431
  }
@@ -2732,17 +2720,10 @@ root.onError((err2, c) => {
2732
2720
  logger.err("err", `${c.req.method} ${new URL(c.req.url).pathname} \u2192 ${err2.message}`);
2733
2721
  return c.json({ status: "error", message: err2.message, stack: err2.stack }, 500);
2734
2722
  });
2735
- var methodColor = {
2736
- GET: chalk2.green,
2737
- POST: chalk2.yellow,
2738
- DELETE: chalk2.red,
2739
- OPTIONS: chalk2.gray
2740
- };
2741
2723
  root.use("*", async (c, next) => {
2742
2724
  const m = c.req.method;
2743
- const colorFn = methodColor[m] ?? chalk2.white;
2744
2725
  const path6 = new URL(c.req.url).pathname;
2745
- logger.log("req", `${colorFn(m.padEnd(6))} ${path6}`);
2726
+ logger.log("req", `${m.padEnd(6)} ${path6}`);
2746
2727
  await next();
2747
2728
  });
2748
2729
  var sessionManager = new SessionManager({ maxSessions });
@@ -2758,17 +2739,17 @@ function shutdown(signal) {
2758
2739
  if (shuttingDown) return;
2759
2740
  shuttingDown = true;
2760
2741
  console.log("");
2761
- logger.log("sna", chalk2.dim("stopping all sessions..."));
2742
+ logger.log("sna", "stopping all sessions...");
2762
2743
  sessionManager.killAll();
2763
2744
  if (server) {
2764
2745
  server.close(() => {
2765
- logger.log("sna", chalk2.green("clean shutdown") + chalk2.dim(" \u2014 see you next time"));
2746
+ logger.log("sna", "clean shutdown \u2014 see you next time");
2766
2747
  console.log("");
2767
2748
  process.exit(0);
2768
2749
  });
2769
2750
  }
2770
2751
  setTimeout(() => {
2771
- logger.log("sna", chalk2.green("shutdown complete"));
2752
+ logger.log("sna", "shutdown complete");
2772
2753
  console.log("");
2773
2754
  process.exit(0);
2774
2755
  }, 3e3).unref();
@@ -2782,13 +2763,13 @@ process.on("uncaughtException", (err2) => {
2782
2763
  });
2783
2764
  server = serve({ fetch: root.fetch, port }, () => {
2784
2765
  console.log("");
2785
- logger.log("sna", chalk2.green.bold(`API server ready \u2192 http://localhost:${port}`));
2786
- logger.log("sna", chalk2.dim(`WebSocket endpoint \u2192 ws://localhost:${port}/ws`));
2766
+ logger.log("sna", `API server ready \u2192 http://localhost:${port}`);
2767
+ logger.log("sna", `WebSocket endpoint \u2192 ws://localhost:${port}/ws`);
2787
2768
  console.log("");
2788
2769
  });
2789
2770
  attachWebSocket(server, sessionManager);
2790
2771
  agentProcess.on("event", (e) => {
2791
2772
  if (e.type === "init") {
2792
- logger.log("agent", chalk2.green(`agent ready (session=${e.data?.sessionId ?? "?"})`));
2773
+ logger.log("agent", `agent ready (session=${e.data?.sessionId ?? "?"})`);
2793
2774
  }
2794
2775
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sna-sdk/core",
3
- "version": "0.9.5",
3
+ "version": "0.9.9",
4
4
  "description": "Skills-Native Application runtime — server, providers, session management, database, and CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -102,7 +102,6 @@
102
102
  ],
103
103
  "dependencies": {
104
104
  "@hono/node-server": "^1.19.11",
105
- "chalk": "^5.0.0",
106
105
  "hono": "^4.12.7",
107
106
  "js-yaml": "^4.1.0",
108
107
  "ws": "^8.20.0"