mshcode 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 noodcon0312
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # Temporary Holding Version
1
+ # mshcode
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Msh Code is an agentic coding tool that runs in your terminal. Just a single Python file, standard library only.
4
+
5
+ ![demo](https://github.com/user-attachments/assets/e1ead27b-c9f7-4f4f-9f07-4ea2cc67662f)
6
+
7
+ ## Get started
8
+
9
+ ```
10
+ npm install -g mshcode
11
+ mshcode
12
+ ```
13
+
14
+ or without installing: `npx mshcode`
15
+
16
+ You need Node.js 14+ (only to start it) and **Python 3.8+**. If Python is not on your PATH, set `MSHCODE_PYTHON` to its
17
+ full path. Anything after `mshcode` is passed on unchanged (for example `mshcode test` runs the self-tests).
18
+
19
+ This package contains the same `mshcode.py` as the [GitHub repo](https://github.com/noodcon0312/Msh-Code); you can also run
20
+ that file directly with `python3 mshcode.py` (`py mshcode.py` on Windows).
21
+
22
+ ## Updating
23
+
24
+ ```
25
+ npm install -g mshcode@latest
26
+ ```
27
+
28
+ MshCode's own `/update` replaces the file it runs from. A global npm install is often not writable, and npm would
29
+ overwrite the change anyway, so update with npm when you installed with npm.
30
+
31
+ ## Bugs
32
+
33
+ Please report bugs in [Issues](https://github.com/noodcon0312/Msh-Code/issues).
34
+
35
+ ## License
36
+
37
+ MIT
package/bin/mshcode.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ // mshcode: starts MshCode (mshcode.py, standard library only) with a Python 3.8+ found on this machine.
4
+ // Everything after `mshcode` is passed on unchanged; the keyboard, the screen and the exit code are MshCode's own.
5
+ const { spawn, spawnSync } = require("child_process");
6
+ const os = require("os");
7
+ const path = require("path");
8
+
9
+ const SCRIPT = path.join(__dirname, "..", "mshcode.py");
10
+ const MIN = [3, 8];
11
+ const WIN = process.platform === "win32";
12
+
13
+ function probe(cmd, pre) {
14
+ const r = spawnSync(cmd, pre.concat(["-c", "import sys; print('%d.%d' % sys.version_info[:2])"]), {
15
+ encoding: "utf8",
16
+ timeout: 15000,
17
+ windowsHide: true,
18
+ });
19
+ if (r.error || r.status !== 0) return null;
20
+ const v = String(r.stdout).trim();
21
+ const m = /^(\d+)\.(\d+)$/.exec(v);
22
+ return m ? { cmd, pre, version: v, ok: +m[1] > MIN[0] || (+m[1] === MIN[0] && +m[2] >= MIN[1]) } : null;
23
+ }
24
+
25
+ function findPython() {
26
+ const tries = [];
27
+ if (process.env.MSHCODE_PYTHON) tries.push([process.env.MSHCODE_PYTHON, []]);
28
+ tries.push(["python3", []], ["python", []]);
29
+ if (WIN) tries.push(["py", ["-3"]]);
30
+ const old = [];
31
+ for (const [cmd, pre] of tries) {
32
+ const p = probe(cmd, pre);
33
+ if (p && p.ok) return { found: p };
34
+ if (p) old.push(cmd + " " + p.version);
35
+ }
36
+ return { old };
37
+ }
38
+
39
+ const { found, old } = findPython();
40
+ if (!found) {
41
+ const lines = ["mshcode needs Python " + MIN.join(".") + " or newer, and could not find one."];
42
+ if (old.length) lines.push("Found only: " + old.join(", ") + ".");
43
+ lines.push(
44
+ WIN
45
+ ? "Install it from https://www.python.org/downloads/ (tick 'Add python.exe to PATH'), or: winget install Python.Python.3.12"
46
+ : process.platform === "darwin"
47
+ ? "Install it with: brew install python"
48
+ : "Install it with your package manager, for example: sudo apt install python3",
49
+ "To use a Python that is not on PATH: set MSHCODE_PYTHON to its full path."
50
+ );
51
+ console.error(lines.join("\n"));
52
+ process.exit(1);
53
+ }
54
+
55
+ const child = spawn(found.cmd, found.pre.concat([SCRIPT], process.argv.slice(2)), { stdio: "inherit" });
56
+
57
+ // Ctrl-C reaches MshCode through the terminal itself (it uses it to stop the AI), so this wrapper must not die on it.
58
+ // Without a terminal nobody else would deliver it, so then it is passed on.
59
+ try {
60
+ process.on("SIGINT", () => {
61
+ if (!process.stdin.isTTY) child.kill("SIGINT");
62
+ });
63
+ for (const s of ["SIGTERM", "SIGHUP"]) process.on(s, () => child.kill(s));
64
+ } catch (e) {
65
+ /* a signal that this platform does not have */
66
+ }
67
+
68
+ child.on("error", (e) => {
69
+ console.error("mshcode: cannot start " + found.cmd + ": " + e.message);
70
+ process.exit(1);
71
+ });
72
+ child.on("exit", (code, signal) => {
73
+ if (signal) process.exit(128 + ((os.constants.signals || {})[signal] || 1));
74
+ process.exit(code === null ? 1 : code);
75
+ });