Skip to content

Commit ca7a10d

Browse files
rekmarksclaude
andcommitted
refactor: Rename background-kref to kref-presence for clarity
- Rename background-kref.ts to kref-presence.ts - Rename makeBackgroundKref to makePresenceManager - Rename BackgroundKref type to PresenceManager - Rename BackgroundKrefOptions to PresenceManagerOptions - Update all imports and references across affected packages - Update JSDoc comments to reflect new naming - All tests pass for kernel-browser-runtime, extension, omnium-gatherum Co-Authored-By: Claude <[email protected]>
1 parent 47faa60 commit ca7a10d

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

packages/extension/src/background.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { E } from '@endo/eventual-send';
22
import {
33
makeBackgroundCapTP,
4-
makeBackgroundKref,
4+
makePresenceManager,
55
makeCapTPNotification,
66
isCapTPNotification,
77
getCapTPMessage,
@@ -117,9 +117,9 @@ async function main(): Promise<void> {
117117
logger.info(result);
118118
};
119119

120-
// Create background kref system for E() calls on vat objects
121-
const bgKref = makeBackgroundKref({ kernelFacade: kernelP });
122-
Object.assign(globalThis.captp, bgKref);
120+
// Create presence manager for E() calls on vat objects
121+
const presenceManager = makePresenceManager({ kernelFacade: kernelP });
122+
Object.assign(globalThis.captp, presenceManager);
123123

124124
// Handle incoming CapTP messages from the kernel
125125
const drainPromise = offscreenStream.drain((message) => {

packages/extension/src/global.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {
2-
BackgroundKref,
2+
PresenceManager,
33
KernelFacade,
44
} from '@metamask/kernel-browser-runtime';
55

@@ -31,7 +31,7 @@ declare global {
3131
* ```
3232
*/
3333
// eslint-disable-next-line no-var
34-
var captp: BackgroundKref;
34+
var captp: PresenceManager;
3535
}
3636

3737
export {};

packages/kernel-browser-runtime/src/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ describe('index', () => {
1313
'getRelaysFromCurrentLocation',
1414
'isCapTPNotification',
1515
'makeBackgroundCapTP',
16-
'makeBackgroundKref',
1716
'makeCapTPNotification',
1817
'makeIframeVatWorker',
18+
'makePresenceManager',
1919
'parseRelayQueryString',
2020
'receiveInternalConnections',
2121
'rpcHandlers',

packages/kernel-browser-runtime/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export {
2222
type CapTPMessage,
2323
} from './background-captp.ts';
2424
export {
25-
makeBackgroundKref,
26-
type BackgroundKref,
27-
type BackgroundKrefOptions,
28-
} from './background-kref.ts';
25+
makePresenceManager,
26+
type PresenceManager,
27+
type PresenceManagerOptions,
28+
} from './kref-presence.ts';

packages/kernel-browser-runtime/src/background-kref.ts renamed to packages/kernel-browser-runtime/src/kref-presence.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Background kref system for creating E()-usable presences from kernel krefs.
2+
* Presence manager for creating E()-usable presences from kernel krefs.
33
*
44
* This module provides "slot translation" - converting kernel krefs (ko*, kp*)
55
* into presences that can receive eventual sends via E(). Method calls on these
@@ -24,9 +24,9 @@ type SendToKernelFn = (
2424
) => Promise<unknown>;
2525

2626
/**
27-
* Options for creating a background kref system.
27+
* Options for creating a presence manager.
2828
*/
29-
export type BackgroundKrefOptions = {
29+
export type PresenceManagerOptions = {
3030
/**
3131
* The kernel facade remote presence from CapTP.
3232
* Can be a promise since E() works with promises.
@@ -35,9 +35,9 @@ export type BackgroundKrefOptions = {
3535
};
3636

3737
/**
38-
* The background kref system interface.
38+
* The presence manager interface.
3939
*/
40-
export type BackgroundKref = {
40+
export type PresenceManager = {
4141
/**
4242
* Resolve a kref string to an E()-usable presence.
4343
*
@@ -137,26 +137,26 @@ function makeKrefPresence(
137137
}
138138

139139
/**
140-
* Create a background kref system for E() on vat objects.
140+
* Create a presence manager for E() on vat objects.
141141
*
142142
* This creates presences from kernel krefs that forward method calls
143143
* to kernel.queueMessage() via the existing CapTP connection.
144144
*
145145
* @param options - Options including the kernel facade.
146-
* @returns The background kref system.
146+
* @returns The presence manager.
147147
*/
148-
export function makeBackgroundKref(
149-
options: BackgroundKrefOptions,
150-
): BackgroundKref {
148+
export function makePresenceManager(
149+
options: PresenceManagerOptions,
150+
): PresenceManager {
151151
const { kernelFacade } = options;
152152

153153
// State for kref↔presence mapping
154154
const krefToPresence = new Map<KRef, object>();
155155
const presenceToKref = new WeakMap<object, KRef>();
156156

157-
// Forward declaration for sendToKernel (needs bgMarshal)
158-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, prefer-const
159-
let bgMarshal: any;
157+
// Forward declaration for sendToKernel
158+
// eslint-disable-next-line prefer-const
159+
let marshal: ReturnType<typeof makeMarshal<string>>;
160160

161161
/**
162162
* Send a message to the kernel and deserialize the result.
@@ -190,7 +190,7 @@ export function makeBackgroundKref(
190190
);
191191

192192
// Deserialize result (krefs become presences)
193-
return bgMarshal.fromCapData(result);
193+
return marshal.fromCapData(result);
194194
};
195195

196196
/**
@@ -232,9 +232,8 @@ export function makeBackgroundKref(
232232
throw new Error('Cannot serialize unknown remotable object');
233233
};
234234

235-
// Create marshal with smallcaps format (same as kernel)
236-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
237-
bgMarshal = makeMarshal(convertValToSlot, convertSlotToVal as any, {
235+
// Same options as kernel-marshal.ts
236+
marshal = makeMarshal(convertValToSlot, convertSlotToVal, {
238237
serializeBodyFormat: 'smallcaps',
239238
errorTagging: 'off',
240239
});
@@ -249,8 +248,8 @@ export function makeBackgroundKref(
249248
},
250249

251250
fromCapData: (data: CapData<KRef>): unknown => {
252-
return bgMarshal.fromCapData(data);
251+
return marshal.fromCapData(data);
253252
},
254253
});
255254
}
256-
harden(makeBackgroundKref);
255+
harden(makePresenceManager);

packages/omnium-gatherum/src/background.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { E } from '@endo/eventual-send';
22
import {
33
makeBackgroundCapTP,
4-
makeBackgroundKref,
4+
makePresenceManager,
55
makeCapTPNotification,
66
isCapTPNotification,
77
getCapTPMessage,
@@ -125,8 +125,8 @@ async function main(): Promise<void> {
125125
return kernelP;
126126
};
127127

128-
// Create background kref system for E() on vat objects
129-
const bgKref = makeBackgroundKref({ kernelFacade: kernelP });
128+
// Create presence manager for E() on vat objects
129+
const presenceManager = makePresenceManager({ kernelFacade: kernelP });
130130

131131
// Create storage adapter
132132
const storageAdapter = makeChromeStorageAdapter();
@@ -214,10 +214,10 @@ async function main(): Promise<void> {
214214
}),
215215
},
216216
resolveKref: {
217-
value: bgKref.resolveKref,
217+
value: presenceManager.resolveKref,
218218
},
219219
krefOf: {
220-
value: bgKref.krefOf,
220+
value: presenceManager.krefOf,
221221
},
222222
});
223223
harden(globalThis.omnium);

0 commit comments

Comments
 (0)