@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@sns-myagent/cli",
4
- "version": "0.2.0",
4
+ "version": "0.3.1",
5
5
  "description": "SNS-MyAgent — Pi Agent size, full features. BYOK coding agent CLI.",
6
6
  "homepage": "https://github.com/Reihantt6/sns-myagent",
7
7
  "author": "Reihantt6",
@@ -33,7 +33,7 @@
33
33
  "scripts": {
34
34
  "fetch-binary": "node scripts/fetch-binary.mjs",
35
35
  "postinstall": "node scripts/fetch-binary.mjs && node scripts/apply-pi-natives-patch.js",
36
- "build": "bun build --compile --define process.env.PI_COMPILED='\"true\"' --define process.env.PKG_VERSION='\"0.1.0\"' --no-compile-autoload-bunfig --no-compile-autoload-dotenv --no-compile-autoload-tsconfig --no-compile-autoload-package-json --keep-names --outfile bin/snscoder-linux-x64 ./src/cli/entry.ts && cp bin/snscoder-linux-x64 bin/snscoder",
36
+ "build": "bun build --compile --define process.env.PI_COMPILED='\"true\"' --define process.env.PKG_VERSION='\"0.3.0\"' --no-compile-autoload-bunfig --no-compile-autoload-dotenv --no-compile-autoload-tsconfig --no-compile-autoload-package-json --keep-names --outfile bin/snscoder-linux-x64 ./src/cli/entry.ts && cp bin/snscoder-linux-x64 bin/snscoder",
37
37
  "check": "biome check . && bun run check:types",
38
38
  "check:types": "tsgo -p tsconfig.json --noEmit",
39
39
  "lint": "biome lint .",
@@ -42,7 +42,7 @@
42
42
  "fmt": "biome format --write . && bun run format-prompts",
43
43
  "format-prompts": "bun scripts/format-prompts.ts",
44
44
  "generate-docs-index": "bun scripts/generate-docs-index.ts --generate",
45
- "prepack": "bun scripts/generate-docs-index.ts --generate && (bun --cwd=../collab-web run build:tool-views 2>/dev/null || echo 'collab-web not found, skipping') && bun scripts/bundle-dist.ts || ( bun scripts/generate-docs-index.ts --reset; exit 1 )",
45
+ "prepack": "(bun scripts/generate-docs-index.ts --generate 2>/dev/null || echo 'docs index skipped') && (bun --cwd=../collab-web run build:tool-views 2>/dev/null || echo 'collab-web not found, skipping') && (bun scripts/bundle-dist.ts 2>/dev/null || echo 'bundle-dist skipped')",
46
46
  "postpack": "bun scripts/generate-docs-index.ts --reset",
47
47
  "bench:guard": "bun scripts/bench-guard.ts"
48
48
  },
@@ -106,6 +106,7 @@
106
106
  },
107
107
  "files": [
108
108
  "src",
109
+ "bin",
109
110
  "dist/cli.js",
110
111
  "dist/*.node",
111
112
  "scripts",
@@ -6,6 +6,13 @@
6
6
  * .node addon is unavailable in a compiled Bun binary (no embed:native step).
7
7
  * This lets the binary start in "JS-only mode" instead of crashing.
8
8
  *
9
+ * The patch REPLACES the trailing `throw new Error("Failed to load ...")` block
10
+ * with an `if (ctx.isCompiledBinary) return noopProxy; else throw;` block. The
11
+ * earlier version of this patch only APPENDED a fallback after the throw — but
12
+ * `throw` is unconditional and aborts the function, so the fallback was dead
13
+ * code. This rewrite uses string replacement to convert the throw into a
14
+ * conditional re-throw.
15
+ *
9
16
  * Re-run: node scripts/apply-pi-natives-patch.js
10
17
  */
11
18
  import { readFileSync, writeFileSync, existsSync } from "node:fs";
@@ -15,72 +22,91 @@ import { fileURLToPath } from "node:url";
15
22
  const __dirname = dirname(fileURLToPath(import.meta.url));
16
23
  const root = join(__dirname, "..");
17
24
 
18
- const target = join(
19
- root,
20
- "node_modules",
21
- "@oh-my-pi",
22
- "pi-natives",
23
- "native",
24
- "loader-state.js",
25
- );
25
+ const target = join(root, "node_modules", "@oh-my-pi", "pi-natives", "native", "loader-state.js");
26
26
 
27
27
  if (!existsSync(target)) {
28
- console.warn("[patch] pi-natives not installed, skipping.");
29
- process.exit(0);
28
+ console.warn("[patch] pi-natives not installed, skipping.");
29
+ process.exit(0);
30
30
  }
31
31
 
32
32
  const src = readFileSync(target, "utf8");
33
33
 
34
- // Already patched?
35
- if (src.includes("JS-only fallback")) {
36
- console.log("[patch] loader-state.js already patched, skipping.");
37
- process.exit(0);
34
+ // Idempotent: already fully patched with the conditional version
35
+ if (src.includes("JS-only mode: native addon unavailable")) {
36
+ console.log("[patch] loader-state.js already fully patched, skipping.");
37
+ process.exit(0);
38
38
  }
39
39
 
40
- const marker = "If you need support for this platform, please open an issue.";
41
- const idx = src.indexOf(marker);
42
- if (idx === -1) {
43
- console.error("[patch] Could not locate injection point in loader-state.js");
44
- process.exit(1);
40
+ // Idempotent: old incomplete patch applied (has dead code after throw)
41
+ // restore by removing the dead append, then re-apply below.
42
+ let working = src;
43
+ const deadBlockMarker = "\t// --- JS-only fallback: return a no-op stub proxy so the binary can ---";
44
+ const deadIdx = working.indexOf(deadBlockMarker);
45
+ if (deadIdx !== -1) {
46
+ // Remove everything from the dead block marker to end of file or to next
47
+ // standalone `}\n\n}` (end of function). Conservative: remove marker + 60 lines.
48
+ const lines = working.split("\n");
49
+ const markerLine = lines.findIndex((l) => l.includes(deadBlockMarker));
50
+ // Find the trailing closing brace of the loadNative function (single `}\n` at col 0
51
+ // or `\n}` at start of line preceded by blank line)
52
+ let endLine = lines.length;
53
+ for (let i = markerLine + 1; i < lines.length; i++) {
54
+ if (lines[i] === "}") {
55
+ endLine = i + 1;
56
+ break;
57
+ }
58
+ }
59
+ lines.splice(markerLine, endLine - markerLine);
60
+ working = lines.join("\n");
61
+ console.log("[patch] Removed dead JS-only fallback block from prior incomplete patch.");
45
62
  }
46
63
 
47
- // Find the end of the "Unsupported platform" throw block (next closing brace + newline)
48
- const afterMarker = src.indexOf("\n\t);", idx) + 4; // after the );\n
49
-
50
- const patch = `
51
- \t// --- JS-only fallback: return a no-op stub proxy so the binary can ---
52
- \t// --- start up even when pi_natives .node files are unavailable. ---
53
- \tif (ctx.isCompiledBinary) {
54
- \t\tconst details = errors.map(error => \`- \${error}\`).join("\\n");
55
- \t\tstartupMarker(\`native:loadNative:jsOnlyFallback:\${details}\`);
56
- \t\ttry {
57
- \t\t\tfs.writeSync(2, \`[pi-natives] JS-only mode: native addon unavailable for \${ctx.addonLabel}\\n\`);
58
- \t\t\tfs.writeSync(2, \`[pi-natives] Tried:\\n\${details}\\n\`);
59
- \t\t\tfs.writeSync(2, \`[pi-natives] Native features (grep, pty, shell, clipboard, syntax highlighting, etc.) are disabled.\\n\`);
60
- \t\t} catch {
61
- \t\t\t// stderr unavailable
62
- \t\t}
64
+ // Locate the trailing throw new Error("Failed to load pi_natives...") block.
65
+ const throwStart = 'throw new Error(\n\t\t`Failed to load pi_natives native addon';
66
+ const throwIdx = working.indexOf(throwStart);
67
+ if (throwIdx === -1) {
68
+ console.error("[patch] Could not locate `throw new Error` block to replace.");
69
+ process.exit(1);
70
+ }
71
+ const throwEnd = working.indexOf("\n\t);", throwIdx) + 4;
72
+ const oldThrowBlock = working.substring(throwIdx, throwEnd);
63
73
 
64
- \t\tconst noop = new Proxy(function () {}, {
65
- \t\t\tget(_target, prop) {
66
- \t\t\t\tif (prop === Symbol.toPrimitive) return () => "";
67
- \t\t\t\tif (prop === Symbol.toStringTag) return "NativeStub";
68
- \t\t\t\tif (prop === "then") return undefined;
69
- \t\t\t\tif (prop === Symbol.iterator) return function* () {};
70
- \t\t\t\tif (prop === "length") return 0;
71
- \t\t\t\treturn noop;
72
- \t\t\t},
73
- \t\t\tapply(_target, _thisArg, args) {
74
- \t\t\t\treturn noop;
75
- \t\t\t},
76
- \t\t\tconstruct(_target, _args) {
77
- \t\t\t\treturn noop;
78
- \t\t\t},
79
- \t\t});
80
- \t\treturn noop;
81
- \t}
82
- `;
74
+ // New conditional block: when compiled binary, return noop Proxy stub;
75
+ // otherwise re-throw the original error.
76
+ const replacement = [
77
+ "\t// --- JS-only fallback (patched by scripts/apply-pi-natives-patch.js): ---",
78
+ "\t// --- when compiled binary can't load native .node, return a no-op ---",
79
+ "\t// --- Proxy stub so the binary still starts. Plain Node mode keeps ---",
80
+ "\t// --- the original throw so missing-native is a hard failure there. ---",
81
+ "\tif (ctx.isCompiledBinary) {",
82
+ "\t\tconst fallbackDetails = errors.map(error => `- ${error}`).join(\"\\n\");",
83
+ "\t\tstartupMarker(`native:loadNative:jsOnlyFallback:${fallbackDetails}`);",
84
+ "\t\ttry {",
85
+ "\t\t\tfs.writeSync(2, `[pi-natives] JS-only mode: native addon unavailable for ${ctx.addonLabel}\\n`);",
86
+ "\t\t\tfs.writeSync(2, `[pi-natives] Native features (grep, pty, shell, clipboard, syntax highlighting, etc.) are disabled.\\n`);",
87
+ "\t\t} catch {",
88
+ "\t\t\t// stderr unavailable",
89
+ "\t\t}",
90
+ "",
91
+ "\t\tconst noop = new Proxy(function () {}, {",
92
+ "\t\t\tget(_target, prop) {",
93
+ "\t\t\t\tif (prop === Symbol.toPrimitive) return () => \"\";",
94
+ "\t\t\t\tif (prop === Symbol.toStringTag) return \"NativeStub\";",
95
+ "\t\t\t\tif (prop === \"then\") return undefined;",
96
+ "\t\t\t\tif (prop === Symbol.iterator) return function* () {};",
97
+ "\t\t\t\tif (prop === \"length\") return 0;",
98
+ "\t\t\t\treturn noop;",
99
+ "\t\t\t},",
100
+ "\t\t\tapply(_target, _thisArg, _args) { return noop; },",
101
+ "\t\t\tconstruct(_target, _args) { return noop; },",
102
+ "\t\t});",
103
+ "\t\treturn noop;",
104
+ "\t}",
105
+ "\tthrow new Error(",
106
+ "\t\t`Failed to load pi_natives native addon for ${ctx.addonLabel}.\\n\\nTried:\\n${details}\\n\\n${buildHelpMessage(ctx)}`,",
107
+ "\t);",
108
+ ].join("\n");
83
109
 
84
- const patched = src.slice(0, afterMarker) + patch + src.slice(afterMarker);
110
+ const patched = working.replace(oldThrowBlock, replacement);
85
111
  writeFileSync(target, patched, "utf8");
86
- console.log("[patch] Applied pi-natives JS-only fallback patch.");
112
+ console.log("[patch] Applied pi-natives JS-only fallback patch (conditional version).");