@sns-myagent/cli 0.2.0 → 0.3.1

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 (67) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/README.md +7 -8
  3. package/bin/.gitkeep +0 -0
  4. package/bin/snscoder.js +7 -96
  5. package/dist/cli.js +22026 -0
  6. package/package.json +4 -3
  7. package/scripts/apply-pi-natives-patch.js +82 -56
  8. package/scripts/fetch-binary.mjs +106 -217
  9. package/scripts/smoke-test.sh +92 -0
  10. package/src/adapters/telegram/bot.ts +41 -1
  11. package/src/adapters/telegram/bridge.ts +186 -0
  12. package/src/adapters/telegram/handler.ts +138 -13
  13. package/src/adapters/telegram/index.ts +12 -2
  14. package/src/agents/__tests__/config.test.ts +79 -0
  15. package/src/agents/__tests__/resilience.test.ts +119 -0
  16. package/src/agents/__tests__/strategies.test.ts +83 -0
  17. package/src/agents/config.ts +367 -0
  18. package/src/agents/ensemble.ts +230 -0
  19. package/src/agents/resilience.ts +332 -0
  20. package/src/agents/strategies/best-of-n.ts +108 -0
  21. package/src/agents/strategies/consensus.ts +104 -0
  22. package/src/agents/strategies/critic.ts +131 -0
  23. package/src/agents/strategies/index.ts +12 -0
  24. package/src/agents/strategies/types.ts +68 -0
  25. package/src/async/__tests__/task-runner.test.ts +162 -0
  26. package/src/async/__tests__/task-store.test.ts +146 -0
  27. package/src/async/index.ts +28 -1
  28. package/src/async/notifier.ts +133 -0
  29. package/src/async/task-runner.ts +175 -0
  30. package/src/async/task-store.ts +170 -0
  31. package/src/async/types.ts +70 -0
  32. package/src/cli/entry.ts +3 -1
  33. package/src/cli/index.ts +74 -55
  34. package/src/config/index.ts +1 -1
  35. package/src/debug/index.ts +1 -1
  36. package/src/internal-urls/docs-index.generated.txt +0 -2
  37. package/src/modes/components/welcome.ts +13 -6
  38. package/src/modes/controllers/event-controller.ts +1 -1
  39. package/src/modes/setup-wizard/scenes/splash.ts +1 -1
  40. package/src/session/agent-session.ts +1 -1
  41. package/src/slash-commands/builtin-registry.ts +63 -0
  42. package/src/slash-commands/helpers/task.ts +181 -0
  43. package/src/tbm/__tests__/tbm.test.ts +660 -0
  44. package/src/tbm/comm-modes.ts +165 -0
  45. package/src/tbm/config.ts +136 -0
  46. package/src/tbm/context-delta.ts +146 -0
  47. package/src/tbm/context-pyramid.ts +202 -0
  48. package/src/tbm/dashboard.ts +131 -0
  49. package/src/tbm/index.ts +247 -0
  50. package/src/tbm/lazy-skills.ts +182 -0
  51. package/src/tbm/response-cache.ts +220 -0
  52. package/src/tbm/tombstone.ts +189 -0
  53. package/src/tbm/tool-compress.ts +230 -0
  54. package/src/tools/ask.ts +1 -1
  55. package/src/tui/chat-blocks.ts +205 -0
  56. package/src/tui/chat-ui.ts +270 -0
  57. package/src/tui/code-cell.ts +90 -1
  58. package/src/tui/command-palette.ts +189 -0
  59. package/src/tui/index.ts +4 -0
  60. package/src/tui/splash.ts +130 -0
  61. package/src/ui/banner.ts +69 -29
  62. package/src/ui/colors.ts +24 -0
  63. package/src/ui/error-display.ts +130 -0
  64. package/src/ui/gradient.ts +104 -0
  65. package/src/ui/index.ts +15 -0
  66. package/src/ui/memory-toast.ts +102 -0
  67. package/src/ui/status-bar.ts +36 -30
package/CHANGELOG.md CHANGED
@@ -10,10 +10,21 @@ Versioning: [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
10
10
  ## [Unreleased]
11
11
 
12
12
  ### Added
13
+ - **TBM (Token Budget Manager) fully implemented** — 7 core modules:
14
+ - Context Delta Cache: static/dynamic message splitting, ~40% token savings
15
+ - Context Pyramid: 5 compression levels (L0–L4), auto-demotion based on budget pressure
16
+ - Lazy Skill Loading: index-on-demand instead of bulk inject, ~85% savings
17
+ - Tool Output Compression: per-tool budgets, auto-truncation, JSON/HTML/markdown reducers
18
+ - Conversation Tombstoning: old messages → 10-line summaries, ~85% reduction
19
+ - Response Cache: exact + semantic (Jaccard bigram) match, configurable TTL
20
+ - Communication Modes: caveman/normal/verbose/auto with system prompt directives
21
+ - `/tokens` command: full TBM dashboard (session stats, cache hits, compression, pyramid level, cost estimate)
22
+ - `/mode` command: set caveman/normal/verbose/auto communication mode
23
+ - `TbmManager` singleton class coordinating all subsystems
13
24
  - Phase 1 scaffold complete: forked from Pi Agent, rebranded as `@sns-myagent/cli` with `snscoder` binary (commit `d1480eb`)
14
25
  - GitHub Actions CI/CD pipeline (`.github/workflows/ci.yml`) with staged verify → install → typecheck → lint → build → diagnose jobs
15
26
  - BYOK provider config system with `.sns-myagent/config.yaml` + env overrides
16
- - Real source-derived inventory of 58 built-in slash commands and 70+ tools documented in README
27
+ - Real source-derived inventory of 58 built-in slash commands and 30 built-in tools documented in README
17
28
  - `docs/memory.md` covering mnemopi / mnemosyne / mem0 / lcm backends
18
29
  - `docs/tbm.md` Token Budget Manager reference
19
30
  - `SECURITY.md` vulnerability reporting + security model
package/README.md CHANGED
@@ -18,12 +18,12 @@
18
18
  </p>
19
19
 
20
20
  <p align="center">
21
- <strong>BYOK coding agent CLI — 30 built-in tools, 58 slash commands, multi-provider LLM, memory, MCP, Telegram.</strong>
21
+ <strong>BYOK coding agent CLI — 30 built-in tools, 61 slash commands, multi-provider LLM, memory, MCP, Telegram.</strong>
22
22
  </p>
23
23
 
24
24
  <p align="center">
25
25
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue?style=flat-square" alt="License: MIT"></a>
26
- <img src="https://img.shields.io/badge/version-0.1.0-yellow?style=flat-square" alt="Version 0.1.0">
26
+ <img src="https://img.shields.io/badge/version-0.2.0-yellow?style=flat-square" alt="Version 0.2.0">
27
27
  <img src="https://img.shields.io/badge/bun-%3E%3D1.3.14-efbbf4?style=flat-square&logo=bun&logoColor=black" alt="Bun >= 1.3.14">
28
28
  <img src="https://img.shields.io/badge/typescript-5.x-3178C6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript 5.x">
29
29
  </p>
@@ -60,9 +60,9 @@
60
60
  | Feature | Source |
61
61
  |---------|--------|
62
62
  | **30 built-in tools** | `src/tools/builtin-names.ts` |
63
- | **58 slash commands** | `src/slash-commands/builtin-registry.ts` |
63
+ | **61 slash commands** | `src/slash-commands/builtin-registry.ts` |
64
64
  | **Multi-provider LLM** | OpenAI, Anthropic, Ollama, custom endpoints via `@oh-my-pi/pi-ai` |
65
- | **4 memory backends** | mnemopi (default), hindsight, local, off — `src/memory-backend/resolve.ts` |
65
+ | **7 memory backends** | mnemopi (default), hindsight, mnemosyne, mem0, lcm, local, off — `src/memory-backend/resolve.ts` |
66
66
  | **MCP integration** | 22 source files in `src/mcp/` |
67
67
  | **Plan mode** | `src/plan-mode/` — agent plans before executing |
68
68
  | **Goal mode** | Autonomous objective with token budget and lifecycle |
@@ -117,11 +117,10 @@ All tool names come from `src/tools/builtin-names.ts`.
117
117
  | `debug` | Debugging assistance |
118
118
 
119
119
  ### Web & Browser
120
-
120
+ ### Web & Browser
121
121
  | Tool | Description |
122
122
  |------|-------------|
123
123
  | `web_search` | Web search via configured provider |
124
- | `search` | File/content search |
125
124
  | `search_tool_bm25` | BM25-based search tool |
126
125
  | `browser` | Headless browser automation (Puppeteer) |
127
126
  | `inspect_image` | Image analysis |
@@ -159,7 +158,7 @@ All tool names come from `src/tools/builtin-names.ts`.
159
158
 
160
159
  ## Slash Commands
161
160
 
162
- 58 built-in commands from `src/slash-commands/builtin-registry.ts`. Most useful:
161
+ 61 built-in commands from `src/slash-commands/builtin-registry.ts`. Most useful:
163
162
 
164
163
  ### Session & Navigation
165
164
 
@@ -401,7 +400,7 @@ Settings use dot-separated paths. Full schema in `src/config/settings-schema.ts`
401
400
  "eval.jl": true,
402
401
 
403
402
  // Memory
404
- "memory.backend": "mnemopi", // "mnemopi" | "hindsight" | "local" | "off"
403
+ "memory.backend": "mnemopi", // "mnemopi" | "hindsight" | "mnemosyne" | "mem0" | "lcm" | "local" | "off"
405
404
  "hindsight.scoping": "...",
406
405
 
407
406
  // MCP
package/bin/.gitkeep ADDED
File without changes
package/bin/snscoder.js CHANGED
@@ -1,98 +1,9 @@
1
1
  #!/usr/bin/env node
2
- // bin/snscoder.js npm-installed shim that locates and spawns the
3
- // platform-specific prebuilt binary downloaded by scripts/fetch-binary.mjs
4
- // (or built locally via `bun scripts/build-binary.ts`).
5
- //
6
- // Runs on plain Node 18+. Uses spawnSync so npm postinstall script chaining
7
- // behaves predictably and exit codes propagate correctly.
8
-
9
- import { existsSync, statSync } from "node:fs";
10
- import { spawnSync } from "node:child_process";
11
- import { dirname, join, resolve } from "node:path";
2
+ // Auto-generated by fetch-binary.mjs execs the platform binary.
3
+ import { spawn } from "node:child_process";
12
4
  import { fileURLToPath } from "node:url";
13
-
14
- const __filename = fileURLToPath(import.meta.url);
15
- const __dirname = dirname(__filename);
16
- const REPO_ROOT = resolve(__dirname, "..");
17
-
18
- const platform = process.platform;
19
- const arch = process.arch;
20
- const isWin = platform === "win32";
21
-
22
- const binaryName = isWin ? "snscoder.exe" : "snscoder";
23
- const binaryPath = join(REPO_ROOT, "bin", binaryName);
24
- const altBinaryPath = join(REPO_ROOT, "bin", `${binaryName}-${platform}-${arch}${isWin ? ".exe" : ""}`);
25
-
26
- // Local dev fallback: if a sibling dist/omp or dist/cli.js exists (source build),
27
- // prefer invoking the Node entry so contributors without a fetched binary still work.
28
- const devEntryCandidates = [
29
- join(REPO_ROOT, "dist", "omp"), // compiled Bun binary from `bun scripts/build-binary.ts`
30
- join(REPO_ROOT, "dist", "cli.js"), // legacy Node entry
31
- ];
32
-
33
- function missingHelp() {
34
- const lines = [
35
- "",
36
- `\u001b[31m✗ snscoder binary not found at ${binaryPath}\u001b[0m`,
37
- "",
38
- " SNS-MyAgent ships a platform-specific prebuilt binary that is downloaded",
39
- " on `npm install` (or fetched explicitly via `npm run fetch-binary`). The",
40
- " binary appears to be missing from this install.",
41
- "",
42
- " \u001b[1mFix — pick one:\u001b[0m",
43
- " 1. Re-run the npm postinstall step:",
44
- " npm rebuild # re-runs postinstall for current pkg",
45
- " npm install -g @sns-myagent/cli --force # full reinstall",
46
- " 2. Use the recommended installer (handles Bun + binary end-to-end):",
47
- " curl -fsSL https://sns.myagent.id/install.sh | bash",
48
- " 3. Windows PowerShell:",
49
- " irm raw.githubusercontent.com/Reihantt6/sns-myagent/main/install.ps1 | iex",
50
- " 4. Build from source (requires Bun >= 1.3.14):",
51
- " git clone https://github.com/Reihantt6/sns-myagent",
52
- " cd sns-myagent && bun install && bun run build",
53
- "",
54
- " If a release hasn't been published yet, you will see a warning from",
55
- " scripts/fetch-binary.mjs during install — that's expected and not a bug.",
56
- "",
57
- ];
58
- process.stderr.write(lines.join("\n"));
59
- }
60
-
61
- function pickExecutable() {
62
- if (existsSync(binaryPath) && statSync(binaryPath).isFile()) {
63
- return { path: binaryPath, args: [] };
64
- }
65
- if (existsSync(altBinaryPath) && statSync(altBinaryPath).isFile()) {
66
- return { path: altBinaryPath, args: [] };
67
- }
68
- // Local dev fallback: bun build artifact or legacy Node entry.
69
- for (const candidate of devEntryCandidates) {
70
- if (existsSync(candidate) && statSync(candidate).isFile()) {
71
- const isNodeEntry = candidate.endsWith(".js");
72
- return {
73
- path: isNodeEntry ? process.execPath : candidate,
74
- args: isNodeEntry ? [candidate] : [],
75
- };
76
- }
77
- }
78
- return null;
79
- }
80
-
81
- const exe = pickExecutable();
82
- if (!exe) {
83
- missingHelp();
84
- process.exit(1);
85
- }
86
-
87
- const result = spawnSync(exe.path, [...exe.args, ...process.argv.slice(2)], {
88
- stdio: "inherit",
89
- // Forward env so callers can still pass API keys etc. through npm-global env.
90
- env: process.env,
91
- });
92
-
93
- // Propagate signal-based termination (e.g. SIGINT from Ctrl-C) rather than
94
- // reporting exit code 1.
95
- if (result.signal) {
96
- process.exit(1);
97
- }
98
- process.exit(result.status ?? 1);
5
+ import { dirname, join } from "node:path";
6
+ const here = dirname(fileURLToPath(import.meta.url));
7
+ const bin = join(here, "snscoder-linux-x64");
8
+ const r = spawn(bin, process.argv.slice(2), { stdio: "inherit" });
9
+ r.on("exit", (c) => process.exit(c ?? 0));