ftown-bridge 0.30.48 → 0.30.49
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/dist/browser-access.js +1 -1
- package/dist/browser-access.js.map +1 -1
- package/dist/command-rpc.d.ts +1 -0
- package/dist/command-rpc.js +9 -1
- package/dist/command-rpc.js.map +1 -1
- package/dist/create-ftown-session.d.ts +5 -1
- package/dist/create-ftown-session.js +21 -27
- package/dist/create-ftown-session.js.map +1 -1
- package/dist/host-resources.d.ts +19 -0
- package/dist/host-resources.js +50 -0
- package/dist/host-resources.js.map +1 -0
- package/dist/index.js +47 -17
- package/dist/index.js.map +1 -1
- package/dist/local-api-server.d.ts +5 -1
- package/dist/local-api-server.js +38 -7
- package/dist/local-api-server.js.map +1 -1
- package/dist/peer-session-cache.d.ts +27 -0
- package/dist/peer-session-cache.js +76 -0
- package/dist/peer-session-cache.js.map +1 -0
- package/dist/peers-cli.js +20 -5
- package/dist/peers-cli.js.map +1 -1
- package/dist/security/bridge/permissions.js +6 -2
- package/dist/security/bridge/permissions.js.map +1 -1
- package/dist/security/bridge/security.d.ts +1 -0
- package/dist/security/bridge/security.js +8 -0
- package/dist/security/bridge/security.js.map +1 -1
- package/dist/session-controller.d.ts +1 -0
- package/dist/session-controller.js +25 -12
- package/dist/session-controller.js.map +1 -1
- package/dist/session-handoff.js +2 -0
- package/dist/session-handoff.js.map +1 -1
- package/dist/session-parent.d.ts +24 -0
- package/dist/session-parent.js +41 -0
- package/dist/session-parent.js.map +1 -0
- package/dist/sessions-commands.js +12 -6
- package/dist/sessions-commands.js.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/wire-types.d.ts +2 -0
- package/dist/wire-types.js.map +1 -1
- package/package.json +2 -2
- package/skills/ftown/SKILL.md +11 -8
- package/skills/ftown/references/orchestrator.md +6 -8
- package/skills/ftown/references/sessions.md +25 -2
package/dist/local-api-server.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { peerResources } from './host-resources.js';
|
|
1
2
|
import { TransferJournal } from './folder-transfer-journal.js';
|
|
2
3
|
import { FolderTransfers, transferError } from './folder-transfer.js';
|
|
3
4
|
import { TRANSFER_LOCAL, TRANSFER_WIRE } from './folder-transfer-protocol.js';
|
|
5
|
+
import { ParentLookupError, sessionRequestPrincipal } from './session-parent.js';
|
|
4
6
|
import { createServer } from 'node:http';
|
|
5
7
|
import { EventEmitter } from 'node:events';
|
|
6
8
|
import { timingSafeEqual } from 'node:crypto';
|
|
@@ -151,9 +153,13 @@ export class LocalApiServer extends EventEmitter {
|
|
|
151
153
|
localEventWaiters = new Set();
|
|
152
154
|
peerControl = null;
|
|
153
155
|
/** Cross-bridge control: forwards the local CLI's requests to other bridges of this account. */
|
|
156
|
+
hostResources;
|
|
157
|
+
rememberedPeerSessions;
|
|
154
158
|
peerLinks = null;
|
|
155
159
|
transfers = null;
|
|
156
|
-
setPeerControl(peers, links, transferStateDir) {
|
|
160
|
+
setPeerControl(peers, links, transferStateDir, remembered, hostResources) {
|
|
161
|
+
this.hostResources = hostResources;
|
|
162
|
+
this.rememberedPeerSessions = remembered;
|
|
157
163
|
this.peerControl = peers;
|
|
158
164
|
this.peerLinks = links ?? null;
|
|
159
165
|
this.transfers = new FolderTransfers(peers, transferStateDir ? new TransferJournal(transferStateDir) : undefined);
|
|
@@ -191,8 +197,21 @@ export class LocalApiServer extends EventEmitter {
|
|
|
191
197
|
return { status: 503, body: { error: 'Cross-bridge control is starting', code: 'peers_starting' } };
|
|
192
198
|
await this.security.revalidate(message.principal);
|
|
193
199
|
try {
|
|
200
|
+
if (url.pathname === '/api/peers/sessions' && method === 'GET') {
|
|
201
|
+
return { status: 200, body: applicationJson({ sessions: await this.rememberedPeerSessions?.() ?? [] }) };
|
|
202
|
+
}
|
|
194
203
|
if (url.pathname === '/api/peers' && method === 'GET') {
|
|
195
|
-
const
|
|
204
|
+
const control = this.peerControl;
|
|
205
|
+
const peers = await control.list(url.searchParams.get('probe') === '1');
|
|
206
|
+
if (url.searchParams.get('resources') === '1') {
|
|
207
|
+
const [resources, reports] = await Promise.all([
|
|
208
|
+
this.hostResources?.() ?? null,
|
|
209
|
+
Promise.all(peers.map(async (peer) => ({ ...peer, resources: await peerResources(control, peer.bridgeId) }))),
|
|
210
|
+
]);
|
|
211
|
+
await this.security.revalidate(message.principal);
|
|
212
|
+
const approved = new Set((await control.list()).map(peer => peer.endpointId));
|
|
213
|
+
return { status: 200, body: applicationJson({ bridgeId: this.security.bridgeId, resources, peers: reports.filter(peer => approved.has(peer.endpointId)) }) };
|
|
214
|
+
}
|
|
196
215
|
return { status: 200, body: applicationJson({ bridgeId: this.security.bridgeId, peers }) };
|
|
197
216
|
}
|
|
198
217
|
if (url.pathname === '/api/peers/http' && method === 'POST') {
|
|
@@ -268,6 +287,9 @@ export class LocalApiServer extends EventEmitter {
|
|
|
268
287
|
wake();
|
|
269
288
|
}
|
|
270
289
|
async dispatchSecure(message, clientGone) {
|
|
290
|
+
return sessionRequestPrincipal.run(message.principal, () => this.dispatchAuthorized(message, clientGone));
|
|
291
|
+
}
|
|
292
|
+
async dispatchAuthorized(message, clientGone) {
|
|
271
293
|
if (!this.security)
|
|
272
294
|
throw new Error('Security is starting');
|
|
273
295
|
const route = message.application.route;
|
|
@@ -279,6 +301,12 @@ export class LocalApiServer extends EventEmitter {
|
|
|
279
301
|
if (route.kind !== 'http')
|
|
280
302
|
throw new Error('Invalid application route');
|
|
281
303
|
const routePath = route.path.split('?')[0];
|
|
304
|
+
if (routePath === '/api/host-resources' && route.method === 'GET') {
|
|
305
|
+
await this.security.revalidate(message.principal);
|
|
306
|
+
if (!this.hostResources)
|
|
307
|
+
return { status: 503, body: { error: 'Host resources unavailable' } };
|
|
308
|
+
return { status: 200, body: applicationJson({ bridgeId: this.security.bridgeId, resources: await this.hostResources() }) };
|
|
309
|
+
}
|
|
282
310
|
if (routePath === TRANSFER_LOCAL || routePath === TRANSFER_WIRE)
|
|
283
311
|
return this.dispatchTransfer(message, routePath);
|
|
284
312
|
if (routePath === '/api/peers' || routePath.startsWith('/api/peers/'))
|
|
@@ -1108,7 +1136,7 @@ export class LocalApiServer extends EventEmitter {
|
|
|
1108
1136
|
return;
|
|
1109
1137
|
}
|
|
1110
1138
|
const message = err instanceof Error ? err.message : String(err);
|
|
1111
|
-
const status =
|
|
1139
|
+
const status = (err instanceof ParentLookupError || ['Parent session not found', 'Project name is required', 'Project name exceeds 256 characters'].includes(message)) ? 400 : 500;
|
|
1112
1140
|
jsonResponse(res, status, { error: message });
|
|
1113
1141
|
}
|
|
1114
1142
|
return;
|
|
@@ -1895,9 +1923,10 @@ export class LocalApiServer extends EventEmitter {
|
|
|
1895
1923
|
});
|
|
1896
1924
|
return;
|
|
1897
1925
|
}
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1926
|
+
let parentSessionId = tombstone.parentSessionId;
|
|
1927
|
+
const remoteParent = tombstone.parentBridgeId && tombstone.parentBridgeId !== tombstone.bridgeId;
|
|
1928
|
+
if (parentSessionId && !remoteParent && !await this.store.loadSession(parentSessionId))
|
|
1929
|
+
parentSessionId = undefined;
|
|
1901
1930
|
// Custom-command tombstones (command override at create time) must rerun
|
|
1902
1931
|
// their command verbatim — the builder would silently swap in a stock
|
|
1903
1932
|
// claude session. Builder-generated commands are rebuilt by
|
|
@@ -1907,6 +1936,8 @@ export class LocalApiServer extends EventEmitter {
|
|
|
1907
1936
|
try {
|
|
1908
1937
|
const session = await createFtownSession(this.sessionDeps, {
|
|
1909
1938
|
command: isCustomCommand ? tombstone.command : undefined,
|
|
1939
|
+
parentBridgeId: tombstone.parentBridgeId,
|
|
1940
|
+
projectName: tombstone.projectName || "Unassigned",
|
|
1910
1941
|
name: tombstone.name,
|
|
1911
1942
|
workingDir: tombstone.workingDir,
|
|
1912
1943
|
env: tombstone.env,
|
|
@@ -1964,7 +1995,7 @@ export class LocalApiServer extends EventEmitter {
|
|
|
1964
1995
|
}
|
|
1965
1996
|
const result = await controller.update(sessionId, {
|
|
1966
1997
|
...(name === undefined ? {} : { name }),
|
|
1967
|
-
...(hasParentField ? { parent: { value: body.parentSessionId } } : {}),
|
|
1998
|
+
...(hasParentField ? { parent: { value: body.parentSessionId, bridgeId: typeof body.parentBridgeId === "string" ? body.parentBridgeId : undefined } } : {}),
|
|
1968
1999
|
...(hasPullRequestField ? { pullRequestUrl: body.pullRequestUrl } : {}),
|
|
1969
2000
|
});
|
|
1970
2001
|
if (!result.ok) {
|