@agentpulselabs/cli-plugin-pulse 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -32
- package/package.json +10 -10
- package/src/commands/pulse/doctor.js +14 -0
- package/src/commands/pulse/hub-write.js +26 -0
- package/src/commands/pulse/install.js +14 -0
- package/src/commands/pulse/login.js +20 -0
- package/src/commands/pulse/mirror.js +27 -0
- package/src/commands/pulse/pair.js +38 -0
- package/src/commands/pulse/restart.js +14 -0
- package/src/commands/pulse/start.js +8 -18
- package/src/commands/pulse/status.js +8 -7
- package/src/commands/pulse/stop.js +24 -0
- package/src/daemon/main.js +36 -0
- package/src/lib/BaseCommand.js +37 -0
- package/src/lib/agentSessions.js +279 -0
- package/src/lib/application.js +656 -0
- package/src/lib/backoff.js +8 -0
- package/src/lib/budgets.js +85 -0
- package/src/lib/cliDefaults.js +20 -0
- package/src/lib/cloudAuth.js +189 -0
- package/src/lib/contract.sha256 +2 -0
- package/src/lib/daemonComposition.js +338 -0
- package/src/lib/daemonLock.js +55 -0
- package/src/lib/daemonLoop.js +69 -0
- package/src/lib/daemonProcess.js +366 -0
- package/src/lib/daemonRuntime.js +820 -0
- package/src/lib/drivers.js +280 -0
- package/src/lib/errors.js +19 -0
- package/src/lib/graphWindows.js +149 -0
- package/src/lib/http.js +84 -0
- package/src/lib/hubActions.js +74 -0
- package/src/lib/identity.js +102 -0
- package/src/lib/intents.js +590 -0
- package/src/lib/ledger.js +535 -0
- package/src/lib/lifecycle.js +123 -0
- package/src/lib/localHub.js +217 -0
- package/src/lib/localHubWriter.js +69 -0
- package/src/lib/mirror-contract.json +4299 -0
- package/src/lib/mirrorContract.js +513 -0
- package/src/lib/mirrorDaemon.js +127 -0
- package/src/lib/mirrorService.js +358 -0
- package/src/lib/mirrorSource.js +455 -0
- package/src/lib/mirrorSync.js +353 -0
- package/src/lib/oauthLogin.js +132 -0
- package/src/lib/ownerLock.js +99 -0
- package/src/lib/pairedConfig.js +40 -0
- package/src/lib/pairingLifecycle.js +179 -0
- package/src/lib/pathRedaction.js +89 -0
- package/src/lib/planContract.js +141 -0
- package/src/lib/priorityLane.js +80 -0
- package/src/lib/processOwnership.js +252 -0
- package/src/lib/processSupervisor.js +376 -0
- package/src/lib/redaction.js +128 -0
- package/src/lib/rootPolicy.js +372 -0
- package/src/lib/rulePacks.js +162 -0
- package/src/lib/secretStore.js +169 -0
- package/src/lib/selfRestart.js +261 -0
- package/src/lib/serviceManager.js +358 -0
- package/src/lib/storage.js +131 -0
- package/src/lib/subprocess.js +45 -0
- package/src/lib/tokenStore.js +97 -0
- package/src/lib/transport.js +286 -0
- package/src/lib/transportContract.js +37 -0
- package/src/commands/pulse/gate.js +0 -23
- package/src/commands/pulse/next.js +0 -13
- package/src/commands/pulse/submit.js +0 -19
- package/src/commands/pulse/verify.js +0 -18
- package/src/runPulse.js +0 -58
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createHash,
|
|
3
|
+
createPrivateKey,
|
|
4
|
+
createPublicKey,
|
|
5
|
+
generateKeyPairSync,
|
|
6
|
+
randomUUID,
|
|
7
|
+
} from 'node:crypto';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { HubError } from './errors.js';
|
|
10
|
+
import { readOwnerOnlyJson, writeOwnerOnlyJson } from './storage.js';
|
|
11
|
+
|
|
12
|
+
const IDENTITY_FILE = 'identity.json';
|
|
13
|
+
|
|
14
|
+
export function fingerprintPublicKey(rawPublicKey) {
|
|
15
|
+
return createHash('sha256').update(rawPublicKey).digest('hex');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createIdentityCandidate({ machineId, now = new Date() } = {}) {
|
|
19
|
+
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
|
|
20
|
+
const publicKeyDer = publicKey.export({ format: 'der', type: 'spki' });
|
|
21
|
+
const rawPublicKey = publicKeyDer.subarray(-32);
|
|
22
|
+
return {
|
|
23
|
+
identity: {
|
|
24
|
+
algorithm: 'Ed25519',
|
|
25
|
+
machineId: machineId || randomUUID(),
|
|
26
|
+
publicKeyEd25519: rawPublicKey.toString('base64url'),
|
|
27
|
+
fingerprint: fingerprintPublicKey(rawPublicKey),
|
|
28
|
+
secretRef: `device-key-${randomUUID()}`,
|
|
29
|
+
createdAt: now.toISOString(),
|
|
30
|
+
},
|
|
31
|
+
privateKeyPem: privateKey.export({ format: 'pem', type: 'pkcs8' }),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function persistIdentity({ configDir, identity }) {
|
|
36
|
+
const stored = {
|
|
37
|
+
algorithm: identity.algorithm,
|
|
38
|
+
machineId: identity.machineId,
|
|
39
|
+
publicKeyEd25519: identity.publicKeyEd25519,
|
|
40
|
+
fingerprint: identity.fingerprint,
|
|
41
|
+
secretRef: identity.secretRef,
|
|
42
|
+
createdAt: identity.createdAt,
|
|
43
|
+
};
|
|
44
|
+
await writeOwnerOnlyJson(path.join(configDir, IDENTITY_FILE), stored);
|
|
45
|
+
return stored;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export async function loadIdentity({ secretStore, configDir }) {
|
|
49
|
+
const identityFile = path.join(configDir, IDENTITY_FILE);
|
|
50
|
+
const existing = await readOwnerOnlyJson(identityFile);
|
|
51
|
+
if (!existing) {
|
|
52
|
+
const error = new Error('Pulse device identity is not installed.');
|
|
53
|
+
error.code = 'HUB_IDENTITY_NOT_INSTALLED';
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
const privateKey = await secretStore.get(existing.secretRef);
|
|
57
|
+
if (!privateKey) {
|
|
58
|
+
const error = new Error('Pulse device private key is missing from the operating-system secret store.');
|
|
59
|
+
error.code = 'HUB_IDENTITY_SECRET_MISSING';
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
let signerPublicKey;
|
|
63
|
+
try {
|
|
64
|
+
signerPublicKey = createPublicKey(createPrivateKey(privateKey))
|
|
65
|
+
.export({ format: 'der', type: 'spki' })
|
|
66
|
+
.subarray(-32);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
throw new HubError(
|
|
69
|
+
'HUB_IDENTITY_MISMATCH',
|
|
70
|
+
'Stored connector identity does not match its operating-system secret',
|
|
71
|
+
{ cause: error },
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
if (
|
|
75
|
+
existing.publicKeyEd25519 !== signerPublicKey.toString('base64url') ||
|
|
76
|
+
existing.fingerprint !== fingerprintPublicKey(signerPublicKey)
|
|
77
|
+
) {
|
|
78
|
+
throw new HubError(
|
|
79
|
+
'HUB_IDENTITY_MISMATCH',
|
|
80
|
+
'Stored connector identity does not match its operating-system secret',
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return { ...existing };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function loadOrCreateIdentity({ secretStore, configDir }) {
|
|
87
|
+
const identityFile = path.join(configDir, IDENTITY_FILE);
|
|
88
|
+
const existing = await readOwnerOnlyJson(identityFile);
|
|
89
|
+
if (existing) {
|
|
90
|
+
return loadIdentity({ secretStore, configDir });
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const { identity, privateKeyPem } = createIdentityCandidate();
|
|
94
|
+
await secretStore.set(identity.secretRef, privateKeyPem);
|
|
95
|
+
try {
|
|
96
|
+
await persistIdentity({ configDir, identity });
|
|
97
|
+
} catch (error) {
|
|
98
|
+
await secretStore.delete(identity.secretRef);
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
return identity;
|
|
102
|
+
}
|