@amoghvj/txr 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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +127 -0
  3. package/dist/index.js +1518 -0
  4. package/package.json +56 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Amogh Vijay
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 ADDED
@@ -0,0 +1,127 @@
1
+ # txr - Transactional Command Runner
2
+
3
+ `txr` is a standalone CLI tool that provides transactional execution of shell commands. It acts as a safety net, allowing you to run commands (like `npm install`, generators, or scripts) and undo them completely if they don't produce the desired outcome.
4
+
5
+ It works independently of any user Git repository, maintaining its own internal state store to track and rollback filesystem changes with strict safety guarantees.
6
+
7
+ ## Philosophy
8
+
9
+ * **One executed command = one transaction.**
10
+ * **Correctness over convenience:** `txr` will strictly refuse to undo if a file was externally modified. It never guesses.
11
+ * **Linear History:** There are no branches or merges. It works like an editor's undo stack.
12
+ * **Invisible Storage:** The internal Git repo is hidden and purely used as an efficient storage engine.
13
+
14
+ ## Installation
15
+
16
+ Currently, `txr` is available as a local package.
17
+
18
+ ```bash
19
+ # Clone or navigate to the repository
20
+ cd agent-cli
21
+
22
+ # Install dependencies and build
23
+ npm install
24
+ npm run build
25
+
26
+ # Link globally (optional, so you can run 'txr' anywhere)
27
+ npm link
28
+ ```
29
+
30
+ If you don't link it, you can run it via `node dist/index.js` or `npx .`.
31
+
32
+ ## Usage Instructions
33
+
34
+ ### 1. Initialize a Workspace
35
+
36
+ Before running transactional commands, initialize `txr` in your project root. This creates a `.txr/` hidden directory to store history and internal state.
37
+
38
+ ```bash
39
+ txr init
40
+ ```
41
+
42
+ By default, `txr` runs in **workspace scope**. This means it only tracks files inside your project directory. If you run a command that modifies files outside the project (like `npm install -g` or writing to an absolute path), `txr` will detect this, flag it as a scope violation, and ask for confirmation before running (and it won't track those external changes).
43
+
44
+ If you want `txr` to track *everything* a command does, no matter where it writes on your system, initialize with global scope:
45
+
46
+ ```bash
47
+ txr init --global
48
+ ```
49
+
50
+ **Using `txr` everywhere on your system:**
51
+ If you want to use `txr run` in *any* folder on your computer without typing `init` for every new project, you can initialize a single global state store in your user's home directory:
52
+
53
+ ```bash
54
+ cd ~
55
+ txr init --global
56
+ ```
57
+ With this setup, `txr` will place the `.txr` folder in your home directory (`~/.txr`). Whenever you use `txr run` anywhere on your machine, it will traverse up the folder tree, find `~/.txr`, and record the transaction there. Because you used `--global`, it will gladly track changes across your entire filesystem.
58
+
59
+ ### 2. Run Commands
60
+
61
+ Execute any command through `txr`. It will automatically track the filesystem changes and record a transaction.
62
+
63
+ ```bash
64
+ txr run "npm install express"
65
+ txr run "npx create-react-app frontend"
66
+ txr run "node script.js"
67
+ ```
68
+
69
+ **Non-transactional Commands:**
70
+ `txr` analyzes commands before running. If you try to run a command that modifies state outside the filesystem (like databases or containers), it will warn you:
71
+
72
+ ```bash
73
+ txr run "docker compose up -d"
74
+ # ⚠ WARNING: This command may modify state outside the transaction engine.
75
+ # Continue? [y/N]
76
+ ```
77
+ You can bypass the prompt with `-y`: `txr run -y "docker compose up -d"`. These commands are logged in history but don't create a transaction.
78
+
79
+ ### 3. Undo a Transaction
80
+
81
+ If a command broke your project, simply undo the most recent transaction. This restores all created, modified, or deleted files to their exact previous state.
82
+
83
+ ```bash
84
+ txr undo
85
+ ```
86
+
87
+ *Note: If any touched file was manually edited outside of `txr` after the transaction, `txr undo` will safely abort to prevent data loss.*
88
+
89
+ ### 4. Redo a Transaction
90
+
91
+ If you undid a transaction by mistake, you can redo it (as long as you haven't run any new commands since).
92
+
93
+ ```bash
94
+ txr redo
95
+ ```
96
+
97
+ ### 5. Check Status and History
98
+
99
+ View the current active transaction and attribution tier:
100
+
101
+ ```bash
102
+ txr status
103
+ ```
104
+
105
+ View an audit log of all commands run through `txr`:
106
+
107
+ ```bash
108
+ txr history
109
+ ```
110
+
111
+ ## Advanced Options
112
+
113
+ * `txr run --transactional "cmd"`: Force a command to be tracked as transactional, even if the classifier flags it as unsafe.
114
+ * `txr run --no-transaction "cmd"`: Force a command to run directly without tracking or generating a transaction.
115
+
116
+ ## Attribution Tiers
117
+
118
+ `txr` uses different methods to track process changes depending on your OS and privileges:
119
+ * **Tier 3 (Hybrid / Scoped Diff):** Default for unprivileged execution. It tracks process lifetimes and diffs declared watch paths.
120
+ * **Tier 2 (Linux ptrace):** *Planned.* Exact syscall interception without root.
121
+ * **Tier 1 (ETW / eBPF):** *Planned.* Exact low-overhead tracking requiring Admin/Root.
122
+
123
+ ## Configuration
124
+
125
+ You can tweak settings in `.txr/metadata/config.json`, such as:
126
+ * `watchPaths`: Array of directories to track for changes (defaults to `["."]`).
127
+ * `ignorePaths`: Glob patterns to ignore (e.g., `node_modules/.cache`).