@agentshouse/kit 0.1.0-alpha.10 → 0.1.0-alpha.11

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 CHANGED
@@ -10,7 +10,7 @@ On Linux `amd64` or `arm64` with a working Docker Engine, run the published,
10
10
  versioned bootstrap once:
11
11
 
12
12
  ```sh
13
- bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.10/connect-linux.sh)
13
+ bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.11/connect-linux.sh)
14
14
  ```
15
15
 
16
16
  The release asset pins one immutable multi-architecture image digest. It creates
@@ -1130,10 +1130,9 @@ retained references still waiting to be saved.
1130
1130
  Every command that changes or reads installation state takes this
1131
1131
  installation's exclusive Environment control lease for the length of its run
1132
1132
  and renews it before it expires, so two Kit commands never work against the
1133
- same installation at once. A command that ends, or is interrupted once its work
1134
- has stopped, releases that exact lease so the next command acquires at once; a
1135
- refused command leaves it to expire. A `kit login` credential is presented only to take
1136
- that lease.
1133
+ same installation at once. A command that ends, is refused, or is interrupted
1134
+ once its work has stopped releases that exact lease so the next command acquires
1135
+ at once. A `kit login` credential is presented only to take that lease.
1137
1136
 
1138
1137
  While `kit resident` holds that lease, a command runs through it instead: the
1139
1138
  command presents no credential, the resident confirms its current lease with
package/bootstrap.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "schemaVersion": 1,
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.11",
4
4
  "hosts": {
5
5
  "linux": {
6
- "command": "bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.10/connect-linux.sh)",
6
+ "command": "bash <(curl -fsSL https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.11/connect-linux.sh)",
7
7
  "asset": {
8
8
  "name": "connect-linux.sh",
9
- "url": "https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.10/connect-linux.sh"
9
+ "url": "https://github.com/agentshouse/kit/releases/download/v0.1.0-alpha.11/connect-linux.sh"
10
10
  },
11
11
  "workspace": {
12
12
  "argument": "--workspace",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/kit",
3
- "version": "0.1.0-alpha.10",
3
+ "version": "0.1.0-alpha.11",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/src/host.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readFile, statfs } from "node:fs/promises";
2
2
  import { readConfiguration } from "./configuration.js";
3
3
  import { HOST_CPU_SAMPLE_MS } from "./contract.js";
4
- import { openSession, reportHostCapacity } from "./house.js";
4
+ import { maintainControl, openSession, reportHostCapacity } from "./house.js";
5
5
  import { KitRefusal } from "./refusal.js";
6
6
 
7
7
  const PROC_STAT = "/proc/stat";
@@ -116,6 +116,10 @@ export async function reportHost(options, dependencies = {}) {
116
116
  ? observed
117
117
  : { ...observed, maxima: declaredMaxima(configuration.host.maxima) };
118
118
  const session = await openSession(options, dependencies);
119
- await reportHostCapacity(session, declaration);
119
+ await maintainControl(
120
+ session,
121
+ (signal) => reportHostCapacity(session, declaration, signal),
122
+ options.signal,
123
+ );
120
124
  return declaration;
121
125
  }
package/src/house.js CHANGED
@@ -438,20 +438,14 @@ export async function maintainControl(session, operation, signal, { release = tr
438
438
  }
439
439
  })();
440
440
  const running = Promise.resolve().then(() => operation(operationSignal));
441
- let ended = false;
442
441
  try {
443
- const answer = await Promise.race([running, failure, cancellation]);
444
- ended = true;
445
- return answer;
446
- } catch (error) {
447
- ended = error instanceof KitRefusal && error.code === "kit_command_cancelled";
448
- throw error;
442
+ return await Promise.race([running, failure, cancellation]);
449
443
  } finally {
450
444
  stopped = true;
451
445
  maintenance.abort();
452
446
  signal?.removeEventListener("abort", cancelOperation);
453
447
  await Promise.all([renewal, running.catch(() => undefined)]);
454
- if (ended && release) await releaseControl(session);
448
+ if (release) await releaseControl(session);
455
449
  }
456
450
  }
457
451
 
package/src/source.js CHANGED
@@ -204,18 +204,24 @@ export async function captureSource(options, dependencies = {}) {
204
204
  const googleOAuthClient =
205
205
  instance.preset === "google" ? dependencies.googleOAuthClient() : null;
206
206
  const session = await openSession(options, dependencies);
207
- const context = {
208
- instance,
207
+ return maintainControl(
209
208
  session,
210
- directory: options.directory,
211
- signal: options.signal,
212
- now: session.now,
213
- dependencies,
214
- googleOAuthClient,
215
- };
216
- const delivered = [];
217
- for (const service of services) delivered.push(await deliverService(context, service));
218
- return { instance: instance.id, services: delivered };
209
+ async (signal) => {
210
+ const context = {
211
+ instance,
212
+ session,
213
+ directory: options.directory,
214
+ signal,
215
+ now: session.now,
216
+ dependencies,
217
+ googleOAuthClient,
218
+ };
219
+ const delivered = [];
220
+ for (const service of services) delivered.push(await deliverService(context, service));
221
+ return { instance: instance.id, services: delivered };
222
+ },
223
+ options.signal,
224
+ );
219
225
  }
220
226
 
221
227
  export async function sourceStatus(options) {
@@ -255,23 +261,27 @@ export async function retrySourceOriginals(options, dependencies = {}) {
255
261
  const configuration = await readConfiguration(options.configuration);
256
262
  const instance = sourceInstance(configuration, options.instance);
257
263
  const services = declaredServices(instance, options.service ?? null);
258
- const context = { instance, directory: options.directory, signal: options.signal };
259
264
  const outstanding = [];
260
265
  for (const service of services) {
261
266
  outstanding.push((await readSourceOriginals(options.directory, instance.id, service.service)).length);
262
267
  }
263
- if (outstanding.some((count) => count > 0)) context.session = await openSession(options, dependencies);
264
- const retried = [];
265
- for (const [position, service] of services.entries()) {
266
- retried.push({
267
- service: service.service,
268
- originals:
269
- outstanding[position] === 0
270
- ? []
271
- : await saveSourceOriginals(context, serviceBinding(context, service)),
272
- });
273
- }
274
- return { instance: instance.id, services: retried };
268
+ const retry = async (context) => {
269
+ const retried = [];
270
+ for (const [position, service] of services.entries()) {
271
+ retried.push({
272
+ service: service.service,
273
+ originals:
274
+ outstanding[position] === 0
275
+ ? []
276
+ : await saveSourceOriginals(context, serviceBinding(context, service)),
277
+ });
278
+ }
279
+ return { instance: instance.id, services: retried };
280
+ };
281
+ const context = { instance, directory: options.directory, signal: options.signal };
282
+ if (outstanding.every((count) => count === 0)) return retry(context);
283
+ const session = await openSession(options, dependencies);
284
+ return maintainControl(session, (signal) => retry({ ...context, session, signal }), options.signal);
275
285
  }
276
286
 
277
287
  export async function resetSource(options, dependencies = {}) {