@runeditrun/rer 0.2.94 → 0.2.96
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 +16 -2
- package/cli/README.md +5 -1
- package/cli/agent-door.mjs +4 -0
- package/cli/agent-journey-fixtures.mjs +1 -1
- package/cli/authoring.mjs +1 -1
- package/cli/business/carry-files.mjs +142 -0
- package/cli/business/carry.mjs +37 -83
- package/cli/business/choices.mjs +17 -8
- package/cli/business/connect.mjs +6 -5
- package/cli/business/invocation.mjs +3 -2
- package/cli/business/local-commands.mjs +6 -6
- package/cli/business/questions.mjs +4 -1
- package/cli/business/state.mjs +4 -1
- package/cli/checkout-folders.mjs +14 -0
- package/cli/checkout-preparation.mjs +83 -0
- package/cli/contract.mjs +1 -1
- package/cli/door-clauses.mjs +29 -2
- package/cli/hosted-output.mjs +14 -3
- package/cli/hosted-queue-producers.mjs +43 -0
- package/cli/jsonc.mjs +1 -115
- package/cli/parse.mjs +1 -1
- package/cli/portability-migrations.mjs +2 -12
- package/edition-authoring/archive-source.mjs +86 -1
- package/edition-authoring/base-copies.mjs +15 -45
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/edition-migrations.mjs +2 -2
- package/edition-authoring/module-closure.mjs +119 -50
- package/edition-authoring/module-packages.mjs +12 -5
- package/edition-authoring/module-syntax.mjs +13 -50
- package/edition-authoring/runtime-dependencies.mjs +4 -4
- package/foundation/runtime/contract-docs.mjs +1 -1
- package/global/CHANGELOG.md +70 -0
- package/global/README.md +16 -2
- package/global/cli/layout.mjs +3 -0
- package/global/launch/facts.mjs +1 -29
- package/global/launch/state.mjs +3 -6
- package/global/list.mjs +9 -15
- package/modules/agent-door/CLAUSES.md +12 -0
- package/modules/agent-door/conformance/audit.mjs +22 -4
- package/modules/agent-door/conformance/discovery.mjs +32 -1
- package/modules/agent-door/conformance/erasure.mjs +103 -0
- package/modules/agent-door/conformance/index.mjs +13 -4
- package/modules/agent-door/conformance/journey.mjs +19 -1
- package/modules/agent-door/conformance/policy-phases.mjs +34 -1
- package/modules/agent-door/conformance/protocol.mjs +13 -3
- package/modules/agent-door/conformance/relay.mjs +63 -0
- package/modules/agent-door/conformance/unpair.mjs +47 -0
- package/modules/deploy-kit/jsonc.mjs +115 -0
- package/modules/deploy-kit/migration-directory.mjs +16 -0
- package/modules/deploy-kit/prepare.mjs +1 -1
- package/modules/deploy-kit/templates.mjs +9 -4
- package/modules/erasure/cascade.mjs +4 -4
- package/modules/erasure/index.d.mts +1 -1
- package/modules/erasure/index.mjs +1 -1
- package/modules/import-kit/src/d1/README.md +16 -1
- package/modules/import-kit/src/d1/preserved-reverse.ts +5 -2
- package/modules/import-kit/src/d1/read-fence.ts +14 -2
- package/modules/import-kit/src/d1/reverse.ts +4 -1
- package/modules/import-kit/src/d1/sets.ts +8 -0
- package/modules/import-kit/src/d1/snapshot-text.ts +68 -0
- package/modules/import-kit/src/d1/undo-report.ts +4 -1
- package/modules/import-kit/src/door/ADOPTING.md +9 -4
- package/modules/portability/README.md +28 -2
- package/modules/portability/bookkeeping.mjs +8 -4
- package/modules/portability/checkout-history.mjs +12 -6
- package/modules/portability/import.mjs +1 -1
- package/modules/portability/storage.mjs +7 -1
- package/modules/portability/worker-history.d.mts +1 -1
- package/modules/portability/worker-history.mjs +1 -1
- package/onboarding/operator-migrations.mjs +5 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,6 +23,10 @@ for adoption, refusal behavior, JSON fields and the original Base-checkout form.
|
|
|
23
23
|
contract, preserving its judgments and its own specialist clauses, then runs
|
|
24
24
|
contract document generation and checking. `rer door clauses --check` reports
|
|
25
25
|
missing or stale requirements without writing; use `--cwd DIR` to select a seed.
|
|
26
|
+
Writing requires a `Shared duties (Base)` table and skips duties listed in its
|
|
27
|
+
`Base duty` column. Unlisted duties are synchronized as clauses; a missing table
|
|
28
|
+
refuses the write. The read-only check skips the same listed duties; without a
|
|
29
|
+
table it checks all thirteen clause definitions.
|
|
26
30
|
The CLI can sync a contract before runtime adoption; regenerate the seed's source lock last.
|
|
27
31
|
See [agent door adoption](https://github.com/runeditrun/base/blob/main/modules/agent-door/ADOPTING.md#contract-clauses).
|
|
28
32
|
|
|
@@ -554,7 +558,10 @@ a headers helper. That output is a short-lived credential: connect it directly
|
|
|
554
558
|
to the MCP client and do not paste it into an agent transcript.
|
|
555
559
|
|
|
556
560
|
`rer business status` shows local pairing, service state and progress without
|
|
557
|
-
printing checkpoints or vendor data.
|
|
561
|
+
printing checkpoints or vendor data. Device credentials are stored separately
|
|
562
|
+
for each Business on an origin; disconnect also finds an older per-origin
|
|
563
|
+
credential through its original pairing record and revokes it once.
|
|
564
|
+
`rer business disconnect` revokes this
|
|
558
565
|
device through device-authenticated `DELETE /api/business/executors/self` before
|
|
559
566
|
removing its service, device and vendor credentials, state and introduced Claude
|
|
560
567
|
rules, preserving preexisting settings and unrelated edits. It says "Device
|
|
@@ -580,7 +587,14 @@ an explicit error. Revocation stops the supervisor on its next 401; it then
|
|
|
580
587
|
removes the device credential if it may and `status` says revoked. While it
|
|
581
588
|
waits, `run` says what for: the owner's permission to scan the folder connect
|
|
582
589
|
ran in (with the Your tools link) until this computer's scan is done, then the
|
|
583
|
-
owner's next step.
|
|
590
|
+
owner's next step.
|
|
591
|
+
If the server reports that this computer's scan failed, run and next instead
|
|
592
|
+
point the owner to **Retry** on **Your tools**, without asking for consent again.
|
|
593
|
+
Connect, next and run carry the Business profile into first-party checkouts
|
|
594
|
+
shown by `rer list` in the current or original pairing folder, including stopped
|
|
595
|
+
apps, as well as running and previously carried apps. Each skipped checkout
|
|
596
|
+
is named with its cause; a folder with no apps gets a next step.
|
|
597
|
+
It removes `run.lock` on every exit, including Ctrl-C,
|
|
584
598
|
SIGTERM and a closed terminal (SIGHUP); a lock whose process is gone, or that
|
|
585
599
|
has not been refreshed for two minutes, is cleared on the next start.
|
|
586
600
|
|
package/cli/README.md
CHANGED
|
@@ -592,7 +592,11 @@ or use its stored device credential.
|
|
|
592
592
|
|
|
593
593
|
`rer door clauses --write` synchronizes Base's thirteen shared agent duties
|
|
594
594
|
into a seed's `CONTRACT.md` and runs its contract-docs generator and check.
|
|
595
|
-
|
|
595
|
+
It requires the seed's `Shared duties (Base)` table and skips duties listed
|
|
596
|
+
in its `Base duty` column; only unlisted duties need clause synchronization.
|
|
597
|
+
Without that table it refuses before writing any files.
|
|
598
|
+
`rer door clauses --check` skips the same listed duties, names missing or stale
|
|
599
|
+
unlisted clauses and exits nonzero; without a table it checks all thirteen duties.
|
|
596
600
|
`--cwd DIR` selects the seed root. Existing statuses, evidence and gaps survive,
|
|
597
601
|
new clauses start missing, and seed-owned AGENT and SURFACE clauses stay intact.
|
|
598
602
|
Run the edition's source-lock command last. See
|
package/cli/agent-door.mjs
CHANGED
|
@@ -20,6 +20,9 @@ import { verificationHistory } from './agent-history.mjs';
|
|
|
20
20
|
import { journeyFixtures } from './agent-journey-fixtures.mjs';
|
|
21
21
|
import { verificationAgentInitializer } from './agent-initializer.mjs';
|
|
22
22
|
|
|
23
|
+
// Unpairing re-serves the installation without the Business trust it was paired with.
|
|
24
|
+
const pairedBindings = ['RER_OWNER_CLAIM_ISSUER', 'RER_OWNER_CLAIM_INSTALLATION_ID', 'RER_OWNER_CLAIM_APP_ORIGIN', 'RER_OWNER_CLAIM_PUBLIC_KEYS', 'RER_BUSINESS_TRUST'];
|
|
25
|
+
|
|
23
26
|
function finish(result, report) {
|
|
24
27
|
if (result.capabilities) report(`Agent capabilities (${result.capabilities.mode}): declared=${result.capabilities.declared.join(',')}; refused=${result.capabilities.refused.join(',')}; unscoped=${result.capabilities.unscoped.join(',')}.`);
|
|
25
28
|
for (const point of result.points) report(`${point.ok ? 'PASS' : 'FAIL'} ${point.id}${point.ok || !point.detail ? '' : `: ${point.detail}`}`);
|
|
@@ -152,6 +155,7 @@ export async function checkAgentDoor(root, { declaration, setupManifest, owner,
|
|
|
152
155
|
const result = await runAgentDoorConformance({ fetch: request, origin: hosted.origin, surface: declared.surface,
|
|
153
156
|
signer: { issuer, installationId, kid, privateKey: pair.privateKey }, person: sponsors[0], sponsors: sponsors.filter(person => !negativeOnly.has(person.label)), webhooks, business, prove, ...journey, nativeStep, prepare, invoke: workerDriver?.run(hosted),
|
|
154
157
|
initializeAgent: initializeAgent && (({ agentId, person }) => initializeAgent({ agentId, person, request, origin: hosted.origin, mail: network.mail, fixtures: network.fixtures })),
|
|
158
|
+
unpair: () => hosted.rebind(pairedBindings),
|
|
155
159
|
});
|
|
156
160
|
const points = [...result.points, ...reviewers.points()];
|
|
157
161
|
return finish({ ...result, points, ok: points.every(point => point.ok) }, report);
|
|
@@ -12,7 +12,7 @@ export async function journeyFixtures(root, declaration, context) {
|
|
|
12
12
|
const prepare = (await import(pathToFileURL(resolve(root, declaration.module)))).default;
|
|
13
13
|
if (typeof prepare !== 'function') throw new RerError('agent_fixtures_invalid', 'verification.fixtures module must default-export a phase preparation function.', 1);
|
|
14
14
|
return async ({ phase, tool, now }) => {
|
|
15
|
-
try { context.queues?.release(); return await prepare({ ...context, phase, tool, now }); }
|
|
15
|
+
try { context.queues?.release(); await context.queues?.restore(); return await prepare({ ...context, phase, tool, now }); }
|
|
16
16
|
catch (error) {
|
|
17
17
|
if (error instanceof FixtureDatabaseError || error?.code === 'hosted_database_invalid') throw new FixtureDatabaseError();
|
|
18
18
|
throw new Error('Native phase preparation failed; no captured mail, credentials or fixture values are logged.');
|
package/cli/authoring.mjs
CHANGED
|
@@ -10,7 +10,7 @@ export function authoringCommand(options) {
|
|
|
10
10
|
...(options.editionMigration ? options.editionMigration.split(',').flatMap(id => ['--edition-migration', id]) : []),
|
|
11
11
|
options.ref, '--record', options.record ?? 'base-copies.json',
|
|
12
12
|
...(options.base ? ['--base', resolve(options.cwd, options.base)] : []),
|
|
13
|
-
...(options.baseArchive ? ['--base-archive', resolve(options.cwd, options.baseArchive)] : []), ...(options.offline ? ['--offline'] : []),
|
|
13
|
+
...(options.baseArchive ? ['--base-archive', resolve(options.cwd, options.baseArchive)] : []), ...(options.offline ? ['--offline'] : []), ...(options.fromApi ? ['--from-api'] : []),
|
|
14
14
|
], 1));
|
|
15
15
|
} catch (error) { throw refuse(error.message); }
|
|
16
16
|
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { chmod, lstat, mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { loadState, stateDirectory } from './state.mjs';
|
|
5
|
+
import { serversDirectory } from '../server-registry.mjs';
|
|
6
|
+
import { alive } from '../../modules/job-queue/identity.mjs';
|
|
7
|
+
import { checkoutFolders } from '../checkout-folders.mjs';
|
|
8
|
+
import { checkoutPreparation } from '../checkout-preparation.mjs';
|
|
9
|
+
|
|
10
|
+
const carryPath = checkout => join(checkout, '.rer/local/business.json');
|
|
11
|
+
const registryPath = () => join(stateDirectory(), 'carried.json');
|
|
12
|
+
async function readJson(path) {
|
|
13
|
+
try { return JSON.parse(await readFile(path, 'utf8')); }
|
|
14
|
+
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
15
|
+
}
|
|
16
|
+
async function recordedCheckouts() {
|
|
17
|
+
const recorded = await readJson(registryPath()) ?? [];
|
|
18
|
+
if (!Array.isArray(recorded)) throw Error('the carry registry is invalid');
|
|
19
|
+
return recorded;
|
|
20
|
+
}
|
|
21
|
+
async function atomicJson(path, value) {
|
|
22
|
+
const directory = dirname(path), temporary = join(directory, `${randomUUID()}.tmp`);
|
|
23
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
24
|
+
await chmod(directory, 0o700);
|
|
25
|
+
try {
|
|
26
|
+
await writeFile(temporary, JSON.stringify(value) + '\n', { flag: 'wx', mode: 0o600 });
|
|
27
|
+
await chmod(temporary, 0o600);
|
|
28
|
+
await rename(temporary, path);
|
|
29
|
+
} finally { await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error; }); }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function regular(path, directory = false, optional = false) {
|
|
33
|
+
let info;
|
|
34
|
+
try { info = await lstat(path); }
|
|
35
|
+
catch (error) { if (optional && error.code === 'ENOENT') return false; throw error; }
|
|
36
|
+
if (info.isSymbolicLink() || !(directory ? info.isDirectory() : info.isFile())) throw Error('the carry path is linked or not a regular file');
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
export async function firstParty(checkout) {
|
|
40
|
+
if (typeof checkout !== 'string' || !isAbsolute(checkout)) return false;
|
|
41
|
+
await regular(checkout, true);
|
|
42
|
+
await regular(join(checkout, 'OPERATIONS.json'));
|
|
43
|
+
return (await readJson(join(checkout, 'OPERATIONS.json')))?.seedContract?.profile === 'first-party';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// This file is generated Business carry, not an app's own settings. Its supported
|
|
47
|
+
// profile values remain carry-owned; unknown documents and foreign carries do not.
|
|
48
|
+
function ownsCarry(prior, carry) {
|
|
49
|
+
return prior && !Array.isArray(prior) && prior.version === carry.version
|
|
50
|
+
&& prior.origin === carry.origin && prior.business_id === carry.business_id && prior.business_url === carry.business_url
|
|
51
|
+
&& typeof prior.name === 'string' && (prior.legal_name === null || typeof prior.legal_name === 'string')
|
|
52
|
+
&& (prior.accent === null || typeof prior.accent === 'string' && /^#[0-9a-f]{6}$/i.test(prior.accent))
|
|
53
|
+
&& (prior.logo_url === null || typeof prior.logo_url === 'string') && typeof prior.refreshed_at === 'string'
|
|
54
|
+
&& Object.keys(prior).length === Object.keys(carry).length + 1 && Object.keys(carry).every(key => Object.hasOwn(prior, key));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function writeCarry(checkout, carry, { existingOnly = false } = {}) {
|
|
58
|
+
if (!await firstParty(checkout)) throw Error('the checkout is not first-party');
|
|
59
|
+
const root = resolve(checkout), path = carryPath(root);
|
|
60
|
+
for (const directory of [join(root, '.rer'), dirname(path)]) await regular(directory, true, !existingOnly);
|
|
61
|
+
const exists = await regular(path, false, !existingOnly);
|
|
62
|
+
const prior = exists ? await readJson(path) : null;
|
|
63
|
+
if (exists && !ownsCarry(prior, carry)) throw Error('the existing file is not a carry for this paired Business');
|
|
64
|
+
const checkouts = await recordedCheckouts();
|
|
65
|
+
// Record custody before the write, so disconnect can clean up even after a crash.
|
|
66
|
+
if (!checkouts.includes(root)) await atomicJson(registryPath(), [...checkouts, root]);
|
|
67
|
+
if (prior && Object.keys(carry).every(key => prior[key] === carry[key])) {
|
|
68
|
+
for (const [file, mode] of [[dirname(path), 0o700], [path, 0o600]]) {
|
|
69
|
+
if (((await stat(file)).mode & 0o777) !== mode) await chmod(file, mode);
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
await atomicJson(path, { ...carry, refreshed_at: new Date().toISOString() });
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The same read-only liveness check as the installed launcher's liveServers.
|
|
78
|
+
// Keep it portable: vendored Business commands have no global launcher files.
|
|
79
|
+
async function liveCheckouts() {
|
|
80
|
+
const registry = await readJson(join(serversDirectory(), 'state.json'));
|
|
81
|
+
const checkouts = [];
|
|
82
|
+
for (const record of registry?.running ?? []) {
|
|
83
|
+
let live = true;
|
|
84
|
+
try { live = await alive(record.owner); } catch { /* Unverifiable identities stay live, as in the registry. */ }
|
|
85
|
+
if (live) checkouts.push(record.checkout);
|
|
86
|
+
}
|
|
87
|
+
return [...new Set(checkouts)];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export async function carryCheckouts(refused, state) {
|
|
91
|
+
const checkouts = new Map();
|
|
92
|
+
try { for (const checkout of await recordedCheckouts()) checkouts.set(checkout, { checkout, live: false }); }
|
|
93
|
+
catch (error) { refused(error); }
|
|
94
|
+
try { for (const checkout of await liveCheckouts()) checkouts.set(checkout, { checkout, live: true }); }
|
|
95
|
+
catch (error) { refused(error); }
|
|
96
|
+
// Include prepared/stopped checkouts, using the same immediate-folder door as
|
|
97
|
+
// rer list, both here and where this Business originally paired.
|
|
98
|
+
for (const directory of new Set([process.cwd(), state?.workingFolder].filter(Boolean))) {
|
|
99
|
+
try {
|
|
100
|
+
const listed = [];
|
|
101
|
+
if (await regular(join(directory, 'OPERATIONS.json'), false, true)) listed.push(directory);
|
|
102
|
+
listed.push(...await checkoutFolders(directory));
|
|
103
|
+
for (const checkout of listed) {
|
|
104
|
+
if (!checkouts.has(checkout)) checkouts.set(checkout, { checkout, live: true });
|
|
105
|
+
}
|
|
106
|
+
} catch (error) { refused(error, directory); }
|
|
107
|
+
}
|
|
108
|
+
const ready = [];
|
|
109
|
+
for (const item of checkouts.values()) {
|
|
110
|
+
try {
|
|
111
|
+
if (await firstParty(item.checkout).catch(() => false)) {
|
|
112
|
+
const status = await checkoutPreparation(item.checkout);
|
|
113
|
+
if (!status.prepared) {
|
|
114
|
+
refused(Object.assign(Error(status.reason), { preparation: true }), item.checkout);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
ready.push(item);
|
|
119
|
+
} catch (error) { refused(error, item.checkout); }
|
|
120
|
+
}
|
|
121
|
+
return ready;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export async function removeCarries() {
|
|
125
|
+
const state = await loadState();
|
|
126
|
+
if (!state?.origin || !state.businessId) return;
|
|
127
|
+
const carry = { version: 1, origin: state.origin, business_id: state.businessId,
|
|
128
|
+
business_url: `${state.origin}/business/${encodeURIComponent(state.businessId)}`,
|
|
129
|
+
name: null, legal_name: null, accent: null, logo_url: null };
|
|
130
|
+
const recorded = await recordedCheckouts();
|
|
131
|
+
for (const checkout of new Set([...recorded, ...await liveCheckouts()])) {
|
|
132
|
+
try {
|
|
133
|
+
if (!await firstParty(checkout)) continue;
|
|
134
|
+
for (const directory of [join(checkout, '.rer'), dirname(carryPath(checkout))]) await regular(directory, true);
|
|
135
|
+
if (await regular(carryPath(checkout), false, true) && ownsCarry(await readJson(carryPath(checkout)), carry)) await unlink(carryPath(checkout));
|
|
136
|
+
} catch (error) {
|
|
137
|
+
// Disconnect must still clean eligible checkouts when an old one was removed,
|
|
138
|
+
// linked, repurposed or became unreadable. Leave unrelated files untouched.
|
|
139
|
+
if (!['ENOENT', 'ENOTDIR'].includes(error.code) && error.message !== 'the carry path is linked or not a regular file' && !(error instanceof SyntaxError)) throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
package/cli/business/carry.mjs
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import { chmod, mkdir, readFile, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
3
|
-
import { randomUUID } from 'node:crypto';
|
|
4
1
|
import { Api } from './api.mjs';
|
|
5
2
|
import { createCredentialStore } from './keychain.mjs';
|
|
6
|
-
import {
|
|
3
|
+
import { deviceCredentialHandle, loadState } from './state.mjs';
|
|
7
4
|
import { localCause } from './errors.mjs';
|
|
8
|
-
import {
|
|
9
|
-
|
|
5
|
+
import { carryCheckouts, firstParty, writeCarry } from './carry-files.mjs';
|
|
6
|
+
export { removeCarries } from './carry-files.mjs';
|
|
10
7
|
|
|
11
|
-
const carryPath = checkout => join(checkout, '.rer/local/business.json');
|
|
12
8
|
const launched = Symbol.for('rer.business.carry.launched');
|
|
13
|
-
|
|
14
|
-
async function readJson(path) {
|
|
15
|
-
try { return JSON.parse(await readFile(path, 'utf8')); }
|
|
16
|
-
catch (error) { if (error.code === 'ENOENT') return null; throw error; }
|
|
17
|
-
}
|
|
18
|
-
async function atomicJson(path, value) {
|
|
19
|
-
const directory = dirname(path), temporary = join(directory, `${randomUUID()}.tmp`);
|
|
20
|
-
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
21
|
-
await chmod(directory, 0o700);
|
|
22
|
-
try {
|
|
23
|
-
await writeFile(temporary, JSON.stringify(value) + '\n', { flag: 'wx', mode: 0o600 });
|
|
24
|
-
await chmod(temporary, 0o600);
|
|
25
|
-
await rename(temporary, path);
|
|
26
|
-
} finally { await unlink(temporary).catch(error => { if (error.code !== 'ENOENT') throw error; }); }
|
|
27
|
-
}
|
|
9
|
+
const summaries = new Map();
|
|
28
10
|
|
|
29
11
|
export function buildCarry(state, self) {
|
|
30
12
|
const business = self?.business;
|
|
@@ -44,65 +26,45 @@ export function buildCarry(state, self) {
|
|
|
44
26
|
logo_url: logo };
|
|
45
27
|
}
|
|
46
28
|
|
|
47
|
-
|
|
48
|
-
const root = resolve(checkout), path = carryPath(root), record = join(stateDirectory(), 'carried.json');
|
|
49
|
-
const checkouts = await readJson(record) ?? [];
|
|
50
|
-
// Record custody before the write, so disconnect can clean up even after a crash.
|
|
51
|
-
if (!checkouts.includes(root)) await atomicJson(record, [...checkouts, root]);
|
|
52
|
-
let prior;
|
|
53
|
-
try { prior = await readJson(path); } catch (error) { if (!(error instanceof SyntaxError)) throw error; }
|
|
54
|
-
const values = { ...prior };
|
|
55
|
-
delete values.refreshed_at;
|
|
56
|
-
if (Object.keys(values).length === Object.keys(carry).length && Object.keys(carry).every(key => values[key] === carry[key])) {
|
|
57
|
-
for (const [file, mode] of [[dirname(path), 0o700], [path, 0o600]]) {
|
|
58
|
-
if (((await stat(file)).mode & 0o777) !== mode) await chmod(file, mode);
|
|
59
|
-
}
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
await atomicJson(path, { ...carry, refreshed_at: new Date().toISOString() });
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async function firstParty(checkout) {
|
|
67
|
-
return typeof checkout === 'string' && isAbsolute(checkout)
|
|
68
|
-
&& (await readJson(join(checkout, 'OPERATIONS.json')))?.seedContract?.profile === 'first-party';
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// The same read-only registry view as the installed launcher's liveServers.
|
|
72
|
-
// Keep this reader in the exported CLI too: vendored Business commands have no global launcher files.
|
|
73
|
-
async function liveCheckouts() {
|
|
74
|
-
const registry = await readJson(join(serversDirectory(), 'state.json'));
|
|
75
|
-
const checkouts = [];
|
|
76
|
-
for (const record of registry?.running ?? []) {
|
|
77
|
-
let live = true;
|
|
78
|
-
try { live = await alive(record.owner); } catch { /* Unverifiable identities stay live, as in the registry. */ }
|
|
79
|
-
if (live) {
|
|
80
|
-
try { if (await firstParty(record.checkout)) checkouts.push(record.checkout); }
|
|
81
|
-
catch { /* A checkout with an unreadable descriptor is not a carry destination. */ }
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return [...new Set(checkouts)];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function warning(origin, error) {
|
|
29
|
+
function warning(origin, error, checkout, report = true) {
|
|
88
30
|
// Do not echo server text, response fields or transport messages: they can contain credentials.
|
|
89
31
|
const reason = error.status ? `the server refused the request (HTTP ${error.status})`
|
|
90
32
|
: error.name === 'TimeoutError' || error.name === 'AbortError' ? 'the server did not answer within 5 seconds'
|
|
91
33
|
: error.message?.startsWith('Could not reach the Business server at ') ? 'the server is unreachable'
|
|
92
34
|
: error.message === 'credential unavailable' ? 'the Business credential is unavailable in OS credential storage'
|
|
93
|
-
:
|
|
94
|
-
|
|
35
|
+
: error.preparation ? error.message
|
|
36
|
+
: localCause(error) ?? (['the response names another Business', 'the Business profile is invalid', 'the checkout is not first-party', 'the carry path is linked or not a regular file', 'the existing file is not a carry for this paired Business', 'the carry registry is invalid', 'the checkout is not set up yet: run rer setup'].includes(error.message) ? error.message : 'the Business profile could not be refreshed');
|
|
37
|
+
const step = error.code === 'ENOENT' ? ' Open the app with rer dev --cwd FOLDER, then run business next again.' : '';
|
|
38
|
+
const text = `Business carry at ${origin}${checkout ? ` for ${JSON.stringify(checkout)}` : ''}: ${reason}; keeping any local carry.${step}\n`;
|
|
39
|
+
if (report) process.stderr.write(text);
|
|
40
|
+
return text;
|
|
95
41
|
}
|
|
96
42
|
|
|
97
|
-
export async function
|
|
43
|
+
export async function carryCheckIn(state, self, { summarize = false } = {}) {
|
|
98
44
|
try {
|
|
45
|
+
if (!state?.origin || !state.businessId || !state.executorId || state.revoked) return;
|
|
99
46
|
const carry = buildCarry(state, self);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
47
|
+
const checkouts = [], unchanged = [], skipped = [];
|
|
48
|
+
let failed = 0;
|
|
49
|
+
const refused = (error, checkout) => { failed++; skipped.push({ checkout, warning: warning(state.origin, error, checkout, false) }); };
|
|
50
|
+
for (const { checkout, live } of await carryCheckouts(refused, state)) {
|
|
51
|
+
try {
|
|
52
|
+
if (!carry) {
|
|
53
|
+
skipped.push({ checkout, warning: `Business carry skipped for ${JSON.stringify(checkout)}: the server did not provide this Business's profile; retry business next after the server supports profile sharing.\n` });
|
|
54
|
+
failed++; continue;
|
|
55
|
+
}
|
|
56
|
+
const changed = await writeCarry(checkout, carry, { existingOnly: !live });
|
|
57
|
+
(changed ? checkouts : unchanged).push(checkout);
|
|
58
|
+
} catch (error) { refused(error, checkout); }
|
|
104
59
|
}
|
|
105
|
-
|
|
60
|
+
// Changed/unchanged writes describe the same carried set. Sorting keeps
|
|
61
|
+
// filesystem and registry order from repeating a long-running run's report.
|
|
62
|
+
const signature = JSON.stringify({ carried: [...checkouts, ...unchanged].sort(), skipped: skipped.map(item => item.warning).sort() });
|
|
63
|
+
const key = JSON.stringify([state.origin, state.businessId, state.executorId]);
|
|
64
|
+
const summaryChanged = !summarize || summaries.get(key) !== signature;
|
|
65
|
+
if (summarize) summaries.set(key, signature);
|
|
66
|
+
if (summaryChanged) for (const item of skipped) process.stderr.write(item.warning);
|
|
67
|
+
return { name: carry?.name ?? state.businessId, checkouts, unchanged, failed, summaryChanged };
|
|
106
68
|
} catch (error) { warning(state.origin, error); }
|
|
107
69
|
}
|
|
108
70
|
|
|
@@ -112,7 +74,7 @@ export async function refreshCarry(api, state, { checkout, signal } = {}) {
|
|
|
112
74
|
if (checkout) {
|
|
113
75
|
const carry = buildCarry(state, self);
|
|
114
76
|
if (carry) await writeCarry(checkout, carry);
|
|
115
|
-
} else await
|
|
77
|
+
} else await carryCheckIn(state, self);
|
|
116
78
|
} catch (error) { if (!signal?.aborted) warning(state.origin, error); }
|
|
117
79
|
}
|
|
118
80
|
|
|
@@ -123,14 +85,14 @@ export async function refreshCheckout(checkout) {
|
|
|
123
85
|
try {
|
|
124
86
|
if (!await firstParty(checkout)) return;
|
|
125
87
|
state = await loadState();
|
|
126
|
-
if (!state?.origin || !state.businessId || !state.executorId) return;
|
|
127
|
-
const credential = await createCredentialStore().get(
|
|
88
|
+
if (!state?.origin || !state.businessId || !state.executorId || state.revoked) return;
|
|
89
|
+
const credential = await createCredentialStore().get(deviceCredentialHandle(state));
|
|
128
90
|
if (!credential) throw Error('credential unavailable');
|
|
129
91
|
await refreshCarry(new Api(state.origin, credential), state, { checkout });
|
|
130
92
|
} catch (error) { warning(state?.origin ?? 'the paired origin', error); }
|
|
131
93
|
}
|
|
132
94
|
|
|
133
|
-
//
|
|
95
|
+
// Reuse the supervisor's existing refresh cycle for live and previously carried apps.
|
|
134
96
|
export async function startCarryRefresh(api, state, signal) {
|
|
135
97
|
const controller = new AbortController(), combined = AbortSignal.any([signal, controller.signal]);
|
|
136
98
|
let pending = Promise.resolve(), busy = false;
|
|
@@ -141,11 +103,3 @@ export async function startCarryRefresh(api, state, signal) {
|
|
|
141
103
|
}, 60_000);
|
|
142
104
|
return async () => { clearInterval(timer); controller.abort(); await pending; };
|
|
143
105
|
}
|
|
144
|
-
|
|
145
|
-
export async function removeCarry(checkout) {
|
|
146
|
-
await unlink(carryPath(checkout)).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
147
|
-
}
|
|
148
|
-
export async function removeCarries() {
|
|
149
|
-
const recorded = await readJson(join(stateDirectory(), 'carried.json')) ?? [];
|
|
150
|
-
for (const checkout of new Set([...recorded, ...await liveCheckouts()])) await removeCarry(checkout);
|
|
151
|
-
}
|
package/cli/business/choices.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from 'node:path';
|
|
2
2
|
import { installService, removeService } from './service.mjs';
|
|
3
3
|
import { installPermissions, removePermissions } from './permissions.mjs';
|
|
4
4
|
import { saveState } from './state.mjs';
|
|
5
|
-
import {
|
|
5
|
+
import { carryCheckIn } from './carry.mjs';
|
|
6
6
|
import { businessCommand } from './invocation.mjs';
|
|
7
7
|
import { describe } from './errors.mjs';
|
|
8
8
|
|
|
@@ -55,7 +55,10 @@ export async function applyChoices(api, state, { reconnecting = false } = {}) {
|
|
|
55
55
|
// nothing is decided yet. On a new computer this first request activates it.
|
|
56
56
|
try { self = await api.get('/api/business/executors/self'); }
|
|
57
57
|
catch (error) { if (![403, 404].includes(error.status)) throw error; }
|
|
58
|
-
|
|
58
|
+
// Use the server's per-computer scan state, rather than interpreting every
|
|
59
|
+
// unfinished scan as missing consent. Do not persist paths from the response.
|
|
60
|
+
state.localScan = self?.local_scan ? { allowed: self.local_scan.allowed === true, state: self.local_scan.state } : undefined;
|
|
61
|
+
const carried = await carryCheckIn(state, self, { summarize: true });
|
|
59
62
|
const decided = Object.fromEntries(names.map(name => [name, typeof self?.optIns?.[name] === 'boolean' ? self.optIns[name] : null]));
|
|
60
63
|
// The agent this computer reported when it paired, as the owner's browser words its choices:
|
|
61
64
|
// the Claude Code rules apply only to Claude Code. An unknown agent (no route yet) decides nothing.
|
|
@@ -87,11 +90,17 @@ export async function applyChoices(api, state, { reconnecting = false } = {}) {
|
|
|
87
90
|
}
|
|
88
91
|
const undecided = names.filter(name => decided[name] === null && !inapplicable[name]);
|
|
89
92
|
if (undecided.length) {
|
|
90
|
-
once(
|
|
93
|
+
once('undecided', `The owner has not chosen yet:\n${undecided.map(name => ` - ${choices[name]}\n`).join('')}They choose on this computer's row in ${state.origin}/business/${encodeURIComponent(state.businessId)}/settings; the run and next commands apply the choices at their next check-in, ${reconnecting ? 'without pairing again' : 'so connect does not need to run again'}.\n`);
|
|
94
|
+
}
|
|
95
|
+
once('choices-next-step', `After choosing this computer's permissions in Business, run ${businessCommand('next')} to apply them and see the next task.\n`);
|
|
96
|
+
if (carried?.summaryChanged) {
|
|
97
|
+
const count = carried.checkouts.length;
|
|
98
|
+
process.stdout.write(count
|
|
99
|
+
? `Refreshed ${count} local app carry ${count === 1 ? 'file' : 'files'} for ${JSON.stringify(carried.name)}:\n${carried.checkouts.map(checkout => ` - ${join(checkout, '.rer/local/business.json')}\n`).join('')}Supporting apps apply these values when they read their carry file.\n`
|
|
100
|
+
: `No local app carry files changed for ${JSON.stringify(carried.name)}.\n`);
|
|
101
|
+
for (const checkout of carried.unchanged) process.stdout.write(`Already current: ${join(checkout, '.rer/local/business.json')}\n`);
|
|
102
|
+
if (carried.failed) process.stdout.write(`${carried.failed} local app carry ${carried.failed === 1 ? 'file could' : 'files could'} not be refreshed; see the carry warnings.\n`);
|
|
103
|
+
if (!count && !carried.unchanged.length && !carried.failed) process.stdout.write(`No local apps were found. Run ${businessCommand('next')} in the folder where rer list shows your apps.\n`);
|
|
91
104
|
}
|
|
92
|
-
once('choices-next-step', `After choosing this computer's apps or settings in Business, run ${businessCommand('next')} to apply them and see the next task.\n`);
|
|
93
|
-
if (carried) once(`carry:${JSON.stringify(carried)}`, carried.checkouts.length
|
|
94
|
-
? carried.checkouts.map(checkout => `Wrote the Business name ${JSON.stringify(carried.name)} to ${join(checkout, '.rer/local/business.json')}; ${JSON.stringify(basename(checkout))} shows it after it reads that file.\n`).join('')
|
|
95
|
-
: `No local app carry files were written for ${JSON.stringify(carried.name)}.\n`);
|
|
96
105
|
return { applied: lines.length, serviceInstalled };
|
|
97
106
|
}
|
package/cli/business/connect.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { Api, originUrl, identifier, pause } from './api.mjs';
|
|
4
|
-
import { loadState, saveState, credentialHandle, loadPending, savePending, clearPending, checkStateWritable } from './state.mjs';
|
|
4
|
+
import { loadState, saveState, credentialHandle, deviceCredentialHandle, loadPending, savePending, clearPending, checkStateWritable } from './state.mjs';
|
|
5
5
|
import { createCredentialStore } from './keychain.mjs';
|
|
6
6
|
import { applyChoices } from './choices.mjs';
|
|
7
7
|
import { rerCommand, businessCommand } from './invocation.mjs';
|
|
@@ -30,7 +30,7 @@ export async function connect({ code, origin } = {}) {
|
|
|
30
30
|
if (stored) {
|
|
31
31
|
if (stored.revoked) throw Error(`This computer was ${revokedText(stored)}\nThen connect with a new code from ${stored.origin}/business.`);
|
|
32
32
|
if (stored.origin !== origin) throw Error(`This computer is already connected to Business at ${stored.origin}. Run ${rerCommand()} business disconnect before connecting it elsewhere.`);
|
|
33
|
-
const credential = await createCredentialStore().get(
|
|
33
|
+
const credential = await createCredentialStore().get(deviceCredentialHandle(stored));
|
|
34
34
|
if (!credential) throw Error(`This computer's Business credential is missing from OS credential storage. Run ${rerCommand()} business disconnect, then connect again with a new code from ${origin}/business.`);
|
|
35
35
|
await connected(new Api(origin, credential), stored, { reconnecting: true });
|
|
36
36
|
return;
|
|
@@ -41,8 +41,8 @@ export async function connect({ code, origin } = {}) {
|
|
|
41
41
|
// Refuse before redeeming the one-use code or collecting an approval when this
|
|
42
42
|
// session cannot keep the pairing or store the device credential.
|
|
43
43
|
await checkStateWritable();
|
|
44
|
-
const store = createCredentialStore()
|
|
45
|
-
try { await store.
|
|
44
|
+
const store = createCredentialStore();
|
|
45
|
+
try { await store.check(); }
|
|
46
46
|
catch (error) {
|
|
47
47
|
const outside = error.sandboxRefused ? ` Approve this command outside the sandbox: ${rerCommand()} business connect${code ? ` --code ${code}` : ''} --origin ${origin}. Every other business command runs inside the sandbox.` : '';
|
|
48
48
|
throw Error(`${error.message}${outside} ${pending ? 'The saved pairing was kept; run connect again once this is fixed.' : nothingSent}`);
|
|
@@ -87,7 +87,8 @@ export async function connect({ code, origin } = {}) {
|
|
|
87
87
|
if (result?.status === 'paired') {
|
|
88
88
|
if (typeof result.device_credential !== 'string') throw Error('Business server returned an invalid device credential.');
|
|
89
89
|
const folder = workingFolder();
|
|
90
|
-
const state = { version: 1, origin, businessId: identifier(result.business_id), executorId: identifier(result.executor_id), vendorHandles: [], awakeConsent: false, ...(folder ? { workingFolder: folder } : {}) };
|
|
90
|
+
const state = { version: 1, credentialVersion: 2, origin, businessId: identifier(result.business_id), executorId: identifier(result.executor_id), vendorHandles: [], awakeConsent: false, ...(folder ? { workingFolder: folder } : {}) };
|
|
91
|
+
const handle = credentialHandle(origin, state.businessId);
|
|
91
92
|
// No authenticated request (including activation) before both durable writes.
|
|
92
93
|
await store.set(handle, result.device_credential);
|
|
93
94
|
try { await saveState(state); } catch (error) { await store.delete(handle); throw error; }
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { accessSync, statSync, constants } from 'node:fs';
|
|
2
2
|
import { delimiter, join, resolve, sep } from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
3
|
|
|
5
4
|
const npx = 'npx -y @runeditrun/rer';
|
|
6
5
|
const word = value => /^[A-Za-z0-9_./~:@%+=,-]+$/.test(value) ? value : `'${value.replaceAll("'", `'\\''`)}'`;
|
|
@@ -19,7 +18,9 @@ function onPath(path = '') {
|
|
|
19
18
|
// An npx run leaves nothing installed; install.sh says which launcher it ran
|
|
20
19
|
// (RER_INVOKED_AS), since it adds that launcher to PATH only for itself.
|
|
21
20
|
export function rerCommand(env = process.env) {
|
|
22
|
-
|
|
21
|
+
// The running entry identifies the invocation even when its dispatcher was
|
|
22
|
+
// delegated to a checkout's pinned copy in another package/cache directory.
|
|
23
|
+
if ((process.argv[1] ?? '').split(sep).includes('_npx')) return npx;
|
|
23
24
|
if (env.RER_INVOKED_AS) return word(env.RER_INVOKED_AS);
|
|
24
25
|
return onPath(env.PATH) ? 'rer' : npx;
|
|
25
26
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeFile, unlink } from 'node:fs/promises';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
import { loadState, loadPending, saveState, stateDirectory, removeStateDirectory, removeWorkFiles,
|
|
3
|
+
import { loadState, loadPending, saveState, stateDirectory, removeStateDirectory, removeWorkFiles, deviceCredentialHandle, liveSupervisor } from './state.mjs';
|
|
4
4
|
import { createCredentialStore, readSecret } from './keychain.mjs';
|
|
5
5
|
import { removeService, serviceStatus } from './service.mjs';
|
|
6
6
|
import { removePermissions, permissionsAdded } from './permissions.mjs';
|
|
@@ -17,7 +17,7 @@ export async function paired() {
|
|
|
17
17
|
const state = await loadState();
|
|
18
18
|
if (!state?.origin || !state.businessId || !state.executorId) throw Error(`This computer is not paired. Run ${rerCommand()} business connect --code CODE.`);
|
|
19
19
|
if (state.revoked) throw Error(`This computer was ${revokedText(state)}`);
|
|
20
|
-
const credential = await createCredentialStore().get(
|
|
20
|
+
const credential = await createCredentialStore().get(deviceCredentialHandle(state));
|
|
21
21
|
if (!credential) throw Error(`This computer's Business credential is missing from OS credential storage. Run ${rerCommand()} business disconnect, then connect again with a new code from ${state.origin}/business.`);
|
|
22
22
|
return { state, credential };
|
|
23
23
|
}
|
|
@@ -42,7 +42,7 @@ export async function forgetLocally(state, { stopRun = true } = {}) {
|
|
|
42
42
|
await attempt('permissions', () => removePermissions());
|
|
43
43
|
const vendorKeys = [];
|
|
44
44
|
for (const handle of store ? state.vendorHandles ?? [] : []) if (await attempt('vendorKeys', () => store.delete(handle))) vendorKeys.push(handle);
|
|
45
|
-
const refused = store ? await attempt('credential', () => store.delete(
|
|
45
|
+
const refused = store ? await attempt('credential', () => store.delete(deviceCredentialHandle(state))) : undefined;
|
|
46
46
|
await removeCarries();
|
|
47
47
|
if (!leftovers.length) { await removeStateDirectory(); return []; }
|
|
48
48
|
const unique = [...new Set(leftovers)];
|
|
@@ -58,7 +58,7 @@ export async function forgetLocally(state, { stopRun = true } = {}) {
|
|
|
58
58
|
export async function revokedByServer(state) {
|
|
59
59
|
const leftovers = [];
|
|
60
60
|
let cause;
|
|
61
|
-
try { await createCredentialStore().delete(
|
|
61
|
+
try { await createCredentialStore().delete(deviceCredentialHandle(state)); }
|
|
62
62
|
catch (error) { leftovers.push('credential'); cause = error.sandboxRefused ? `macOS Keychain refused to remove it inside this agent sandbox (security exited with status ${error.osStatus ?? 'unknown'}).` : describe(error); }
|
|
63
63
|
if (state.vendorHandles?.length) leftovers.push('vendorKeys');
|
|
64
64
|
if ((await serviceStatus()).installed) leftovers.push('service');
|
|
@@ -112,7 +112,7 @@ export async function disconnect() {
|
|
|
112
112
|
const state = await loadState();
|
|
113
113
|
const origin = state?.origin ?? (await loadPending())?.origin;
|
|
114
114
|
const page = origin && (state?.businessId ? `${origin}/business/${encodeURIComponent(state.businessId)}/settings` : `${origin}/business`);
|
|
115
|
-
const credential = state?.origin ? await createCredentialStore().get(
|
|
115
|
+
const credential = state?.origin ? await createCredentialStore().get(deviceCredentialHandle(state)) : null;
|
|
116
116
|
const revocation = credential ? await revoke(state.origin, credential) : 'not_sent';
|
|
117
117
|
// Until the server confirms, the device stays connected: keep its credential
|
|
118
118
|
// and everything else so disconnect can run again after browser revocation.
|
|
@@ -139,7 +139,7 @@ export async function status({ json = false } = {}) {
|
|
|
139
139
|
if (!state) {
|
|
140
140
|
process.stdout.write(json ? JSON.stringify({ paired: false, service: 'not_installed', current_task: null, checkpoint: null }) + '\n' : 'Business: not paired.\nService: not installed.\nTask: none.\nCheckpoint: none.\n'); return;
|
|
141
141
|
}
|
|
142
|
-
const stored = !state.revoked && state.origin && await createCredentialStore().get(
|
|
142
|
+
const stored = !state.revoked && state.origin && await createCredentialStore().get(deviceCredentialHandle(state));
|
|
143
143
|
const service = await serviceStatus();
|
|
144
144
|
const active = state.revoked ? null : (await loadProgress()).current;
|
|
145
145
|
if (json) {
|
|
@@ -43,7 +43,10 @@ export const ownerLink = state => `${state.origin}/business/${encodeURIComponent
|
|
|
43
43
|
// folder scan has finished, that is the owner's scan permission for the folder
|
|
44
44
|
// connect ran in; afterwards it is the owner's next step in the browser.
|
|
45
45
|
export function waitingFor(state) {
|
|
46
|
+
if (state.localScan?.state === 'failed') return `This computer's scan failed. The owner can press Retry on Your tools: ${ownerLink(state)}/tools`;
|
|
47
|
+
if (state.localScan?.state === 'done') return `Waiting for the next task. Nothing needs this computer until the owner moves the plan forward: ${ownerLink(state)}`;
|
|
46
48
|
if (!state.discovered) {
|
|
49
|
+
if (state.localScan?.allowed) return `Waiting for this computer's allowed scan to run. Check its progress on Your tools: ${ownerLink(state)}/tools`;
|
|
47
50
|
const folder = state.workingFolder ?? process.cwd();
|
|
48
51
|
return `Waiting for the owner to allow scanning ${folder} (names only). They allow it on Your tools: ${ownerLink(state)}/tools`;
|
|
49
52
|
}
|
|
@@ -143,7 +146,7 @@ export async function next() {
|
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
148
|
const { toolId, vendorId, vendors } = classification(item);
|
|
146
|
-
process.stdout.write(`Agent: ${id}\nTool: ${toolId}\nSuggested vendor: ${vendorId}\nVendors: ${vendors.join(' | ')}\nSuggest how this tool is used. The owner confirms in the browser.\nUsage: ${classifications.join(' | ')}\nRun:
|
|
149
|
+
process.stdout.write(`Agent: ${id}\nTool: ${toolId}\nSuggested vendor: ${vendorId}\nVendors: ${vendors.join(' | ')}\nSuggest how this tool is used. The owner confirms in the browser.\nUsage: ${classifications.join(' | ')}\nRun: ${businessCommand(`answer ${id} <vendor_id|none> <usage> [confidence]`)}\n`);
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
export async function answer(id, vendorId, choice, rawConfidence = '1') {
|
package/cli/business/state.mjs
CHANGED
|
@@ -15,7 +15,10 @@ export function stateDirectory() {
|
|
|
15
15
|
if (chosen.includes('\0')) throw Error('RER_BUSINESS_STATE_DIR must name a folder.');
|
|
16
16
|
return resolve(chosen);
|
|
17
17
|
}
|
|
18
|
-
export const credentialHandle = origin => `device:${createHash('sha256').update(origin).digest('hex')}`;
|
|
18
|
+
export const credentialHandle = (origin, businessId) => `device:${createHash('sha256').update(businessId ? JSON.stringify([origin, businessId]) : origin).digest('hex')}`;
|
|
19
|
+
// Old pairing records still own the per-origin key, which disconnect revokes
|
|
20
|
+
// and removes once. New pairings never read or overwrite that legacy key.
|
|
21
|
+
export const deviceCredentialHandle = state => credentialHandle(state.origin, state.credentialVersion === 2 ? state.businessId : undefined);
|
|
19
22
|
|
|
20
23
|
async function loadJson(name) {
|
|
21
24
|
const path = join(stateDirectory(), name);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The immediate checkout folders shown by rer list. No recursive disk search.
|
|
2
|
+
import { readdir, realpath, stat } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
|
|
5
|
+
export async function checkoutFolders(directory) {
|
|
6
|
+
const folders = [];
|
|
7
|
+
for (const item of await readdir(directory, { withFileTypes: true })) {
|
|
8
|
+
const path = join(directory, item.name);
|
|
9
|
+
try {
|
|
10
|
+
if ((await stat(path)).isDirectory() && (await stat(join(path, 'OPERATIONS.json'))).isFile()) folders.push(await realpath(path));
|
|
11
|
+
} catch { /* Not a readable checkout, as in rer list. */ }
|
|
12
|
+
}
|
|
13
|
+
return [...new Set(folders)];
|
|
14
|
+
}
|