@zgeoff/imp-client 0.16.0 → 0.18.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/README.md +42 -8
- package/dist/index.d.ts +1687 -73
- package/dist/index.js +380 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -107,10 +107,40 @@ With `session: 'main'`, `openConsole` and `openExec` start that session, or atta
|
|
|
107
107
|
and the shell outlives the handle: `close()` detaches.
|
|
108
108
|
`imp.openAttach('dev', 'main', { cols, rows })` attaches to a running session; its `stdout` starts
|
|
109
109
|
with a replay of the recent output. `sessions.list` names them without waking the imp. `started`
|
|
110
|
-
resolves with `{ pid, session, created }`. When impd ends the socket while the
|
|
111
|
-
`exit` rejects with `DETACHED`, and its `data.reason` says why: `taken_over`
|
|
112
|
-
attached; one is attached at a time), `slow` (the client fell too far behind) or
|
|
113
|
-
the guest, as when the imp slept; attach again).
|
|
110
|
+
resolves with `{ pid, session, created, groupKill, output }`. When impd ends the socket while the
|
|
111
|
+
session runs on, `exit` rejects with `DETACHED`, and its `data.reason` says why: `taken_over`
|
|
112
|
+
(another client attached; one is attached at a time), `slow` (the client fell too far behind) or
|
|
113
|
+
`lost` (impd lost the guest, as when the imp slept; attach again).
|
|
114
|
+
|
|
115
|
+
### Resuming a session
|
|
116
|
+
|
|
117
|
+
`started.output` places the data in the session's output. With `continuity: 'offsets'` it has the
|
|
118
|
+
generation (`executionGeneration`, one run of the process), the `bootId`, `bufferStart` and `end`,
|
|
119
|
+
and `offset`, the offset of the first data byte after `prelude` mode bytes; `{ continuity: 'none' }`
|
|
120
|
+
means an imp whose agent predates offsets, or an older impd. `exit` resolves with `offset`, and
|
|
121
|
+
`DETACHED` has `data.offset`: the offset after the last byte received. Keep the generation and that
|
|
122
|
+
offset, and resume from them:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const tail = await imp.openAttach('dev', 'main', {
|
|
126
|
+
resumeFrom: { executionGeneration, offset },
|
|
127
|
+
wake: false,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const { output } = await tail.started;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`output.resume` says how the resume was met: `exact`; `gap`, whose bytes `[from, to)` are gone (a
|
|
134
|
+
terminal should attach again without `resumeFrom`, since the data can start inside an escape
|
|
135
|
+
sequence); or `generation_changed`, a new process, whose data starts at `firstOffset`. A resume can
|
|
136
|
+
repeat bytes you have: drop those below your high-water mark. `output.coldBoots` lists the imp's
|
|
137
|
+
last cold boots, newest first, with a `cause` (`start`, `wake_fallback`, `watchdog`, `restore`,
|
|
138
|
+
`recovery`, `unknown`); the first one after your `bootId` ended your generation. `wake: false`
|
|
139
|
+
rejects with `InvalidStateError` instead of booting or waking the imp.
|
|
140
|
+
|
|
141
|
+
A disconnected client cannot recover bytes below `bufferStart`, any byte of a generation that a cold
|
|
142
|
+
boot ended, or the output of an exec without `session`. Keep what you received if you need them.
|
|
143
|
+
`system.info()` has `features.sessionOffsets` on an impd that carries offsets.
|
|
114
144
|
|
|
115
145
|
With a tty, `sendSignal('SIGINT')` and `sendSignal('SIGQUIT')` send ^C and ^\ as keys, so they reach
|
|
116
146
|
the foreground job; other signals, and every signal without a tty, go to the process. A write after
|
|
@@ -124,9 +154,13 @@ the command did not run to its exit, `exit` rejects with an `ExecError` whose `c
|
|
|
124
154
|
in the table below, plus `EXEC_FAILED` when the command cannot start and `INNER_DOWN` when the imp's
|
|
125
155
|
container is down) or one of `UNAUTHORIZED` (also for an exec ticket that expired or was used),
|
|
126
156
|
`UNREACHABLE`, `RESTARTING`, `CONNECTION_CLOSED`, `DETACHED`, `BAD_MESSAGE`, `CLOSED`,
|
|
127
|
-
`OUTPUT_OVERFLOW` and `LOCAL_ERROR`. Its `data` is impd's error data.
|
|
128
|
-
|
|
129
|
-
`
|
|
157
|
+
`OUTPUT_OVERFLOW` and `LOCAL_ERROR`. Its `data` is impd's error data. Three codes reject as their
|
|
158
|
+
own subclasses, with typed `data`: `NoSessionError` (`NO_SESSION`:
|
|
159
|
+
`{ bootId, coldBoots, previous? }`, or no data from an agent without offsets), `InvalidStateError`
|
|
160
|
+
(`INVALID_STATE`: `{ state, allowed, coldBoots? }`) and `InvalidResumeError` (`INVALID_RESUME`:
|
|
161
|
+
`{ end, bufferStart }`, a resume past the end). An abort before the command starts, during the
|
|
162
|
+
ticket call or the connect, rejects with the abort's reason instead, an `AbortError` by default;
|
|
163
|
+
after the start it ends the session as `CLOSED`.
|
|
130
164
|
|
|
131
165
|
## Errors
|
|
132
166
|
|
|
@@ -136,7 +170,7 @@ A failed call throws an `ORPCError`. impd's errors carry a `code` and typed `dat
|
|
|
136
170
|
| --------------------- | ---------------------------------------------------- | -------------------------------------- |
|
|
137
171
|
| `NOT_FOUND` | No imp, image, checkpoint or session has that name. | `{ kind, name }` |
|
|
138
172
|
| `CONFLICT` | The name is taken. | `{ kind, name }` |
|
|
139
|
-
| `INVALID_STATE` | The imp's state does not allow the call. | `{ state, allowed }`
|
|
173
|
+
| `INVALID_STATE` | The imp's state does not allow the call. | `{ state, allowed, coldBoots? }` |
|
|
140
174
|
| `RAM_BUDGET_EXCEEDED` | The host has no room, even after sleeping idle imps. | `{ budgetMib, usedMib, requestedMib }` |
|
|
141
175
|
| `SERVICE_UNAVAILABLE` | impd is stopping. | |
|
|
142
176
|
| `FORBIDDEN` | An exec ticket was used for another imp. | |
|