@origintrail-official/dkg-adapter-prime-agent 10.0.13

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.
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Bridge discovery.
3
+ *
4
+ * Prime Agent loads extensions per session, into the worker process that owns
5
+ * that session, so each live session binds its own loopback port. There is no
6
+ * single well-known endpoint to point the daemon at. The extension therefore
7
+ * publishes a descriptor file per session and removes it on shutdown; the
8
+ * daemon reads the directory and picks a live bridge.
9
+ *
10
+ * The staleness problem is real: a crashed worker never removes its file, and
11
+ * an OS may later hand the same port to an unrelated process. Two defences:
12
+ * 1. `pid` is recorded and checked with signal 0 before a descriptor is used;
13
+ * 2. `/health` echoes its `sessionId`, so the daemon can detect a descriptor
14
+ * that points at the wrong process even when the pid happens to be alive.
15
+ */
16
+ import { randomUUID } from 'node:crypto';
17
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
18
+ import { isIP } from 'node:net';
19
+ import { join } from 'node:path';
20
+ /** A session id may become a filename, so keep it to a conservative charset. */
21
+ const SAFE_SESSION_ID = /^[A-Za-z0-9._:-]{1,200}$/;
22
+ // A dead-pid descriptor younger than this is never pruned: it may be a live
23
+ // republication that landed (atomic rename, fresh mtime) between our read and
24
+ // the rm. Mirrored in the extension's start-time prune (`extension.ts`).
25
+ const PRUNE_MIN_AGE_MS = 30_000;
26
+ export function isSafeSessionId(sessionId) {
27
+ return SAFE_SESSION_ID.test(sessionId);
28
+ }
29
+ export function sessionDescriptorPath(sessionsDir, sessionId) {
30
+ if (!isSafeSessionId(sessionId)) {
31
+ throw new Error(`unsafe session id: ${JSON.stringify(sessionId.slice(0, 32))}`);
32
+ }
33
+ return join(sessionsDir, `${sessionId}.json`);
34
+ }
35
+ /** Called by the extension when its bridge is listening. */
36
+ export function writeSessionDescriptor(sessionsDir, descriptor) {
37
+ mkdirSync(sessionsDir, { recursive: true });
38
+ const path = sessionDescriptorPath(sessionsDir, descriptor.sessionId);
39
+ const temporaryPath = join(sessionsDir, `.${descriptor.sessionId}.${process.pid}.${randomUUID()}.tmp`);
40
+ try {
41
+ // Same-directory rename is atomic: readers see either the complete old
42
+ // descriptor or the complete new one, never a partially-written JSON file.
43
+ writeFileSync(temporaryPath, `${JSON.stringify(descriptor, null, 2)}\n`, {
44
+ mode: 0o600,
45
+ flag: 'wx',
46
+ });
47
+ renameSync(temporaryPath, path);
48
+ }
49
+ finally {
50
+ rmSync(temporaryPath, { force: true });
51
+ }
52
+ return path;
53
+ }
54
+ /** Called by the extension on session shutdown. Never throws. */
55
+ export function removeSessionDescriptor(sessionsDir, sessionId) {
56
+ try {
57
+ rmSync(sessionDescriptorPath(sessionsDir, sessionId), { force: true });
58
+ }
59
+ catch {
60
+ /* best effort: a leftover file is pruned by the reader's pid check */
61
+ }
62
+ }
63
+ export function isProcessAlive(pid) {
64
+ if (!Number.isInteger(pid) || pid <= 0)
65
+ return false;
66
+ try {
67
+ // Signal 0 performs permission and existence checks without delivering.
68
+ process.kill(pid, 0);
69
+ return true;
70
+ }
71
+ catch (err) {
72
+ // EPERM means the process exists but belongs to another user.
73
+ return err?.code === 'EPERM';
74
+ }
75
+ }
76
+ function isOlderThanPruneAge(path) {
77
+ try {
78
+ return Date.now() - statSync(path).mtimeMs >= PRUNE_MIN_AGE_MS;
79
+ }
80
+ catch {
81
+ return false; // already gone: nothing left to prune
82
+ }
83
+ }
84
+ function parseDescriptor(raw) {
85
+ try {
86
+ const parsed = JSON.parse(raw);
87
+ if (typeof parsed?.sessionId !== 'string' ||
88
+ typeof parsed?.bridgeUrl !== 'string' ||
89
+ typeof parsed?.pid !== 'number' ||
90
+ typeof parsed?.startedAt !== 'string') {
91
+ return null;
92
+ }
93
+ if (!isSafeSessionId(parsed.sessionId))
94
+ return null;
95
+ if (!isLoopbackBridgeUrl(parsed.bridgeUrl))
96
+ return null;
97
+ // A bad activity stamp invalidates only itself, not the descriptor: the
98
+ // file still names a live bridge, ordering just falls back to startedAt.
99
+ if (parsed.lastActiveAt !== undefined && typeof parsed.lastActiveAt !== 'string') {
100
+ delete parsed.lastActiveAt;
101
+ }
102
+ return parsed;
103
+ }
104
+ catch {
105
+ return null;
106
+ }
107
+ }
108
+ /**
109
+ * Loopback-only, mirroring the daemon's own rule for Hermes bridge targets. A
110
+ * descriptor is data written by another process; treat it as untrusted input.
111
+ */
112
+ export function isLoopbackBridgeUrl(value) {
113
+ if (!value)
114
+ return false;
115
+ try {
116
+ const { hostname, protocol } = new URL(value);
117
+ if (protocol !== 'http:' && protocol !== 'https:')
118
+ return false;
119
+ return (hostname === 'localhost' ||
120
+ hostname === '::1' ||
121
+ hostname === '[::1]' ||
122
+ (isIP(hostname) === 4 && hostname.startsWith('127.')));
123
+ }
124
+ catch {
125
+ return false;
126
+ }
127
+ }
128
+ /**
129
+ * Every descriptor currently on disk whose owning process is still alive.
130
+ * Stale files are pruned as a side effect so the directory cannot grow
131
+ * unbounded across crashes.
132
+ *
133
+ * Ordered most recently ACTIVE first, not most recently started: Prime Agent's
134
+ * daemon resumes sessions across terminal restarts, so a resumed session's
135
+ * descriptor can be newer than the fresh one the operator is actually using.
136
+ * Routing follows the session whose `lastActiveAt` moved last — that stamp is
137
+ * written per turn, so the operator's next turn settles the election.
138
+ */
139
+ export function readLiveSessions(sessionsDir, opts = {}) {
140
+ const prune = opts.prune ?? true;
141
+ if (!existsSync(sessionsDir))
142
+ return [];
143
+ const live = [];
144
+ let entries;
145
+ try {
146
+ entries = readdirSync(sessionsDir).filter((f) => f.endsWith('.json'));
147
+ }
148
+ catch {
149
+ return [];
150
+ }
151
+ for (const entry of entries) {
152
+ const full = join(sessionsDir, entry);
153
+ let descriptor = null;
154
+ try {
155
+ descriptor = parseDescriptor(readFileSync(full, 'utf8'));
156
+ }
157
+ catch {
158
+ descriptor = null;
159
+ }
160
+ // A parse failure may be a concurrent or externally-managed write. Skip it
161
+ // rather than deleting a descriptor whose ownership/liveness is unknown.
162
+ if (!descriptor)
163
+ continue;
164
+ if (!isProcessAlive(descriptor.pid)) {
165
+ // A dead pid alone does not justify deleting by path: a respawned
166
+ // session republishes a LIVE descriptor at this exact path via atomic
167
+ // rename, and that rename can land between our read and the rm. Only a
168
+ // file old enough that no republication can explain its mtime is
169
+ // removed; a wrongly deleted descriptor would be republished on that
170
+ // session's next agent_start anyway, so the failure mode self-heals.
171
+ if (prune && isOlderThanPruneAge(full))
172
+ rmSync(full, { force: true });
173
+ continue;
174
+ }
175
+ live.push(descriptor);
176
+ }
177
+ // Most recently active first; startedAt is both the fallback for descriptors
178
+ // written before lastActiveAt existed and the tiebreak, and sessionId keeps
179
+ // the order total so equal stamps cannot flap between reads.
180
+ live.sort((a, b) => (b.lastActiveAt ?? b.startedAt).localeCompare(a.lastActiveAt ?? a.startedAt) ||
181
+ b.startedAt.localeCompare(a.startedAt) ||
182
+ a.sessionId.localeCompare(b.sessionId));
183
+ return live;
184
+ }
185
+ /**
186
+ * Resolve which session a request should go to.
187
+ * - explicit id wins, and a miss is an error rather than a silent fallback;
188
+ * - exactly one live session is unambiguous;
189
+ * - several live sessions with no id selected is ambiguous by construction, so
190
+ * return the most recently active one but report it, letting the caller
191
+ * surface a choice.
192
+ */
193
+ export function selectSession(sessions, requestedSessionId) {
194
+ if (requestedSessionId) {
195
+ const match = sessions.find((s) => s.sessionId === requestedSessionId);
196
+ if (!match) {
197
+ return { ambiguous: false, error: `no live Prime Agent session with id ${requestedSessionId}` };
198
+ }
199
+ return { session: match, ambiguous: false };
200
+ }
201
+ if (sessions.length === 0) {
202
+ return { ambiguous: false, error: 'no live Prime Agent session' };
203
+ }
204
+ return { session: sessions[0], ambiguous: sessions.length > 1 };
205
+ }
206
+ //# sourceMappingURL=session-registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-registry.js","sourceRoot":"","sources":["../src/session-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,U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AAClE,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Setup lifecycle for the Prime Agent adapter.
3
+ *
4
+ * Prime Agent has no memory-provider slot to swap, so "election" here means
5
+ * registering our extension in `settings.json.extensions`. The ownership and
6
+ * reversal contract is copied from adapter-hermes deliberately, because it is
7
+ * the part that has to survive a SIGINT:
8
+ *
9
+ * 1. write setup-state.json carrying `priorSettings` (FIRST-WINS) ← intent
10
+ * 2. write settings.json.bak.<unix-ms> with the original bytes ← backup
11
+ * 3. rewrite settings.json adding our extension path ← destructive
12
+ *
13
+ * An interrupt between any two steps stays recoverable: a later run reads the
14
+ * persisted snapshot and can restore from the captured backup even if step 3
15
+ * never happened.
16
+ *
17
+ * One asymmetry versus Hermes: `priorMemoryProvider` is a scalar, ours is an
18
+ * array the user may legitimately edit between setup and disconnect. Restore is
19
+ * therefore *entry removal*, never wholesale replacement — otherwise we would
20
+ * silently revert unrelated user edits.
21
+ */
22
+ import type { PrimeAgentProfileMetadata, PrimeAgentPublishGuardPolicy, PrimeAgentRestoreRequest, PrimeAgentRestoreResult, PrimeAgentSetupPlan, PrimeAgentSetupRequest, PrimeAgentSetupResult, PrimeAgentSetupState, PrimeAgentVerifyResult } from './types.js';
23
+ export declare const MANAGED_BY = "@origintrail-official/dkg-adapter-prime-agent";
24
+ export declare const ADAPTER_STATE_DIRNAME = ".dkg-adapter-prime-agent";
25
+ export declare const SETUP_STATE_FILENAME = "setup-state.json";
26
+ export declare const ADAPTER_CONFIG_FILENAME = "dkg.json";
27
+ export declare const DEFAULT_DAEMON_URL = "http://127.0.0.1:9200";
28
+ export declare const DEFAULT_CONTEXT_GRAPH = "agent-context";
29
+ export declare const DEFAULT_MEMORY_ASSERTION = "memory";
30
+ /** Conservative by construction — see DESIGN.md §Q9. */
31
+ export declare const DEFAULT_PUBLISH_GUARD: PrimeAgentPublishGuardPolicy;
32
+ export interface PrimeAgentSetupOptions {
33
+ profileName?: string;
34
+ agentDir?: string;
35
+ memoryMode?: 'hooks' | 'tools-only';
36
+ daemonUrl?: string;
37
+ dkgHome?: string;
38
+ bridgeToken?: string;
39
+ contextGraph?: string;
40
+ memoryAssertion?: string;
41
+ preserveSettings?: boolean;
42
+ dryRun?: boolean;
43
+ /** Injectable for tests; defaults to the shipped extension file. */
44
+ extensionPath?: string;
45
+ }
46
+ /** `~/.prime/agent` unless PRIME_AGENT_CODING_AGENT_DIR overrides it. */
47
+ export declare function resolveAgentDir(explicit?: string): string;
48
+ /** Absolute path of the extension we register. Ships inside this package. */
49
+ export declare function defaultExtensionPath(): string;
50
+ export declare function resolvePrimeAgentProfile(options?: Pick<PrimeAgentSetupOptions, 'profileName' | 'agentDir' | 'memoryMode'>): PrimeAgentProfileMetadata;
51
+ interface PrimeSettings {
52
+ extensions?: string[];
53
+ [k: string]: unknown;
54
+ }
55
+ /** Resolve the same daemon credential used by the daemon-side channel route. */
56
+ export declare function loadDkgAuthToken(dkgHome?: string): string | undefined;
57
+ export declare function readSettings(settingsPath: string): PrimeSettings;
58
+ export declare function readSetupState(profile: PrimeAgentProfileMetadata): PrimeAgentSetupState | undefined;
59
+ /** Non-destructive: computes what setup would do. */
60
+ export declare function planPrimeAgentSetup(options?: PrimeAgentSetupOptions): PrimeAgentSetupPlan;
61
+ /**
62
+ * The destructive half. Ordering is the contract; see the module comment.
63
+ */
64
+ export declare function setupPrimeAgentProfile(options?: PrimeAgentSetupOptions): PrimeAgentSetupPlan;
65
+ /**
66
+ * Restore: surgical first (remove exactly our entry, leave unrelated user edits
67
+ * intact), backup-rename as fallback, then VERIFY the entry is really gone.
68
+ */
69
+ export declare function restorePrimeAgentProfile(req?: PrimeAgentRestoreRequest): PrimeAgentRestoreResult;
70
+ export declare function disconnectPrimeAgentProfile(options?: PrimeAgentSetupOptions): PrimeAgentSetupPlan;
71
+ export declare function verifyPrimeAgentProfile(options?: PrimeAgentSetupOptions): PrimeAgentVerifyResult;
72
+ /** Canonical orchestrator, mirroring runHermesSetup's role. */
73
+ export declare function runPrimeAgentSetup(req?: PrimeAgentSetupRequest): Promise<PrimeAgentSetupResult>;
74
+ export declare function runSetup(options?: PrimeAgentSetupRequest): Promise<void>;
75
+ export declare function runVerify(options?: PrimeAgentSetupOptions): Promise<void>;
76
+ export declare function runStatus(options?: PrimeAgentSetupOptions): Promise<void>;
77
+ export declare function runDoctor(options?: PrimeAgentSetupOptions): Promise<void>;
78
+ export declare function runDisconnect(options?: PrimeAgentSetupOptions): Promise<void>;
79
+ export declare function runReconnect(options?: PrimeAgentSetupOptions): Promise<void>;
80
+ export declare function runUninstall(options?: PrimeAgentSetupOptions): Promise<void>;
81
+ export declare const setup: typeof runSetup;
82
+ export declare const verify: typeof runVerify;
83
+ export declare const status: typeof runStatus;
84
+ export declare const doctor: typeof runDoctor;
85
+ export declare const disconnect: typeof runDisconnect;
86
+ export declare const reconnect: typeof runReconnect;
87
+ export declare const uninstall: typeof runUninstall;
88
+ export {};
89
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAmBH,OAAO,KAAK,EACV,yBAAyB,EACzB,4BAA4B,EAC5B,wBAAwB,EACxB,uBAAuB,EACvB,mBAAmB,EAEnB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAGpB,eAAO,MAAM,UAAU,kDAAkD,CAAC;AAC1E,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAChE,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAClD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAC1D,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AACrD,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAEjD,wDAAwD;AACxD,eAAO,MAAM,qBAAqB,EAAE,4BAMnC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