@temps-sdk/cli 0.1.36 → 0.1.37

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 (3) hide show
  1. package/README.md +193 -0
  2. package/dist/index.js +99250 -87938
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,6 +16,199 @@
16
16
 
17
17
  ---
18
18
 
19
+ ## Develop and test a plugin locally
20
+
21
+ Run a compiled plugin with a simulated Temps host on macOS or Linux:
22
+
23
+ ```bash
24
+ bunx @temps-sdk/cli plugin dev ./my-plugin --session demo --grant events_read
25
+ ```
26
+
27
+ `./my-plugin` is an executable, not a directory. Open the printed loopback URL
28
+ to preview its UI. No Temps server, login, Docker, database, or provider key is
29
+ required. The CLI starts Bun automatically for these commands. Native plugins
30
+ execute with your OS permissions: this is a development host, not a sandbox.
31
+
32
+ To run source without compiling, pass an executable and arguments separately:
33
+
34
+ ```bash
35
+ bunx @temps-sdk/cli plugin dev --session demo --exec bun -- run src/index.ts
36
+ ```
37
+
38
+ In another terminal:
39
+
40
+ ```bash
41
+ bunx @temps-sdk/cli plugin dev events
42
+ bunx @temps-sdk/cli plugin dev emit deployment.succeeded --session demo \
43
+ --project-id 1 --environment-id 1 --environment production \
44
+ --deployment-id 42 --url https://example.com --json
45
+ bunx @temps-sdk/cli plugin dev status --session demo --json
46
+ bunx @temps-sdk/cli plugin dev logs --session demo --json
47
+ bunx @temps-sdk/cli plugin dev grants set --session demo --clear
48
+ ```
49
+
50
+ The plugin must subscribe to the event and declare `events_read`, and the runner
51
+ must grant it. New sessions have no grants. `grants set --grant events_read
52
+ ai_generate` replaces the complete set; `--clear` revokes everything immediately.
53
+ Manifest declarations limit effective permissions even when a grant is saved.
54
+ Use different session names to run multiple plugins. Ctrl-C stops the plugin and
55
+ its process group. Plugin data and grants persist under `~/.temps/plugin-dev/`;
56
+ `--data-dir` overrides the plugin data location. Stale session locks fail with
57
+ recovery instructions rather than risking stopping another process.
58
+
59
+ Use `emit --file event.json --repeat 2` to test duplicate delivery of the same
60
+ ID, or `--count 5` for distinct IDs. Counts are bounded at 1,000. Emission is
61
+ sequential; separate commands can deliver concurrently (maximum eight in
62
+ flight). `--transport http` exercises the authenticated fallback endpoint.
63
+ `sent` and `http_accepted` confirm transmission, **not completion of the plugin's
64
+ async handler**. Check the plugin's state to prove the resulting work completed.
65
+ There is no implicit event replay. Custom event envelopes are supported with
66
+ `--file`; listing a custom type does not mean the production host emits it.
67
+
68
+ For mock AI, supply `--fixtures fixtures.json` and explicitly grant `ai_generate`:
69
+
70
+ ```json
71
+ {
72
+ "version": 1,
73
+ "ai": {
74
+ "mode": "success",
75
+ "text": "Local mock response",
76
+ "dailyCallLimit": 3,
77
+ "concurrency": 1,
78
+ "delayMs": 100,
79
+ "maxOutputTokens": 1024
80
+ }
81
+ }
82
+ ```
83
+
84
+ AI modes are `unconfigured` (default), `success`, `error`, and `timeout`. Timeout
85
+ mode returns a simulated provider-timeout error after `delayMs`; it does not
86
+ wait for a real provider. Quota counters reset when the runner restarts; they do
87
+ not emulate production database persistence or a full calendar-day rollover.
88
+ The fixture file can also supply `projects`, `environments`, and `deployments`
89
+ arrays matching the SDK DTOs; IDs and references are validated. Default fixtures
90
+ contain project 1, production environment 1, and deployment 42. Host API calls
91
+ outside discovery, these read methods, and mock AI return explicit unsupported
92
+ errors; no request is forwarded to a real Temps instance.
93
+
94
+ `--role admin|reader` changes the synthetic preview user, independently of plugin
95
+ grants. Browser cookies are intentionally isolated from the plugin; plugins
96
+ requiring cookie authentication need full-instance testing. Preview writes need
97
+ the local session cookie (open `/` first) and a same-origin Origin header.
98
+ Control/event endpoints are available only through the private local socket.
99
+ Payloads are bounded to 1 MiB, logs to 200 records, and host calls to 32 in flight.
100
+
101
+ A runnable deployment-journal example and mock AI fixtures live in
102
+ [`examples/plugin-dev.ts`](examples/plugin-dev.ts) and
103
+ [`examples/plugin-dev-fixtures.json`](examples/plugin-dev-fixtures.json).
104
+ From this repository's `apps/temps-cli` directory, run the development CLI with
105
+ `bun run src/index.ts` in place of `bunx @temps-sdk/cli` before the feature is
106
+ released. Compile the example with:
107
+
108
+ ```bash
109
+ bun build --compile examples/plugin-dev.ts --outfile /tmp/temps-example-plugin
110
+ ```
111
+
112
+ The example uses the repository SDK source, stores unique events across
113
+ restarts, previews its event journal, and can call mock AI. A small Rust
114
+ conformance example lives at `crates/temps-plugin-sdk/examples/plugin-dev-probe.rs`.
115
+ Run `bun run build` followed by `bun run scripts/test-plugin-dev-package.ts`
116
+ to repeat the packed-CLI end-to-end test. Simulator verification does not replace
117
+ installation testing against Temps.
118
+
119
+ ## SSH setup proof of concept
120
+
121
+ From this checkout, install dependencies with `bun install` in `apps/temps-cli`.
122
+ Preview the plan before installing on an existing Linux VPS:
123
+
124
+ ```bash
125
+ bun run src/index.ts setup --ssh root@server.example --email admin@example.com --dry-run
126
+ bun run src/index.ts setup --ssh root@server.example --email admin@example.com --context production --yes
127
+ ```
128
+
129
+ The target must have key-based SSH access, an already verified host key in your
130
+ SSH configuration, root or passwordless sudo, and `curl`, `flock`, and `cksum` installed.
131
+ The PoC supports Linux x86_64/ARM64 and public QuickStart networking (ports 80/443).
132
+ `--identity`, `--port`, `--channel`, and `--runtime-version` are supported.
133
+
134
+ Setup downloads the existing HTTPS installer at `https://temps.sh/deploy.sh`;
135
+ `--runtime-version` pins the runtime, not the installer script. It does not create
136
+ a VPS or enroll a worker. It rejects unrecognized existing installations and
137
+ checks common port conflicts. The installer owns dependency setup and its own
138
+ durable wizard state. A remote lock prevents overlapping CLI setups. Repeating
139
+ the command inspects `/root/.temps/setup-result.json` without modifying the server
140
+ and checks context-name conflicts before installation. Valid matching results are
141
+ reused after HTTPS and API-key verification. Incomplete CLI results are backed up
142
+ and the installer resumes its wizard state. The requested release selection is
143
+ recorded before installation; retries with another channel or version fail clearly.
144
+ Setup is not an upgrade command. Legacy results must identify QuickStart and the
145
+ same channel; legacy pins or unidentifiable state require server inspection.
146
+ Rejected API keys or broken DNS/TLS still require operator repair.
147
+
148
+ The selected context is not switched when another context already exists. A
149
+ different server cannot overwrite a context with the same name. If an existing
150
+ context cannot be matched to a valid remote result, choose another context name
151
+ before recovery. Refreshes preserve the default project and active selection;
152
+ key metadata is retained for unchanged keys and cleared when the key changes. Deploy local
153
+ source using the existing command:
154
+
155
+ ```bash
156
+ temps --target-context production drop .
157
+ ```
158
+
159
+ Installer output can contain credentials and is retained **only on the remote
160
+ server**, in `/root/.temps/cli-setup.log` with mode 0600. The result file also
161
+ contains credentials. Neither is printed or sent to analytics. The CLI imports
162
+ the installer-created API key into its existing protected context store; it
163
+ does not import the admin password. A future production implementation should
164
+ mint a dedicated scoped client credential and pin the installer artifact.
165
+
166
+ CLI analytics are off unless `--telemetry` is explicitly supplied for that
167
+ attempt. `--no-telemetry` disables them. The sender batches `cli_setup_step` events
168
+ to the existing telemetry API with a random per-attempt UUID and only step,
169
+ status, elapsed-time bucket, method, and CLI version. It sends no host, email,
170
+ path, key, logs, or raw error. This does not measure retention or link setup to
171
+ runtime activity; runtime telemetry is disabled on new installs in this PoC.
172
+ Retries that reuse a completed installation do not change its telemetry setting.
173
+ The collector changes in this branch must be deployed before those events are
174
+ accepted. Analytics delivery has a two-second timeout and cannot fail setup;
175
+ abrupt process termination can lose the in-memory batch. Receiver/proxy IP-log
176
+ retention must be reviewed before promising strict anonymity.
177
+
178
+ Local checks use fixture installers and mocked APIs; a fresh VPS installation,
179
+ an interrupted real install, certificate issuance, and a first app deployment
180
+ remain the end-to-end release gate. No cloud resources are needed for the tests:
181
+
182
+ ```bash
183
+ bun test src/commands/setup
184
+ bun run typecheck
185
+ bun run build
186
+ ```
187
+
188
+ ## TypeScript plugin publishing
189
+
190
+ Run plugin commands with Bun: `bunx --bun @temps-sdk/cli plugin init`,
191
+ `plugin build --all`, and `plugin publish`. Bun compiles the native platform
192
+ packages; `npm publish` handles npm's interactive browser/2FA approval, with
193
+ lifecycle scripts disabled. Do not substitute a bypass token.
194
+
195
+ Publication keeps a private, mode-0600 journal in `.temps-plugin/`. Preserve it
196
+ until publication completes; do not commit or share it. Before the first remote
197
+ create, the CLI durably records a metadata digest and random 256-bit recovery
198
+ token. The publisher API must accept `recoveryToken` and replay the same draft,
199
+ expiry, package IDs, and verification codes for that account and exact metadata.
200
+ Different tokens or metadata must fail for an existing release, and another
201
+ account must never retrieve its challenges. Deploy the companion API before
202
+ releasing this CLI; do not retry an older API with the token removed.
203
+
204
+ State writes use Bun file I/O through exclusively opened descriptors, then
205
+ fsync, atomic rename, and directory fsync. Invalid state or mismatched responses
206
+ stop publication instead of creating another draft. Existing valid
207
+ `release.json` files resume without a create call. Orphaned drafts without a
208
+ recovery journal require maintainer assistance or a new version. Publication to
209
+ npm is separate from protected registry signing; check the publisher dashboard
210
+ for catalog publication status.
211
+
19
212
  ```bash
20
213
  # npm
21
214
  npm install -g @temps-sdk/cli