@lapxo/head 0.1.0 → 0.1.3
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/TARGET.bound +392 -49
- package/dist/src/access/contract.d.ts +2 -0
- package/dist/src/access/obtain.js +2 -2
- package/dist/src/adopt/adopt.js +5 -2
- package/dist/src/compile/pin.js +5 -5
- package/dist/src/core/act.d.ts +1 -0
- package/dist/src/core/act.js +1 -0
- package/dist/src/core/answer.d.ts +16 -4
- package/dist/src/core/answer.js +7 -4
- package/dist/src/core/lock.d.ts +2 -0
- package/dist/src/core/lock.js +2 -0
- package/dist/src/core/package.d.ts +54 -0
- package/dist/src/core/package.js +65 -0
- package/dist/src/core/read.d.ts +3 -0
- package/dist/src/core/read.js +8 -4
- package/dist/src/core/surface.d.ts +1 -40
- package/dist/src/core/surface.js +4 -29
- package/dist/src/core/trust.d.ts +7 -0
- package/dist/src/core/trust.js +19 -0
- package/dist/src/flows/device.js +1 -6
- package/dist/src/flows/read.js +18 -8
- package/dist/src/flows/world.js +3 -3
- package/dist/src/index.js +37 -18
- package/dist/src/onboard/first.d.ts +7 -0
- package/dist/src/onboard/first.js +21 -0
- package/dist/src/places/admit.js +1 -1
- package/dist/src/places/found.d.ts +1 -0
- package/dist/src/places/found.js +8 -7
- package/dist/src/ports/access/authorizer.d.ts +10 -0
- package/dist/src/ports/access/authorizer.js +34 -0
- package/dist/src/ports/access/flow.js +13 -3
- package/dist/src/ports/access/person.d.ts +3 -2
- package/dist/src/ports/access/person.js +12 -5
- package/dist/src/ports/adapters/request.d.ts +3 -0
- package/dist/src/ports/adapters/request.js +5 -3
- package/dist/src/ports/bound.d.ts +12 -2
- package/dist/src/ports/bound.js +30 -13
- package/dist/src/ports/documents.d.ts +34 -0
- package/dist/src/ports/documents.js +64 -0
- package/dist/src/ports/keychain.d.ts +2 -1
- package/dist/src/ports/keychain.js +3 -2
- package/dist/src/ports/place.d.ts +1 -0
- package/dist/src/ports/place.js +7 -1
- package/dist/src/ports/process.d.ts +9 -0
- package/dist/src/ports/process.js +5 -3
- package/dist/src/ports/spare.d.ts +1 -0
- package/dist/src/ports/spare.js +33 -0
- package/dist/src/ports/surface.d.ts +126 -0
- package/dist/src/ports/surface.js +48 -0
- package/dist/src/ports/warm.d.ts +19 -0
- package/dist/src/ports/warm.js +46 -0
- package/dist/src/signer.js +1 -1
- package/dist/src/sources/access.d.ts +10 -1
- package/dist/src/sources/access.js +15 -10
- package/dist/src/sources/connect.d.ts +5 -2
- package/dist/src/sources/connect.js +98 -36
- package/dist/src/tools/card.js +1 -1
- package/dist/src/tools/look.d.ts +2 -2
- package/dist/src/tools/look.js +4 -3
- package/dist/src/tools/places.d.ts +7 -0
- package/dist/src/tools/places.js +32 -0
- package/dist/src/tools/share.d.ts +1 -0
- package/dist/src/tools/share.js +1 -0
- package/package.json +6 -5
- /package/dist/src/{core → ports}/keys.d.ts +0 -0
- /package/dist/src/{core → ports}/keys.js +0 -0
package/dist/src/ports/bound.js
CHANGED
|
@@ -4,6 +4,7 @@ import { tmpdir } from 'node:os';
|
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
5
5
|
import { parse } from '@lapxo/topos/wire';
|
|
6
6
|
import { spawned } from "./process.js";
|
|
7
|
+
import { cooled, kept, warmed } from "./warm.js";
|
|
7
8
|
const binOf = (name) => {
|
|
8
9
|
try {
|
|
9
10
|
const manifest = createRequire(import.meta.url).resolve(join(name, 'package.json'));
|
|
@@ -15,24 +16,38 @@ const binOf = (name) => {
|
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
export const limits = { wait: 0, most: 0 };
|
|
18
|
-
/** bound run as a process in a folder, beside head and never blocking it, within the wait and the bytes head's lock gives it and stopped when the asker cancels. */
|
|
19
|
-
export const run = async (name, cwd, args, env = {}, signal) => ((bin) => (bin === undefined ? undefined
|
|
20
|
-
: spawned(process.execPath, [bin, ...args], { cwd, env: { ...process.env, ...env } }, { wait: limits.wait, most: limits.most || Number.MAX_SAFE_INTEGER, ...(signal ? { signal } : {}) })
|
|
19
|
+
/** bound run as a process in a folder, beside head and never blocking it, within the wait and the bytes head's lock gives it and stopped when the asker cancels: one started ahead when head holds one, else one started now. */
|
|
20
|
+
export const run = async (name, cwd, args, env = {}, signal) => ((bin, at, bounds) => (bin === undefined ? undefined
|
|
21
|
+
: (warmed(bin, args, at, bounds) ?? spawned(process.execPath, [bin, ...args], at, bounds)).then(apart)))(binOf(name), { cwd, env: { ...process.env, ...env } }, { wait: limits.wait, most: limits.most || Number.MAX_SAFE_INTEGER, ...(signal ? { signal } : {}) });
|
|
22
|
+
/** The record bound prints after a refusal's diagnostic, read apart from it: what bound printed is kept whole, the record beside it, and why bound refused is the diagnostic's last line, never the record. */
|
|
23
|
+
const recordOf = (line) => { try {
|
|
24
|
+
return ((got) => (got?.profile === words.refusal ? got : undefined))(JSON.parse(line));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
} };
|
|
29
|
+
const isRecord = (line) => line.startsWith('{') && recordOf(line) !== undefined;
|
|
30
|
+
const apart = (printed) => ((record) => (record === undefined ? printed : { ...printed, refusal: recordOf(record) }))([...printed.err].reverse().find(isRecord));
|
|
31
|
+
const why = (printed) => printed?.err.filter((line) => !isRecord(line)).at(-1);
|
|
32
|
+
/** bound started ahead of the first ask of a call, as many times as head's lock keeps it started; resolved once each is ready. */
|
|
33
|
+
export const warm = (name) => ((bin) => (bin === undefined ? Promise.resolve() : kept(bin)))(binOf(name));
|
|
34
|
+
export { cooled };
|
|
21
35
|
const facts = (out) => out.flatMap((line) => ((got) => (got.kind === 'fact' ? [got.value.fields] : []))(parse(line)));
|
|
22
|
-
const readOf = (printed) => (printed === undefined || printed.code !== 0 ? { refused: printed
|
|
36
|
+
const readOf = (printed) => (printed === undefined || printed.code !== 0 ? { refused: why(printed) ?? '' } : { lines: facts(printed.out) });
|
|
23
37
|
/**
|
|
24
|
-
* The lines a place stands on, from bound's public views alone: its folded normative standing (the lines view)
|
|
38
|
+
* The lines a place stands on, from bound's public views alone: its folded normative standing (the lines view) — its
|
|
39
|
+
* policy, all that a reader of its pins, keys and views needs, read alone where nothing else is — and from
|
|
25
40
|
* its authenticated evidence what this device's own keys signed. Receipts are history, each kept as it was made; any other
|
|
26
41
|
* line of a device key, the person's own attestation, stands only while it is the one line of its scope and measure,
|
|
27
42
|
* unwithdrawn and beside no line of the place's own: anything else needs a fold bound does not publish, and is refused by
|
|
28
43
|
* name. A place whose land prints no act result is refused before anything lands in it. Any refusal of bound is no standing.
|
|
29
44
|
*/
|
|
45
|
+
export const policyAt = async (name, place, signal) => ((folded) => ('refused' in folded || folded.lines.some((line) => line.scope === words.profile) ? folded
|
|
46
|
+
: { refused: `REFUSE·act the place declares no ${words.profile}: land would print nothing of what it admits, so head lands nothing there; its root can land the local-act@1 profile and view/act` }))(readOf(await run(name, place, [words.read, words.view, words.standing], {}, signal)));
|
|
30
47
|
export const standingAt = async (name, place, devicesOf, isHistory, signal) => {
|
|
31
|
-
const folded =
|
|
48
|
+
const folded = await policyAt(name, place, signal);
|
|
32
49
|
if ('refused' in folded)
|
|
33
50
|
return folded;
|
|
34
|
-
if (!folded.lines.some((line) => line.scope === words.profile))
|
|
35
|
-
return { refused: `REFUSE·act the place declares no ${words.profile}: land would print nothing of what it admits, so head lands nothing there; its root can land the local-act@1 profile and view/act` };
|
|
36
51
|
const evidence = readOf(await run(name, place, [words.read, words.view, words.evidence], {}, signal));
|
|
37
52
|
if ('refused' in evidence)
|
|
38
53
|
return evidence;
|
|
@@ -43,16 +58,18 @@ export const standingAt = async (name, place, devicesOf, isHistory, signal) => {
|
|
|
43
58
|
: { refused: `REFUSE·standing ${unfolded.by} attests ${key(unfolded)} more than once, withdrawn, or beside the place's own line: folding a device key's lines is bound's, and bound publishes no view of it` };
|
|
44
59
|
};
|
|
45
60
|
const lotFile = (lines) => ((at) => { writeFileSync(at, `${lines.join('\n')}\n`); return at; })(join(mkdtempSync(join(tmpdir(), 'head-lot-')), 'lot.bound'));
|
|
46
|
-
export const sign = async (name, place, lot, key, signer, env, signal) => ((got) => (got !== undefined && got.code === 0 ? { lines: got.out.filter((line) => parse(line).kind === 'fact') } : { refused: got
|
|
61
|
+
export const sign = async (name, place, lot, key, signer, env, signal) => ((got) => (got !== undefined && got.code === 0 ? { lines: got.out.filter((line) => parse(line).kind === 'fact') } : { refused: why(got) ?? '' }))(await run(name, place, [words.sign, lotFile(lot), words.key, key, words.signer, signer], env, signal));
|
|
47
62
|
/** A lot signed and landed in one process, its result read from what bound printed of the committed act: the records it admitted, never the receipt beside them; a place that declares no act result is refused by name. */
|
|
63
|
+
/** A place's receipts rendered beside its lock, so bound alone checks the place: nothing when they closed, else why they did not. */
|
|
64
|
+
export const closing = async (name, place, signal) => ((got) => (got !== undefined && got.code === 0 ? undefined : why(got) ?? 'nothing printed'))(await run(name, place, [words.read, words.view, words.receipts], {}, signal));
|
|
48
65
|
export const landAct = async (name, place, lot, key, signer, env, signal) => ((got) => {
|
|
49
66
|
if (got === undefined || got.code !== 0)
|
|
50
|
-
return { refused: got
|
|
67
|
+
return { refused: why(got) ?? '' };
|
|
51
68
|
const at = got.out.findIndex((line) => line.startsWith(words.act));
|
|
52
69
|
return at < 0 ? { refused: `REFUSE·act bound printed no act result, and the place declares ${words.profile}: what was admitted is bound's to say` }
|
|
53
70
|
: { lines: got.out.slice(at + 1).filter((line) => parse(line).kind === 'fact').slice(0, -1) };
|
|
54
71
|
})(await run(name, place, [words.land, lotFile(lot), words.key, key, words.signer, signer], env, signal));
|
|
55
|
-
export const land = async (name, place, signed, signal) => ((got) => (got !== undefined && got.code === 0 ? { lines: signed } : { refused: got
|
|
72
|
+
export const land = async (name, place, signed, signal) => ((got) => (got !== undefined && got.code === 0 ? { lines: signed } : { refused: why(got) ?? '' }))(await run(name, place, [words.land, lotFile(signed)], {}, signal));
|
|
56
73
|
export const told = async (name, place, signed, view, signal) => ((got) => [...(got?.out ?? []), ...(got?.err ?? [])])(await run(name, place, [words.read, words.view, view, lotFile(signed)], {}, signal));
|
|
57
74
|
export const pinnedAt = async (name, place, file, signal) => {
|
|
58
75
|
const printed = await run(name, place, [words.read, file], {}, signal);
|
|
@@ -63,6 +80,6 @@ export const pinnedAt = async (name, place, file, signal) => {
|
|
|
63
80
|
const bytes = printed.out.filter((line) => line.startsWith(words.topos)).map((line) => `${line.slice(words.topos.length)}\n`).join('');
|
|
64
81
|
return pin === undefined || !bytes ? undefined : { pin, bytes, lines: read.lines };
|
|
65
82
|
};
|
|
66
|
-
export const founded = async (name, place, key, signer, env, signal) => ((got) => (got !== undefined && got.code === 0 ? { lines: got.out } : { refused: got
|
|
67
|
-
export const words = { read: '', view: '', sign: '', land: '', key: '', signer: '', pin: '', topos: '', standing: '', evidence: '', act: '', profile: '' };
|
|
83
|
+
export const founded = async (name, place, key, signer, env, signal) => ((got) => (got !== undefined && got.code === 0 ? { lines: got.out } : { refused: why(got) ?? '' }))(await run(name, place, [words.land, words.key, key, words.signer, signer], env, signal));
|
|
84
|
+
export const words = { read: '', view: '', sign: '', land: '', key: '', signer: '', pin: '', topos: '', standing: '', evidence: '', act: '', profile: '', receipts: '', refusal: '' };
|
|
68
85
|
export const settledView = async (name, place, view, signal) => readOf(await run(name, place, [words.read, words.view, view], {}, signal));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Attachment } from '../access/contract.ts';
|
|
2
|
+
import type { Context } from '../core/answer.ts';
|
|
3
|
+
import type { Said } from '../core/lock.ts';
|
|
4
|
+
import type { Call } from '../core/read.ts';
|
|
5
|
+
export type Read = {
|
|
6
|
+
readonly bytes: Uint8Array;
|
|
7
|
+
readonly kind: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const kindOf: (at: string, type?: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* A document the person names: a file inside the place or a folder the client shares, or an encrypted address read with
|
|
12
|
+
* nothing attached — signed or expiring as it may be — and, when its digest is named, followed wherever it moves to the
|
|
13
|
+
* bytes that digest names, and only to them. Anything else is not read. Its kind is named, never read for: its file's
|
|
14
|
+
* extension, its address's, or the media type it was served as; bytes that say none are octet-stream.
|
|
15
|
+
*/
|
|
16
|
+
export declare const documentOf: (context: Context, place: string, at: string, named?: string) => Promise<Read | undefined>;
|
|
17
|
+
/** A document read with the access a source the place connected holds: sent to that source's own origin alone, never redirected with it; a move is followed with nothing attached, only to the bytes its named digest names. */
|
|
18
|
+
export declare const fetchedAs: (context: Context, at: string, via: string, got: {
|
|
19
|
+
readonly plan: Call;
|
|
20
|
+
readonly attachment: Attachment | undefined;
|
|
21
|
+
}, named: string, accept: string | undefined) => Promise<Read | {
|
|
22
|
+
readonly said: readonly string[];
|
|
23
|
+
}>;
|
|
24
|
+
/**
|
|
25
|
+
* Every byte a package's lines name, by the path each names: read where a line of the same scope says — an encrypted
|
|
26
|
+
* address, signed or expiring, read with nothing attached and only to the bytes its digest names — or else beside the
|
|
27
|
+
* package's lock, in its folder or at its address. A path outside the package is never read. And what a place laid
|
|
28
|
+
* for a source it connected — its document and the overlay beside it — by the path the place keeps them at. And where
|
|
29
|
+
* an origin says its documents are: the catalog it publishes at its well-known address (RFC 9727), then the paths head's
|
|
30
|
+
* lock names, each once.
|
|
31
|
+
*/
|
|
32
|
+
export declare const besideOf: (context: Context, document: string, lines: readonly Said[]) => Promise<ReadonlyMap<string, Uint8Array | undefined>>;
|
|
33
|
+
export declare const describedAt: (context: Context, origin: string) => Promise<readonly string[]>;
|
|
34
|
+
export declare const laidOf: (context: Context, place: string, source: string) => readonly (readonly [string, Uint8Array])[];
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { dirname, extname, join } from 'node:path';
|
|
2
|
+
import { within } from "../core/answer.js";
|
|
3
|
+
import { members, valueOf } from "../core/lock.js";
|
|
4
|
+
import { sayIn } from "../core/surface.js";
|
|
5
|
+
const limits = (context) => ['adapter/request/wait', 'adapter/request/document-bytes'].map((k) => Number(valueOf(context.lock, k).split('..')[1]));
|
|
6
|
+
export const kindOf = (at, type = '') => (extname(URL.canParse(at) ? new URL(at).pathname : at).slice(1)
|
|
7
|
+
|| (type.split(';')[0].split('/')[1] ?? '').split('+').at(-1).replace(/^x-/, '') || 'octet-stream').toLowerCase();
|
|
8
|
+
/**
|
|
9
|
+
* A document the person names: a file inside the place or a folder the client shares, or an encrypted address read with
|
|
10
|
+
* nothing attached — signed or expiring as it may be — and, when its digest is named, followed wherever it moves to the
|
|
11
|
+
* bytes that digest names, and only to them. Anything else is not read. Its kind is named, never read for: its file's
|
|
12
|
+
* extension, its address's, or the media type it was served as; bytes that say none are octet-stream.
|
|
13
|
+
*/
|
|
14
|
+
export const documentOf = async (context, place, at, named = '') => {
|
|
15
|
+
const [wait, most] = limits(context), transport = URL.canParse(at) ? await context.adapter(at) : undefined;
|
|
16
|
+
if (URL.canParse(at))
|
|
17
|
+
return named ? ((bytes) => bytes && { bytes, kind: kindOf(at) })(await transport?.published(at, named, most, wait)) : ((got) => got && { bytes: got.bytes, kind: kindOf(at, got.type) })(await transport?.get(at, wait));
|
|
18
|
+
return ((bytes) => bytes && { bytes, kind: kindOf(at) })((await within(context, place, at)) ? context.files.take(at) : undefined);
|
|
19
|
+
};
|
|
20
|
+
/** A document read with the access a source the place connected holds: sent to that source's own origin alone, never redirected with it; a move is followed with nothing attached, only to the bytes its named digest names. */
|
|
21
|
+
export const fetchedAs = async (context, at, via, got, named, accept) => {
|
|
22
|
+
const [say, [wait, most]] = [sayIn(context.lock), limits(context)];
|
|
23
|
+
if (!URL.canParse(at))
|
|
24
|
+
return { said: [say('document-unread', { document: at })] };
|
|
25
|
+
if (new URL(at).origin !== new URL(got.plan.origin).origin)
|
|
26
|
+
return { said: [say('fetch-cross-origin', { document: at, via })] };
|
|
27
|
+
const transport = await context.adapter(at), answer = transport ? await transport.fetched(at, got.attachment, accept, most, wait) : undefined;
|
|
28
|
+
if (answer?.kind !== 'got')
|
|
29
|
+
return { said: [say('document-unread', { document: at })] };
|
|
30
|
+
if (answer.status >= 300 && answer.status < 400 && answer.location !== undefined) {
|
|
31
|
+
if (!named)
|
|
32
|
+
return { said: [say('fetch-redirect', { document: at })] };
|
|
33
|
+
return ((bytes) => (bytes ? { bytes, kind: kindOf(at) } : { said: [say('document-unread', { document: at })] }))(await transport.published(new URL(answer.location, at).href, named, most, wait));
|
|
34
|
+
}
|
|
35
|
+
return answer.status < 300 ? { bytes: answer.bytes, kind: kindOf(at, answer.type) } : { said: [say('fetch-status', { document: at, via, status: String(answer.status) })] };
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Every byte a package's lines name, by the path each names: read where a line of the same scope says — an encrypted
|
|
39
|
+
* address, signed or expiring, read with nothing attached and only to the bytes its digest names — or else beside the
|
|
40
|
+
* package's lock, in its folder or at its address. A path outside the package is never read. And what a place laid
|
|
41
|
+
* for a source it connected — its document and the overlay beside it — by the path the place keeps them at. And where
|
|
42
|
+
* an origin says its documents are: the catalog it publishes at its well-known address (RFC 9727), then the paths head's
|
|
43
|
+
* lock names, each once.
|
|
44
|
+
*/
|
|
45
|
+
export const besideOf = async (context, document, lines) => {
|
|
46
|
+
const [wait, most] = limits(context), read = new Map();
|
|
47
|
+
for (const l of lines.filter((one) => one.needs && one.measure === 'digest' && !one.needs.split('/').includes('..') && !one.needs.startsWith('/'))) {
|
|
48
|
+
const at = lines.find((o) => o.scope === l.scope && o.measure === 'id')?.value ?? (URL.canParse(document) ? new URL(l.needs, document).href : join(dirname(document), l.needs));
|
|
49
|
+
read.set(l.needs, URL.canParse(at) ? await (await context.adapter(at))?.published(at, l.value ?? '', most, wait) : context.files.take(at));
|
|
50
|
+
}
|
|
51
|
+
return read;
|
|
52
|
+
};
|
|
53
|
+
export const describedAt = async (context, origin) => {
|
|
54
|
+
const [wait] = limits(context), catalog = await (await context.adapter(origin))?.get(new URL(valueOf(context.lock, 'use/catalog'), origin).href, wait), rel = valueOf(context.lock, 'use/catalog-rel');
|
|
55
|
+
const listed = (() => { try {
|
|
56
|
+
return JSON.parse(new TextDecoder().decode(catalog?.bytes ?? new Uint8Array())).linkset?.flatMap((l) => (l[rel] ?? []).flatMap((d) => d.href ?? [])) ?? [];
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return [];
|
|
60
|
+
} })();
|
|
61
|
+
return [...new Set([...listed, ...members(valueOf(context.lock, 'use/documents'))].flatMap((at) => (URL.canParse(at, origin) ? [new URL(at, origin).href] : [])))];
|
|
62
|
+
};
|
|
63
|
+
export const laidOf = (context, place, source) => ((at) => context.files.list(place, at).filter((f) => new RegExp(`^${source}\\.(overlay\\.)?[^.]+$`).test(f))
|
|
64
|
+
.map((f) => [`${at}/${f}`, context.files.take(join(place, at, f)) ?? new Uint8Array()]))(valueOf(context.lock, 'place/connected'));
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export interface KeyStore {
|
|
2
2
|
readonly read: (account: string) => string | undefined;
|
|
3
3
|
readonly write: (account: string, secret: string) => void;
|
|
4
|
+
readonly made?: (account: string) => string | undefined;
|
|
4
5
|
}
|
|
5
6
|
export declare const plain: (word: string) => string;
|
|
6
|
-
/** The secret store this host keeps head's keys in, by the name its lock gives the platform's: one adapter each, every secret crossing a command's stdin and stdout only. */
|
|
7
|
+
/** The secret store this host keeps head's keys in, by the name its lock gives the platform's: one adapter each, every secret crossing a command's stdin and stdout only; a key it is asked for by its account is made there once, and only its public half handed on. */
|
|
7
8
|
export declare const keychain: (service: string, kind: string) => KeyStore;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { store as credentialManager } from "./stores/credential-manager.js";
|
|
2
2
|
import { store as keychainOfMac } from "./stores/keychain.js";
|
|
3
3
|
import { store as secretTool } from "./stores/secret-tool.js";
|
|
4
|
+
import { newKey, publicOf } from "./keys.js";
|
|
4
5
|
export const plain = (word) => { if (!/^[\w.@/+=-]+$/.test(word))
|
|
5
6
|
throw Error('REFUSE·keychain a name holds more than word characters'); return word; };
|
|
6
|
-
/** The secret store this host keeps head's keys in, by the name its lock gives the platform's: one adapter each, every secret crossing a command's stdin and stdout only. */
|
|
7
|
+
/** The secret store this host keeps head's keys in, by the name its lock gives the platform's: one adapter each, every secret crossing a command's stdin and stdout only; a key it is asked for by its account is made there once, and only its public half handed on. */
|
|
7
8
|
export const keychain = (service, kind) => ((made) => {
|
|
8
9
|
if (made === undefined)
|
|
9
10
|
throw Error(`REFUSE·keychain ${kind} is no store head carries`);
|
|
10
|
-
return made(service);
|
|
11
|
+
return ((store) => ({ ...store, made: (account) => ((secret) => secret && publicOf(secret))(store.read(account) ?? ((key) => { store.write(account, key.secret); return store.read(account) === key.secret ? key.secret : undefined; })(newKey())) }))(made(service));
|
|
11
12
|
})({ keychain: keychainOfMac, 'secret-tool': secretTool, 'credential-manager': credentialManager }[kind]);
|
|
@@ -8,3 +8,4 @@ export declare const layAt: (place: string, rel: string, bytes: Uint8Array) => v
|
|
|
8
8
|
export declare const takeAt: (path: string) => Uint8Array | undefined;
|
|
9
9
|
export declare const hasAt: (place: string, rel: string) => boolean;
|
|
10
10
|
export declare const dropAt: (place: string, rel: string) => void;
|
|
11
|
+
export declare const listAt: (place: string, rel: string) => readonly string[];
|
package/dist/src/ports/place.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join, resolve, sep } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import { LOCK } from '@lapxo/topos/wire';
|
|
@@ -24,3 +24,9 @@ catch {
|
|
|
24
24
|
} };
|
|
25
25
|
export const hasAt = (place, rel) => existsSync(resolve(place, rel));
|
|
26
26
|
export const dropAt = (place, rel) => rmSync(inside(place, rel), { force: true });
|
|
27
|
+
export const listAt = (place, rel) => { try {
|
|
28
|
+
return readdirSync(inside(place, rel));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return [];
|
|
32
|
+
} };
|
|
@@ -1,13 +1,20 @@
|
|
|
1
|
+
import type { ChildProcess } from 'node:child_process';
|
|
1
2
|
export interface Printed {
|
|
2
3
|
readonly code: number;
|
|
3
4
|
readonly out: readonly string[];
|
|
4
5
|
readonly err: readonly string[];
|
|
6
|
+
readonly refusal?: Readonly<Record<string, string>>;
|
|
5
7
|
}
|
|
6
8
|
export interface Bounds {
|
|
7
9
|
readonly wait: number;
|
|
8
10
|
readonly most: number;
|
|
9
11
|
readonly signal?: AbortSignal;
|
|
10
12
|
}
|
|
13
|
+
/** A process head starts in a group of its own, so stopping it stops everything it started. */
|
|
14
|
+
export declare const grouped: (command: string, args: readonly string[], at: {
|
|
15
|
+
readonly cwd?: string;
|
|
16
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
17
|
+
}, pipes?: number) => ChildProcess;
|
|
11
18
|
/**
|
|
12
19
|
* A process run beside head, never blocking it: what it printed, out and err, line by line, and its exit, which is
|
|
13
20
|
* transport and never the verdict. Its whole group is stopped when the wait runs out, when it prints more bytes than it
|
|
@@ -18,3 +25,5 @@ export declare const spawned: (command: string, args: readonly string[], at: {
|
|
|
18
25
|
readonly env?: NodeJS.ProcessEnv;
|
|
19
26
|
readonly input?: string;
|
|
20
27
|
}, bounds: Bounds) => Promise<Printed>;
|
|
28
|
+
/** What a process head already started prints from now on, within the same bounds. */
|
|
29
|
+
export declare const watched: (child: ChildProcess, bounds: Bounds) => Promise<Printed>;
|
|
@@ -2,13 +2,16 @@ import { spawn } from 'node:child_process';
|
|
|
2
2
|
const running = new Set();
|
|
3
3
|
process.once('exit', () => { for (const stop of running)
|
|
4
4
|
stop(); });
|
|
5
|
+
/** A process head starts in a group of its own, so stopping it stops everything it started. */
|
|
6
|
+
export const grouped = (command, args, at, pipes = 3) => spawn(command, [...args], { cwd: at.cwd, env: at.env, stdio: Array(pipes).fill('pipe'), detached: process.platform !== 'win32', windowsHide: true });
|
|
5
7
|
/**
|
|
6
8
|
* A process run beside head, never blocking it: what it printed, out and err, line by line, and its exit, which is
|
|
7
9
|
* transport and never the verdict. Its whole group is stopped when the wait runs out, when it prints more bytes than it
|
|
8
10
|
* may, when the asker cancels or when head exits; the exit is then -1 and the cause is err's last line.
|
|
9
11
|
*/
|
|
10
|
-
export const spawned = (command, args, at, bounds) =>
|
|
11
|
-
|
|
12
|
+
export const spawned = (command, args, at, bounds) => ((child) => { child.stdin.on('error', () => undefined).end(at.input ?? ''); return watched(child, bounds); })(grouped(command, args, at));
|
|
13
|
+
/** What a process head already started prints from now on, within the same bounds. */
|
|
14
|
+
export const watched = (child, bounds) => new Promise((resolve) => {
|
|
12
15
|
const [out, err] = [[], []];
|
|
13
16
|
let [printed, cause, done] = [0, undefined, false];
|
|
14
17
|
const kill = () => { try {
|
|
@@ -41,7 +44,6 @@ export const spawned = (command, args, at, bounds) => new Promise((resolve) => {
|
|
|
41
44
|
child.stderr.on('data', take(err));
|
|
42
45
|
child.on('error', (error) => { cause ??= error.message; finish(-1); });
|
|
43
46
|
child.on('close', (code) => finish(code ?? -1));
|
|
44
|
-
child.stdin.on('error', () => undefined).end(at.input ?? '');
|
|
45
47
|
if (signal.aborted)
|
|
46
48
|
cancel();
|
|
47
49
|
else
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
import { Socket } from 'node:net';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
/**
|
|
13
|
+
* A process started before it is asked: it loads what the program it will run imports, says it is ready on its fourth
|
|
14
|
+
* pipe, and waits there for one ask, the folder, the arguments and the variables a process started then would have been
|
|
15
|
+
* given. It takes them as its own, closes that pipe and runs the program once, as that process would have. An ask that
|
|
16
|
+
* never comes ends it.
|
|
17
|
+
*/
|
|
18
|
+
const [program] = process.argv.slice(2);
|
|
19
|
+
const url = pathToFileURL(program), pipe = new Socket({ fd: 3, readable: true, writable: true });
|
|
20
|
+
const asked = new Promise((resolve) => { let text = ''; pipe.setEncoding('utf8').on('data', (chunk) => { text += chunk; }).on('error', () => undefined).on('close', () => resolve(text)); });
|
|
21
|
+
await Promise.all([...readFileSync(program, 'utf8').matchAll(/^import [^'"]*['"](\.{1,2}\/[^'"]+)['"];?$/gm)].map(([, path]) => import(__rewriteRelativeImportExtension(new URL(path, url).href)).catch(() => undefined)));
|
|
22
|
+
pipe.write('ready\n');
|
|
23
|
+
const text = await asked;
|
|
24
|
+
if (!text)
|
|
25
|
+
process.exit(0);
|
|
26
|
+
const { cwd, args, env } = JSON.parse(text);
|
|
27
|
+
for (const name of Object.keys(process.env))
|
|
28
|
+
if (!(name in env))
|
|
29
|
+
delete process.env[name];
|
|
30
|
+
Object.assign(process.env, env);
|
|
31
|
+
process.chdir(cwd);
|
|
32
|
+
process.argv = [process.argv[0], program, ...args];
|
|
33
|
+
await import(__rewriteRelativeImportExtension(url.href));
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Said } from '../core/lock.ts';
|
|
2
|
+
export interface Field {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly about: string;
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly required: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface Tool {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly about: string;
|
|
11
|
+
readonly fields: readonly Field[];
|
|
12
|
+
readonly hints: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
export interface Resource {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
readonly about: string;
|
|
17
|
+
readonly template: string;
|
|
18
|
+
readonly mime: string;
|
|
19
|
+
}
|
|
20
|
+
export interface Prompt {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
readonly about: string;
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly line: string;
|
|
25
|
+
readonly fields: readonly Field[];
|
|
26
|
+
}
|
|
27
|
+
export interface Surface {
|
|
28
|
+
readonly name: string;
|
|
29
|
+
readonly version: string;
|
|
30
|
+
readonly tools: readonly Tool[];
|
|
31
|
+
readonly resources: readonly Resource[];
|
|
32
|
+
readonly prompts: readonly Prompt[];
|
|
33
|
+
}
|
|
34
|
+
/** Everything a client is offered, read off the lock alone: its tools, resources and prompts, each with the words a model sees. */
|
|
35
|
+
export declare const surfaceOf: (lock: readonly Said[]) => Surface;
|
|
36
|
+
export declare const refusedOn: (lock: readonly Said[], platform: string) => string | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The fields a URI gives a resource template, or none when it is not one of its URIs: {name} matches one path step,
|
|
39
|
+
* {?a,b} names query fields any of which may be absent, in any order, each decoded.
|
|
40
|
+
*/
|
|
41
|
+
export declare const matchTemplate: (template: string, uri: string) => Readonly<Record<string, string>> | undefined;
|
|
42
|
+
export interface Cell {
|
|
43
|
+
readonly code: string;
|
|
44
|
+
readonly state: string;
|
|
45
|
+
readonly next: {
|
|
46
|
+
readonly tool: string;
|
|
47
|
+
readonly args: Readonly<Record<string, string>>;
|
|
48
|
+
} | {
|
|
49
|
+
readonly none: string;
|
|
50
|
+
};
|
|
51
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
52
|
+
readonly head?: string;
|
|
53
|
+
}
|
|
54
|
+
/** A said code as the cell head answers with: its state and next from the lock, the next's arguments read from the cell's own fields; a bound refusal a field carries keeps bound's code, head's own beside it. */
|
|
55
|
+
export declare const cellOf: (lock: readonly Said[], key: string, given: Readonly<Record<string, string | undefined>>) => Cell;
|
|
56
|
+
export declare const cellLine: (cell: Cell) => string;
|
|
57
|
+
/** An answer as cells and the lines bound printed beside them, read back from what head said: the shape every tool result has. */
|
|
58
|
+
export declare const shapeOf: (answer: readonly string[]) => {
|
|
59
|
+
readonly cells: readonly Cell[];
|
|
60
|
+
readonly lines: readonly string[];
|
|
61
|
+
};
|
|
62
|
+
/** The one output schema every tool declares: cells in the states the lock names, and the lines bound printed. */
|
|
63
|
+
export declare const shapeSchema: (lock: readonly Said[]) => {
|
|
64
|
+
type: "object";
|
|
65
|
+
required: string[];
|
|
66
|
+
properties: {
|
|
67
|
+
cells: {
|
|
68
|
+
type: string;
|
|
69
|
+
items: {
|
|
70
|
+
type: string;
|
|
71
|
+
required: string[];
|
|
72
|
+
properties: {
|
|
73
|
+
code: {
|
|
74
|
+
type: string;
|
|
75
|
+
};
|
|
76
|
+
state: {
|
|
77
|
+
enum: string[];
|
|
78
|
+
};
|
|
79
|
+
head: {
|
|
80
|
+
type: string;
|
|
81
|
+
};
|
|
82
|
+
next: {
|
|
83
|
+
oneOf: ({
|
|
84
|
+
type: string;
|
|
85
|
+
required: string[];
|
|
86
|
+
properties: {
|
|
87
|
+
tool: {
|
|
88
|
+
type: string;
|
|
89
|
+
};
|
|
90
|
+
args: {
|
|
91
|
+
type: string;
|
|
92
|
+
additionalProperties: {
|
|
93
|
+
type: string;
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
none?: undefined;
|
|
97
|
+
};
|
|
98
|
+
} | {
|
|
99
|
+
type: string;
|
|
100
|
+
required: string[];
|
|
101
|
+
properties: {
|
|
102
|
+
none: {
|
|
103
|
+
type: string;
|
|
104
|
+
};
|
|
105
|
+
tool?: undefined;
|
|
106
|
+
args?: undefined;
|
|
107
|
+
};
|
|
108
|
+
})[];
|
|
109
|
+
};
|
|
110
|
+
fields: {
|
|
111
|
+
type: string;
|
|
112
|
+
additionalProperties: {
|
|
113
|
+
type: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
lines: {
|
|
120
|
+
type: string;
|
|
121
|
+
items: {
|
|
122
|
+
type: string;
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { aboutOf, below, members, valueOf } from "../core/lock.js";
|
|
2
|
+
import { sayIn } from "../core/surface.js";
|
|
3
|
+
const nameOf = (line) => line.scope.split('/')[1];
|
|
4
|
+
const fieldsOf = (lock, scope) => ((required) => members(valueOf(lock, scope)).map((name) => ({
|
|
5
|
+
name, about: aboutOf(lock, `${scope}/${name}`), type: valueOf(lock, `${scope}/${name}`), required: required.includes(name)
|
|
6
|
+
})))(members(valueOf(lock, `${scope}/required`)));
|
|
7
|
+
/** Everything a client is offered, read off the lock alone: its tools, resources and prompts, each with the words a model sees. */
|
|
8
|
+
export const surfaceOf = (lock) => ({
|
|
9
|
+
name: valueOf(lock, 'name'), version: valueOf(lock, 'version'),
|
|
10
|
+
tools: below(lock, 'tool').map((line) => ({ name: nameOf(line), about: line.about ?? '', fields: fieldsOf(lock, line.scope), hints: members(valueOf(lock, `${line.scope}/hints`)) })),
|
|
11
|
+
resources: below(lock, 'resource').map((line) => ({ name: nameOf(line), about: line.about ?? '', template: line.value ?? '', mime: valueOf(lock, `${line.scope}/mime`) })),
|
|
12
|
+
prompts: below(lock, 'prompt').map((line) => ({ name: nameOf(line), about: line.about ?? '', text: aboutOf(lock, `${line.scope}/text`), line: aboutOf(lock, `${line.scope}/line`), fields: fieldsOf(lock, line.scope) })),
|
|
13
|
+
});
|
|
14
|
+
export const refusedOn = (lock, platform) => ((supported) => (supported.includes(platform) ? undefined : sayIn(lock)('platform', { platform, supported: supported.join('|') })))(members(valueOf(lock, 'platform/supported')));
|
|
15
|
+
/**
|
|
16
|
+
* The fields a URI gives a resource template, or none when it is not one of its URIs: {name} matches one path step,
|
|
17
|
+
* {?a,b} names query fields any of which may be absent, in any order, each decoded.
|
|
18
|
+
*/
|
|
19
|
+
export const matchTemplate = (template, uri) => {
|
|
20
|
+
const [path = '', query = ''] = template.split('{?');
|
|
21
|
+
const names = [...path.matchAll(/\{(\w+)\}/g)].map((m) => m[1]);
|
|
22
|
+
const pattern = new RegExp(`^${path.split(/\{\w+\}/).map((part) => part.replace(/[.*+?^$()|[\]\\]/g, '\\$&')).join('([^/?#]+)')}(?:\\?(.*))?$`);
|
|
23
|
+
const got = pattern.exec(uri);
|
|
24
|
+
if (got === null)
|
|
25
|
+
return undefined;
|
|
26
|
+
const params = new URLSearchParams(got[names.length + 1] ?? '');
|
|
27
|
+
return { ...Object.fromEntries(names.map((name, i) => [name, decodeURIComponent(got[i + 1])])),
|
|
28
|
+
...Object.fromEntries(query.replace('}', '').split(',').filter(Boolean).flatMap((name) => ((v) => (v === null ? [] : [[name, v]]))(params.get(name)))) };
|
|
29
|
+
};
|
|
30
|
+
/** A said code as the cell head answers with: its state and next from the lock, the next's arguments read from the cell's own fields; a bound refusal a field carries keeps bound's code, head's own beside it. */
|
|
31
|
+
export const cellOf = (lock, key, given) => {
|
|
32
|
+
const fields = Object.fromEntries(Object.entries(given).filter((e) => e[1] !== undefined)), bound = Object.values(fields).map((v) => /^REFUSE·[\w-]+/.exec(v)?.[0]).find(Boolean);
|
|
33
|
+
const [tool, args] = [valueOf(lock, `said/${key}/next`), members(valueOf(lock, `said/${key}/next/args`)).map((a) => ((k, v) => [k, v.startsWith('$') ? fields[v.slice(1)] ?? '' : v])(a.split(':')[0], a.slice(a.indexOf(':') + 1)))];
|
|
34
|
+
return { code: bound ?? `head/${key}`, state: valueOf(lock, `said/${key}/state`), next: tool === 'none' ? { none: aboutOf(lock, `said/${key}/next`) } : { tool, args: Object.fromEntries(args) }, fields, ...(bound ? { head: `head/${key}` } : {}) };
|
|
35
|
+
};
|
|
36
|
+
export const cellLine = (cell) => [`said/${cell.code} state=${cell.state}`, ...('tool' in cell.next ? [`next=${cell.next.tool}`, ...Object.entries(cell.next.args).map(([k, v]) => `next.${k}=${JSON.stringify(v)}`)] : ['next=none', `next.why=${JSON.stringify(cell.next.none)}`]),
|
|
37
|
+
...(cell.head ? [`head=${JSON.stringify(cell.head)}`] : []), ...Object.entries(cell.fields).map(([k, v]) => `${k}=${JSON.stringify(v)}`)].join(' ');
|
|
38
|
+
/** An answer as cells and the lines bound printed beside them, read back from what head said: the shape every tool result has. */
|
|
39
|
+
export const shapeOf = (answer) => ({ lines: answer.filter((l) => !l.startsWith('said/')),
|
|
40
|
+
cells: answer.filter((l) => l.startsWith('said/')).map((l) => ((code, rest) => ((t) => ({ code, state: t['state'] ?? '', next: t['next'] === 'none' || t['next'] === undefined ? { none: t['next.why'] ?? '' } : { tool: t['next'], args: Object.fromEntries(Object.entries(t).filter(([k]) => k.startsWith('next.')).map(([k, v]) => [k.slice(5), v])) },
|
|
41
|
+
fields: Object.fromEntries(Object.entries(t).filter(([k]) => !['state', 'next', 'head'].includes(k) && !k.startsWith('next.'))), ...(t['head'] ? { head: t['head'] } : {}) }))(Object.fromEntries([...rest.matchAll(/(\S+?)=("(?:[^"\\]|\\.)*"|\S+)/g)].map((m) => [m[1], m[2].startsWith('"') ? JSON.parse(m[2]) : m[2]]))))(l.slice('said/'.length, l.indexOf(' ')), l.slice(l.indexOf(' ') + 1))) });
|
|
42
|
+
/** The one output schema every tool declares: cells in the states the lock names, and the lines bound printed. */
|
|
43
|
+
export const shapeSchema = (lock) => ({ type: 'object', required: ['cells', 'lines'], properties: {
|
|
44
|
+
cells: { type: 'array', items: { type: 'object', required: ['code', 'state', 'next', 'fields'], properties: { code: { type: 'string' }, state: { enum: [...members(valueOf(lock, 'shape/states'))] }, head: { type: 'string' },
|
|
45
|
+
next: { oneOf: [{ type: 'object', required: ['tool', 'args'], properties: { tool: { type: 'string' }, args: { type: 'object', additionalProperties: { type: 'string' } } } }, { type: 'object', required: ['none'], properties: { none: { type: 'string' } } }] },
|
|
46
|
+
fields: { type: 'object', additionalProperties: { type: 'string' } } } } },
|
|
47
|
+
lines: { type: 'array', items: { type: 'string' } }
|
|
48
|
+
} });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Bounds, Printed } from './process.ts';
|
|
2
|
+
/** How many processes head keeps started ahead of each program while it answers a call, and the variables node reads as it starts: a process started under other values of them is never asked. */
|
|
3
|
+
export declare const warmth: {
|
|
4
|
+
spares: number;
|
|
5
|
+
boot: readonly string[];
|
|
6
|
+
};
|
|
7
|
+
/** Keeps as many processes started ahead of a program as head's lock says; resolved when each has loaded what it runs. */
|
|
8
|
+
export declare const kept: (program: string) => Promise<unknown>;
|
|
9
|
+
/** Every process still waiting to be asked is stopped: head keeps none past the call it started them for. */
|
|
10
|
+
export declare const cooled: () => void;
|
|
11
|
+
/**
|
|
12
|
+
* A program run in a process started ahead under the same starting variables, handed the folder, arguments and
|
|
13
|
+
* variables a process started now would get, and watched within the same bounds; undefined when none is held ready,
|
|
14
|
+
* so the caller starts one as before and never waits on one still loading. Each process answers one ask and ends.
|
|
15
|
+
*/
|
|
16
|
+
export declare const warmed: (program: string, args: readonly string[], at: {
|
|
17
|
+
readonly cwd: string;
|
|
18
|
+
readonly env: NodeJS.ProcessEnv;
|
|
19
|
+
}, bounds: Bounds) => Promise<Printed> | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { grouped, watched } from "./process.js";
|
|
3
|
+
/** How many processes head keeps started ahead of each program while it answers a call, and the variables node reads as it starts: a process started under other values of them is never asked. */
|
|
4
|
+
export const warmth = { spares: 0, boot: [] };
|
|
5
|
+
const spares = new Map();
|
|
6
|
+
const alive = (one) => one.child.exitCode === null && one.child.signalCode === null;
|
|
7
|
+
const entry = fileURLToPath(new URL(`./spare${import.meta.url.slice(import.meta.url.lastIndexOf('.'))}`, import.meta.url));
|
|
8
|
+
const bootOf = (env) => JSON.stringify(Object.entries(env).filter(([name]) => warmth.boot.some((p) => name.startsWith(p))).sort(([a], [b]) => (a < b ? -1 : 1)));
|
|
9
|
+
const stop = (one) => { try {
|
|
10
|
+
process.kill(-one.child.pid, 'SIGKILL');
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
one.child.kill('SIGKILL');
|
|
14
|
+
} };
|
|
15
|
+
const started = (program) => {
|
|
16
|
+
const env = { ...process.env }, child = grouped(process.execPath, [entry, program], { env }, 4);
|
|
17
|
+
child.stdin.on('error', () => undefined).end('');
|
|
18
|
+
const spare = { child, boot: bootOf(env), ready: new Promise((resolve) => { child.stdio[3].on('error', () => undefined).once('data', () => { spare.loaded = true; resolve(); }); child.once('close', () => resolve()); }), loaded: false };
|
|
19
|
+
return spare;
|
|
20
|
+
};
|
|
21
|
+
/** Keeps as many processes started ahead of a program as head's lock says; resolved when each has loaded what it runs. */
|
|
22
|
+
export const kept = (program) => {
|
|
23
|
+
const live = (spares.get(program) ?? []).filter(alive);
|
|
24
|
+
while (live.length < warmth.spares)
|
|
25
|
+
live.push(started(program));
|
|
26
|
+
spares.set(program, live);
|
|
27
|
+
return Promise.all(live.map((one) => one.ready));
|
|
28
|
+
};
|
|
29
|
+
/** Every process still waiting to be asked is stopped: head keeps none past the call it started them for. */
|
|
30
|
+
export const cooled = () => { for (const one of [...spares.values()].flat())
|
|
31
|
+
stop(one); spares.clear(); };
|
|
32
|
+
process.once('exit', cooled);
|
|
33
|
+
/**
|
|
34
|
+
* A program run in a process started ahead under the same starting variables, handed the folder, arguments and
|
|
35
|
+
* variables a process started now would get, and watched within the same bounds; undefined when none is held ready,
|
|
36
|
+
* so the caller starts one as before and never waits on one still loading. Each process answers one ask and ends.
|
|
37
|
+
*/
|
|
38
|
+
export const warmed = (program, args, at, bounds) => {
|
|
39
|
+
const live = spares.get(program) ?? [], index = live.findIndex((one) => one.loaded && alive(one) && one.boot === bootOf(at.env));
|
|
40
|
+
const spare = index < 0 ? undefined : live.splice(index, 1)[0];
|
|
41
|
+
if (spare === undefined)
|
|
42
|
+
return undefined;
|
|
43
|
+
void kept(program);
|
|
44
|
+
spare.child.stdio[3].end(`${JSON.stringify({ cwd: at.cwd, args, env: at.env })}\n`);
|
|
45
|
+
return watched(spare.child, bounds);
|
|
46
|
+
};
|
package/dist/src/signer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { signLot } from "./
|
|
3
|
+
import { signLot } from "./ports/keys.js";
|
|
4
4
|
import { keychain } from "./ports/keychain.js";
|
|
5
5
|
const [service = '', account = '', key = '', algorithm = '', store = 'keychain'] = process.argv.slice(2);
|
|
6
6
|
const secret = keychain(service, store).read(account);
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { Asked, Context } from '../core/answer.ts';
|
|
2
|
+
import type { Call } from '../core/read.ts';
|
|
3
|
+
import type { Attachment } from '../access/contract.ts';
|
|
2
4
|
/**
|
|
3
5
|
* Access to a source obtained ahead of any call, at the origin the person picked once where several are declared: the
|
|
4
6
|
* way its document says access is proven, run by the adapter of
|
|
5
7
|
* that kind — the person's own page, or the provider they are sent to with a client registered for the visit — its
|
|
6
|
-
* secret kept in this keychain and its obtaining landed as a receipt the device key signs. Nothing is called.
|
|
8
|
+
* secret kept in this keychain and its obtaining landed as a receipt the device key signs. Nothing is called. What it
|
|
9
|
+
* attaches is what a fetch made as that source carries, to that source's own origin alone.
|
|
7
10
|
*/
|
|
8
11
|
export declare const accessed: (asked: Asked, context: Context) => Promise<readonly string[]>;
|
|
12
|
+
export declare const attachedFor: (context: Context, place: string, source: string, asked?: string) => Promise<{
|
|
13
|
+
readonly plan: Call;
|
|
14
|
+
readonly attachment: Attachment | undefined;
|
|
15
|
+
} | {
|
|
16
|
+
readonly said: readonly string[];
|
|
17
|
+
}>;
|