appback-remoteagent 0.13.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 (46) hide show
  1. package/.env.example +39 -0
  2. package/LICENSE +21 -0
  3. package/README.md +371 -0
  4. package/bin/remoteagent.js +2 -0
  5. package/dist/adapters/claude-adapter.js +78 -0
  6. package/dist/adapters/codex-adapter.js +241 -0
  7. package/dist/adapters/provider-adapter.js +1 -0
  8. package/dist/adapters/shell-adapter.js +44 -0
  9. package/dist/adapters/windows-shell.js +111 -0
  10. package/dist/bot.js +2135 -0
  11. package/dist/config.js +170 -0
  12. package/dist/index.js +534 -0
  13. package/dist/secret-helper.js +24 -0
  14. package/dist/services/agent-memory-service.js +737 -0
  15. package/dist/services/bot-management-service.js +626 -0
  16. package/dist/services/bridge-service.js +807 -0
  17. package/dist/services/local-ui-service.js +533 -0
  18. package/dist/services/provider-setup-service.js +284 -0
  19. package/dist/services/remote-shell-service.js +97 -0
  20. package/dist/store/file-store.js +690 -0
  21. package/dist/telegram-fetch.js +85 -0
  22. package/dist/types.js +1 -0
  23. package/docs/ARCHITECTURE.md +170 -0
  24. package/docs/COKACDIR_NOTES.md +79 -0
  25. package/docs/ERROR_NORMALIZATION.md +46 -0
  26. package/docs/MINI_APP.md +112 -0
  27. package/docs/MVP.md +108 -0
  28. package/docs/OPERATIONS.md +181 -0
  29. package/docs/RELEASING.md +87 -0
  30. package/docs/SESSION_DIRECTORY_PLAN.md +506 -0
  31. package/package.json +47 -0
  32. package/scripts/bump-version.sh +23 -0
  33. package/scripts/finish-claude-login.sh +48 -0
  34. package/scripts/install-claude.sh +6 -0
  35. package/scripts/install-codex.sh +8 -0
  36. package/scripts/install.ps1 +51 -0
  37. package/scripts/install.sh +101 -0
  38. package/scripts/mock-adapter.sh +7 -0
  39. package/scripts/restart-after-bot-op.sh +118 -0
  40. package/scripts/selftest-telegram-update.mjs +359 -0
  41. package/scripts/start-claude-login.sh +4 -0
  42. package/scripts/start.ps1 +39 -0
  43. package/scripts/start.sh +54 -0
  44. package/scripts/stop.ps1 +40 -0
  45. package/scripts/stop.sh +39 -0
  46. package/tsconfig.json +20 -0
@@ -0,0 +1,181 @@
1
+ # Operations
2
+
3
+ ## Source of truth
4
+
5
+ RemoteAgent production is operated from one canonical Git history:
6
+
7
+ - source of truth: `origin/main` on GitHub
8
+ - production runtime host: server 30
9
+ - production package: `appback-remoteagent`
10
+ - branch used for production releases: `main`
11
+
12
+ Do not treat stale server paths or duplicate worktrees as authoritative.
13
+ Code changes should be committed and pushed to `origin/main`, published to npm, and then server 30/26 should be updated from that npm version.
14
+
15
+ ## Product shape in operations
16
+
17
+ Operationally, RemoteAgent is a self-hosted runtime with multiple client surfaces.
18
+
19
+ Current and planned client layers:
20
+
21
+ - Telegram bot chat: primary production client
22
+ - Telegram Mini App: planned richer control UI
23
+ - local terminal / shell: operator maintenance path
24
+
25
+ The runtime server is always the execution engine.
26
+ Neither Telegram chat nor the Mini App is the source of truth for sessions.
27
+
28
+ ## Current bot split
29
+
30
+ Current production bot ownership is intentionally split:
31
+
32
+ - server 30: RemoteAgent production bots
33
+ - local machine 21: local-only bot runtime
34
+
35
+ Do not run the same Telegram bot token from multiple runtimes at the same time.
36
+ Bot polling conflicts are treated as incidents, not harmless warnings.
37
+
38
+ ## Workspace policy
39
+
40
+ Default fresh sessions should not use a broad parent folder like `/home/au2223/projects` as their direct working directory.
41
+
42
+ Current policy:
43
+
44
+ - `DEFAULT_WORKSPACE` is a fallback path for explicit attaches and compatibility
45
+ - `WORKSPACE_ROOT` is the root for runtime-managed fresh session workspaces
46
+ - fresh `/start` and `/new` sessions without an explicit path create a new subdirectory under `WORKSPACE_ROOT`
47
+ - the managed subdirectory name is a random 8-character uid
48
+ - display ids like `S001` remain user-facing session labels only and are not reused as folder names
49
+
50
+ ## Runtime model
51
+
52
+ Server 30 runs RemoteAgent as a `systemd` service.
53
+
54
+ - unit: `remoteagent.service`
55
+ - working directory: the installed `appback-remoteagent` package root
56
+ - runtime data: `/home/au2223/.remoteagent`
57
+ - service entrypoint: `remoteagent` or `node <installed-package-root>/dist/index.js`
58
+
59
+ The service environment is loaded from:
60
+
61
+ - `/home/au2223/.remoteagent/.env`
62
+
63
+ ## Single-instance rule
64
+
65
+ A previous failure mode was mixed lifecycle control:
66
+
67
+ - manual `./scripts/start.sh`
68
+ - existing `systemd` service
69
+ - stale PID files
70
+ - multiple `node dist/index.js` processes
71
+
72
+ That caused old and new builds to overlap and made Telegram image handling look random.
73
+
74
+ Current protections:
75
+
76
+ 1. `systemd` is the primary runtime owner.
77
+ 2. `scripts/start.sh` and `scripts/stop.sh` prefer `systemd` when the service exists.
78
+ 3. the app creates a lock file at `/home/au2223/.remoteagent/remoteagent.lock`.
79
+ 4. a second `node dist/index.js` process exits immediately instead of starting a duplicate runtime.
80
+ 5. per-session message handling is serialized inside `BridgeService`.
81
+
82
+ ## Day-to-day commands
83
+
84
+ Check service status:
85
+
86
+ ```bash
87
+ sudo systemctl status remoteagent
88
+ ```
89
+
90
+ Watch logs:
91
+
92
+ ```bash
93
+ journalctl -u remoteagent -f
94
+ ```
95
+
96
+ Restart after build:
97
+
98
+ ```bash
99
+ sudo npm install -g appback-remoteagent@<version>
100
+ sudo systemctl restart remoteagent
101
+ ```
102
+
103
+ Check the lock owner:
104
+
105
+ ```bash
106
+ cat /home/au2223/.remoteagent/remoteagent.lock
107
+ ```
108
+
109
+ ## Git workflow
110
+
111
+ The intended workflow is:
112
+
113
+ 1. edit in the active development checkout
114
+ 2. choose `patch`, `minor`, or `major` for the current deployment
115
+ 3. bump the package version before deployment
116
+ 4. run `npm run check`
117
+ 5. run `npm run build`
118
+ 6. commit on `main`
119
+ 7. push `main` to `origin/main`
120
+ 8. publish `appback-remoteagent@<version>` to npm
121
+ 9. install that exact npm version on server 30 and server 26
122
+ 10. restart `remoteagent.service` when runtime code changed
123
+ 11. verify logs or a Telegram/local UI path on each target
124
+
125
+ Avoid side branches and extra worktrees unless there is a strong reason.
126
+ If a temporary branch is unavoidable, merge it back to `main`, push it, and deploy from `origin/main`.
127
+
128
+ A task is not done until commit and push both happened.
129
+ A production deployment is not done until server 30 and server 26 are running the published npm version and the runtime path has been verified.
130
+
131
+ See `docs/RELEASING.md` for the detailed versioning rules.
132
+
133
+ ## GitHub authentication
134
+
135
+ Server 30 is configured to push as `appback`.
136
+
137
+ Validation commands:
138
+
139
+ ```bash
140
+ gh auth status -h github.com
141
+ ssh -T git@github.com
142
+ ```
143
+
144
+ At the time of writing, `origin/main` pushes are performed successfully from server 30.
145
+
146
+ ## Mini App operational rule
147
+
148
+ A Telegram Mini App must be treated as another client surface for the same runtime.
149
+
150
+ That means:
151
+
152
+ - it must read and act on the same session model
153
+ - it must not invent a second session store
154
+ - it must not bypass runtime authorization or ownership checks
155
+ - it should prefer structured actions that map cleanly onto existing runtime commands and APIs
156
+
157
+ ## Attachment handling status
158
+
159
+ As of the latest stabilization work:
160
+
161
+ - Telegram image download works
162
+ - files are saved under `/home/au2223/.remoteagent/uploads/telegram/...`
163
+ - duplicate runtime startup has been blocked
164
+ - cross-bot direct Telegram token leakage to provider subprocesses has been blocked
165
+ - official runtime-mediated file sending is available only through confirmed RemoteAgent transfer paths
166
+
167
+ Remaining work is still needed on attachment response policy and richer file UX.
168
+ The transport/runtime stability issue and the user-facing attachment response quality issue are separate concerns.
169
+
170
+ ## Incident summary
171
+
172
+ The main production problem around April and May 2026 was not just attachment support itself.
173
+ The deeper issues were runtime ownership and transport discipline:
174
+
175
+ - old processes survived restarts
176
+ - service-managed and manually-started processes overlapped
177
+ - PID state and actual live processes diverged
178
+ - Telegram responses could come from an unexpected process generation
179
+ - provider subprocesses had to be prevented from directly using Telegram bot tokens
180
+
181
+ The single-instance lock, `systemd`-first lifecycle, and runtime-mediated file transfer rules were added specifically to stop that class of bug from recurring.
@@ -0,0 +1,87 @@
1
+ # Releasing
2
+
3
+ ## Versioning rule
4
+
5
+ RemoteAgent uses semantic versioning for every production deployment:
6
+
7
+ - `MAJOR`: breaking command changes, storage/runtime contract changes, or migrations that can break an existing installation
8
+ - `MINOR`: new user-facing capabilities, new commands, new adapters, or non-breaking workflow expansion
9
+ - `PATCH`: bug fixes, reliability improvements, security fixes, text-only corrections, and non-breaking maintenance
10
+
11
+ Do not deploy production changes without bumping the package version first.
12
+
13
+ ## Decision guide
14
+
15
+ Use `PATCH` when the behavior is supposed to stay the same but gets safer or more correct.
16
+ Use `MINOR` when the owner can do something new after the release without needing migration.
17
+ Use `MAJOR` when an older installation, script, or user workflow would need active adjustment.
18
+
19
+ When unsure between two levels, choose the higher one and explain why in the commit message.
20
+
21
+ ## Required release flow
22
+
23
+ A release is only considered complete when all of the following are done in order:
24
+
25
+ 1. Choose the release scope: `patch`, `minor`, or `major`
26
+ 2. Bump the version in `package.json` and `package-lock.json`
27
+ 3. Run `npm run check`
28
+ 4. Run `npm run build`
29
+ 5. Commit the completed work
30
+ 6. Push `main` to `origin/main`
31
+ 7. Publish `appback-remoteagent@<version>` to npm
32
+ 8. Install that exact npm version on server 30 and server 26
33
+ 9. Restart `remoteagent.service` on each target if runtime code changed
34
+ 10. Verify the relevant runtime path, logs, or Telegram behavior on each target
35
+
36
+ If commit or push is missing, the work is not done.
37
+ If server 30 or server 26 is not running the published npm version, the production deployment is incomplete.
38
+
39
+ ## Commands
40
+
41
+ Version bump helpers:
42
+
43
+ ```bash
44
+ ./scripts/bump-version.sh patch
45
+ ./scripts/bump-version.sh minor
46
+ ./scripts/bump-version.sh major
47
+ ```
48
+
49
+ Equivalent npm shortcuts:
50
+
51
+ ```bash
52
+ npm run version:patch
53
+ npm run version:minor
54
+ npm run version:major
55
+ ```
56
+
57
+ Typical local release sequence:
58
+
59
+ ```bash
60
+ ./scripts/bump-version.sh patch
61
+ npm run check
62
+ npm run build
63
+ git status
64
+ git add -A
65
+ git commit -m "Release 0.12.3"
66
+ git push origin main
67
+ npm publish
68
+ ```
69
+
70
+ Typical target deployment sequence for server 30 and server 26:
71
+
72
+ ```bash
73
+ VERSION=0.13.0
74
+ npm install -g appback-remoteagent@$VERSION
75
+ remoteagent-install
76
+ sudo systemctl restart remoteagent
77
+ systemctl is-active remoteagent
78
+ journalctl -u remoteagent --since "2 minutes ago" --no-pager
79
+ ```
80
+
81
+ ## Other Runtime Follow-up
82
+
83
+ Server 30 and server 26 are production runtime targets.
84
+ Machine 21 or any other host should be updated only when it intentionally runs a separate RemoteAgent service.
85
+
86
+ At minimum, the operator should run the install/update flow again and verify the process comes back up cleanly.
87
+ For npm installs, the package contains `dist/`, so the target machine should not need a repository checkout or a separate manual build step.