@jaromil/gestalt 0.16.0 → 0.16.1
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/lib/gestalt +178 -13
- package/package.json +2 -2
package/lib/gestalt
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
set -Eeuo pipefail
|
|
4
4
|
IFS=$'\n\t'
|
|
5
5
|
|
|
6
|
-
readonly GESTALT_CLI_VERSION='0.16.
|
|
6
|
+
readonly GESTALT_CLI_VERSION='0.16.1'
|
|
7
7
|
readonly DEFAULT_INSTALL_BASE_URL='https://dyne.github.io/gestalt'
|
|
8
8
|
readonly DEFAULT_MARKETPLACE='dyne/gestalt-agents'
|
|
9
9
|
readonly DEFAULT_MARKETPLACE_NAME='dyne-gestalt-agents'
|
|
@@ -119,10 +119,92 @@ function scratchJson(file) {
|
|
|
119
119
|
return JSON.parse(scratchFs.readFileSync(fd, 'utf8'));
|
|
120
120
|
} finally { scratchFs.closeSync(fd); }
|
|
121
121
|
}
|
|
122
|
+
function scratchRuntimeContainer() {
|
|
123
|
+
scratchAssert(typeof process.getuid === 'function');
|
|
124
|
+
return scratchPath.join(scratchFs.realpathSync('/tmp'), 'gs-' + process.getuid());
|
|
125
|
+
}
|
|
126
|
+
function scratchRuntimeIdentity(directory) {
|
|
127
|
+
scratchPrivate(directory);
|
|
128
|
+
const info = scratchFs.lstatSync(directory, {bigint:true});
|
|
129
|
+
return `${info.dev}:${info.ino}:${info.birthtimeNs}`;
|
|
130
|
+
}
|
|
131
|
+
function scratchRuntimeRecord(owner, runtime) {
|
|
132
|
+
return {schemaVersion:2,ownerId:owner.ownerId,workspacePath:owner.workspacePath,token:runtime.token,identity:runtime.identity};
|
|
133
|
+
}
|
|
134
|
+
function scratchAllocateRuntime(owner) {
|
|
135
|
+
const container = scratchRuntimeContainer();
|
|
136
|
+
try {scratchFs.mkdirSync(container,{mode:0o700});} catch(error) {if(error.code!=='EEXIST')throw error;}
|
|
137
|
+
scratchPrivate(container);
|
|
138
|
+
for(let attempt=0;attempt<16;attempt++) {
|
|
139
|
+
const directory=scratchPath.join(container,scratchCrypto.randomBytes(10).toString('hex'));
|
|
140
|
+
if(Buffer.byteLength(directory)>48)throw Error('SESSION_SCRATCH_RUNTIME_ROOT_TOO_LONG');
|
|
141
|
+
try {scratchFs.mkdirSync(directory,{mode:0o700});} catch(error) {if(error.code==='EEXIST')continue;throw error;}
|
|
142
|
+
const runtime={directory,token:scratchCrypto.randomBytes(32).toString('hex'),identity:scratchRuntimeIdentity(directory)};
|
|
143
|
+
scratchPublish(scratchPath.join(directory,'.gestalt-runtime.json'),scratchRuntimeRecord(owner,runtime),true);
|
|
144
|
+
return runtime;
|
|
145
|
+
}
|
|
146
|
+
throw Error('SESSION_SCRATCH_RUNTIME_COLLISION');
|
|
147
|
+
}
|
|
148
|
+
function scratchValidateRuntime(owner,runtime) {
|
|
149
|
+
const container=scratchRuntimeContainer();
|
|
150
|
+
scratchAssert(runtime && typeof runtime.directory==='string' && scratchPath.dirname(runtime.directory)===container &&
|
|
151
|
+
/^[0-9a-f]{20}$/.test(scratchPath.basename(runtime.directory)) && Buffer.byteLength(runtime.directory)<=48 &&
|
|
152
|
+
typeof runtime.token==='string' && /^[0-9a-f]{64}$/.test(runtime.token) &&
|
|
153
|
+
typeof runtime.identity==='string' && /^\d+:\d+:\d+$/.test(runtime.identity) && runtime.retiring===undefined);
|
|
154
|
+
scratchPrivate(container);
|
|
155
|
+
scratchAssert(scratchRuntimeIdentity(runtime.directory)===runtime.identity &&
|
|
156
|
+
JSON.stringify(scratchJson(scratchPath.join(runtime.directory,'.gestalt-runtime.json')))===JSON.stringify(scratchRuntimeRecord(owner,runtime)));
|
|
157
|
+
}
|
|
158
|
+
function scratchTemporaryDirectory(context) {return context.runtime?.directory ?? context.directory;}
|
|
159
|
+
function scratchSocketPath(endpoint,capacity=({linux:108,darwin:104})[process.platform]) {
|
|
160
|
+
if(!capacity)throw Error('UNIX_SOCKET_PLATFORM_UNSUPPORTED: no verified pathname capacity for this platform');
|
|
161
|
+
if(endpoint.includes('\0') || Buffer.byteLength(endpoint)+1>capacity)
|
|
162
|
+
throw Error('UNIX_SOCKET_PATH_TOO_LONG: shorten the endpoint name or temporary root');
|
|
163
|
+
return endpoint;
|
|
164
|
+
}
|
|
165
|
+
function scratchWorkspacePublication(workspace,publish) {
|
|
166
|
+
scratchCanonical(workspace);
|
|
167
|
+
const path=scratchPath.join(workspace,'.gestalt-scratch-lock');
|
|
168
|
+
let claimed=false;
|
|
169
|
+
for(let attempt=0;attempt<100;attempt++) {
|
|
170
|
+
try {scratchFs.mkdirSync(path,{mode:0o700});claimed=true;break;}
|
|
171
|
+
catch(error){if(error.code!=='EEXIST')throw error;Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,10);}
|
|
172
|
+
}
|
|
173
|
+
if(!claimed)throw Error('SESSION_SCRATCH_BUSY');
|
|
174
|
+
scratchPrivate(path);
|
|
175
|
+
const fd=scratchFs.openSync(path,scratchFs.constants.O_RDONLY|scratchFs.constants.O_DIRECTORY|scratchFs.constants.O_NOFOLLOW);
|
|
176
|
+
const held=scratchFs.fstatSync(fd,{bigint:true});
|
|
177
|
+
try {
|
|
178
|
+
const parents=scratchManagedAncestors(workspace).map(ancestor=>ancestor.context.workspacePath);
|
|
179
|
+
scratchCheckParentPublications(workspace,parents);
|
|
180
|
+
const result=publish();
|
|
181
|
+
scratchCheckParentPublications(workspace,parents);
|
|
182
|
+
return result;
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
try {
|
|
186
|
+
const current=scratchFs.lstatSync(path,{bigint:true});
|
|
187
|
+
scratchAssert(current.isDirectory() && !current.isSymbolicLink() && current.dev===held.dev && current.ino===held.ino && current.birthtimeNs===held.birthtimeNs);
|
|
188
|
+
scratchFs.rmdirSync(path);
|
|
189
|
+
} finally {scratchFs.closeSync(fd);}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function scratchCheckParentPublications(workspace,logicalParents=[]) {
|
|
193
|
+
const parents=new Set(logicalParents);let current=scratchPath.parse(workspace).root;
|
|
194
|
+
for(const part of workspace.slice(current.length).split(scratchPath.sep).filter(Boolean)) {
|
|
195
|
+
current=scratchPath.join(current,part);if(part==='tmp')parents.add(scratchPath.dirname(current));
|
|
196
|
+
}
|
|
197
|
+
parents.delete(workspace);
|
|
198
|
+
for(const parent of parents) {
|
|
199
|
+
try{scratchFs.lstatSync(scratchPath.join(parent,'.gestalt-scratch-lock'));}
|
|
200
|
+
catch(error){if(error.code==='ENOENT')continue;throw error;}
|
|
201
|
+
throw Error('SESSION_SCRATCH_BUSY');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
122
204
|
function scratchContext(environment = process.env, allowReleased = false) {
|
|
123
205
|
if (!Object.hasOwn(environment, scratchVariable)) return null;
|
|
124
206
|
const context = JSON.parse(environment[scratchVariable]);
|
|
125
|
-
scratchAssert(context?.schemaVersion
|
|
207
|
+
scratchAssert([1,2].includes(context?.schemaVersion) && scratchId(context.ownerId));
|
|
126
208
|
scratchCanonical(context.workspacePath);
|
|
127
209
|
const container = scratchPath.join(context.workspacePath, 'tmp', 'sessions');
|
|
128
210
|
scratchAssert(context.directory === scratchPath.join(container, context.ownerId) &&
|
|
@@ -135,11 +217,15 @@ function scratchContext(environment = process.env, allowReleased = false) {
|
|
|
135
217
|
scratchAssert(!process.getuid || scratchFs.lstatSync(parent).uid === process.getuid());
|
|
136
218
|
for (const directory of [container, context.directory]) scratchPrivate(directory);
|
|
137
219
|
const marker = scratchJson(context.markerPath);
|
|
138
|
-
scratchAssert(marker?.schemaVersion ===
|
|
220
|
+
scratchAssert(marker?.schemaVersion === context.schemaVersion && marker.ownerId === context.ownerId &&
|
|
139
221
|
marker.workspacePath === context.workspacePath && scratchId(marker.sessionId) &&
|
|
140
222
|
typeof marker.createdAt === 'string' && Number.isFinite(Date.parse(marker.createdAt)) &&
|
|
141
223
|
Array.isArray(marker.providerThreads) && marker.providerThreads.every(thread =>
|
|
142
224
|
['codex', 'kimi'].includes(thread?.provider) && scratchId(thread.threadId)));
|
|
225
|
+
if(context.schemaVersion===2) {
|
|
226
|
+
scratchAssert(JSON.stringify(context.runtime)===JSON.stringify(marker.runtime));
|
|
227
|
+
scratchValidateRuntime(marker,marker.runtime);
|
|
228
|
+
} else scratchAssert(context.runtime===undefined && marker.runtime===undefined);
|
|
143
229
|
if (marker.ownerKind === 'mobile-session') {
|
|
144
230
|
scratchAssert(context.ownerId === 'mobile-' + scratchCrypto.createHash('sha256').update(marker.sessionId).digest('hex') &&
|
|
145
231
|
marker.authority?.kind === 'mobile-roster' && marker.authority.sessionId === marker.sessionId);
|
|
@@ -160,7 +246,8 @@ function scratchContext(environment = process.env, allowReleased = false) {
|
|
|
160
246
|
}
|
|
161
247
|
function scratchEnvironment(environment = process.env) {
|
|
162
248
|
const context = scratchContext(environment);
|
|
163
|
-
|
|
249
|
+
const directory=context && scratchTemporaryDirectory(context);
|
|
250
|
+
return context ? { ...environment, TMPDIR: directory, TMP: directory, TEMP: directory } : { ...environment };
|
|
164
251
|
}
|
|
165
252
|
function scratchDiscoveryEnvironment(environment = process.env) {
|
|
166
253
|
const result = { ...environment };
|
|
@@ -189,7 +276,10 @@ function scratchContainer(workspace) {
|
|
|
189
276
|
}
|
|
190
277
|
function scratchOwnerContext(workspace, ownerId) {
|
|
191
278
|
const directory = scratchPath.join(workspace, 'tmp', 'sessions', ownerId);
|
|
192
|
-
|
|
279
|
+
const context={schemaVersion:1,workspacePath:workspace,ownerId,directory,markerPath:scratchPath.join(directory,'.gestalt-owner.json')};
|
|
280
|
+
try {const marker=scratchJson(context.markerPath);if(marker.schemaVersion===2){context.schemaVersion=2;context.runtime=marker.runtime;}}
|
|
281
|
+
catch(error){if(error.code!=='ENOENT')throw error;}
|
|
282
|
+
return context;
|
|
193
283
|
}
|
|
194
284
|
function scratchLeaseRecords(context) {
|
|
195
285
|
const directory = scratchPath.join(context.directory, 'leases');
|
|
@@ -225,20 +315,34 @@ function scratchAncestorOwner(context) {
|
|
|
225
315
|
return {
|
|
226
316
|
context, identity: scratchDirectoryIdentity(context.directory),
|
|
227
317
|
provenance: JSON.stringify([marker.schemaVersion, marker.ownerKind, marker.ownerId, marker.workspacePath,
|
|
228
|
-
marker.sessionId, marker.createdAt, marker.authority.kind, marker.authority.sessionId ?? null, marker.authority.leaseId ?? null]),
|
|
318
|
+
marker.sessionId, marker.createdAt, marker.authority.kind, marker.authority.sessionId ?? null, marker.authority.leaseId ?? null, marker.runtime ?? null]),
|
|
229
319
|
};
|
|
230
320
|
}
|
|
231
|
-
function scratchManagedAncestors(workspace) {
|
|
321
|
+
function scratchManagedAncestors(workspace, ancestors=[], visiting=new Set()) {
|
|
322
|
+
scratchAssert(!visiting.has(workspace) && visiting.size<64);
|
|
323
|
+
visiting.add(workspace);
|
|
232
324
|
const parts = workspace.slice(scratchPath.parse(workspace).root.length).split(scratchPath.sep).filter(Boolean);
|
|
233
|
-
const
|
|
325
|
+
const runtimeBase=process.getuid?scratchRuntimeContainer():undefined;
|
|
234
326
|
let directory = scratchPath.parse(workspace).root;
|
|
235
327
|
for (let i = 0; i < parts.length; i++) {
|
|
236
328
|
directory = scratchPath.join(directory, parts[i]);
|
|
329
|
+
if(runtimeBase && scratchPath.dirname(directory)===runtimeBase) {
|
|
330
|
+
scratchPrivate(directory);
|
|
331
|
+
const locator=scratchJson(scratchPath.join(directory,'.gestalt-runtime.json'));
|
|
332
|
+
scratchAssert(typeof locator.workspacePath==='string' && scratchId(locator.ownerId));
|
|
333
|
+
const owner=scratchOwnerContext(locator.workspacePath,locator.ownerId);
|
|
334
|
+
scratchContext({[scratchVariable]:JSON.stringify(owner)},true);
|
|
335
|
+
scratchAssert(owner.runtime?.directory===directory);
|
|
336
|
+
scratchManagedAncestors(owner.directory,ancestors,visiting);
|
|
337
|
+
}
|
|
237
338
|
if (i >= 2 && parts[i - 1] === 'sessions' && parts[i - 2] === 'tmp') {
|
|
339
|
+
if(ancestors.some(ancestor=>ancestor.context.directory===directory))continue;
|
|
340
|
+
scratchAssert(ancestors.length<64);
|
|
238
341
|
const ownerWorkspace = scratchPath.dirname(scratchPath.dirname(scratchPath.dirname(directory)));
|
|
239
342
|
ancestors.push(scratchAncestorOwner(scratchOwnerContext(ownerWorkspace, parts[i])));
|
|
240
343
|
}
|
|
241
344
|
}
|
|
345
|
+
visiting.delete(workspace);
|
|
242
346
|
return ancestors;
|
|
243
347
|
}
|
|
244
348
|
function scratchRevalidateAncestor(ancestor) {
|
|
@@ -333,9 +437,38 @@ function scratchRecoverToolLeases(workspace, ownerId, token) {
|
|
|
333
437
|
{...lease, state: 'released', consumers: [], updatedAt: new Date().toISOString()});
|
|
334
438
|
}
|
|
335
439
|
}
|
|
440
|
+
// Offline-only publication recovery also works when allocation never reached an owner.
|
|
441
|
+
function scratchPublicationSnapshot(workspace) {
|
|
442
|
+
scratchCanonical(workspace);
|
|
443
|
+
const path=scratchPath.join(workspace,'.gestalt-scratch-lock');
|
|
444
|
+
scratchPrivate(path);
|
|
445
|
+
scratchAssert(scratchFs.readdirSync(path).length===0);
|
|
446
|
+
const expected=scratchDirectoryIdentity(path);
|
|
447
|
+
const token=scratchCrypto.createHash('sha256').update(JSON.stringify({
|
|
448
|
+
workspace:scratchDirectoryIdentity(workspace),lock:expected,
|
|
449
|
+
ancestors:scratchManagedAncestors(workspace).map(ancestor=>({
|
|
450
|
+
owner:ancestor.provenance,identity:ancestor.identity,
|
|
451
|
+
leases:scratchFs.existsSync(scratchPath.join(ancestor.context.directory,'leases'))
|
|
452
|
+
? scratchLeaseRecords(ancestor.context).sort((a,b)=>a.leaseId.localeCompare(b.leaseId)):[],
|
|
453
|
+
})),
|
|
454
|
+
},(_,value)=>typeof value==='bigint'?value.toString():value)).digest('hex');
|
|
455
|
+
return {path,expected,token};
|
|
456
|
+
}
|
|
457
|
+
function scratchRecoverPublication(workspace,token) {
|
|
458
|
+
scratchAssert(typeof token==='string' && /^[a-f0-9]{64}$/.test(token));
|
|
459
|
+
const snapshot=scratchPublicationSnapshot(workspace);
|
|
460
|
+
if(snapshot.token!==token)throw Error('SESSION_SCRATCH_RECOVERY_SNAPSHOT_CHANGED');
|
|
461
|
+
const fd=scratchFs.openSync(snapshot.path,scratchFs.constants.O_RDONLY|scratchFs.constants.O_DIRECTORY|scratchFs.constants.O_NOFOLLOW);
|
|
462
|
+
try {
|
|
463
|
+
const held=scratchFs.fstatSync(fd,{bigint:true});
|
|
464
|
+
scratchAssert(scratchSameDirectory(snapshot.expected,{dev:held.dev,ino:held.ino,birth:held.birthtimeNs}));
|
|
465
|
+
if(scratchPublicationSnapshot(workspace).token!==token)throw Error('SESSION_SCRATCH_RECOVERY_SNAPSHOT_CHANGED');
|
|
466
|
+
scratchFs.rmdirSync(snapshot.path);
|
|
467
|
+
} finally {scratchFs.closeSync(fd);}
|
|
468
|
+
}
|
|
336
469
|
function scratchRecoveryCommand(args) {
|
|
337
470
|
const [action, ...options] = args;
|
|
338
|
-
scratchAssert(['inspect', 'recover', 'inspect-tool-leases', 'recover-tool-leases'].includes(action));
|
|
471
|
+
scratchAssert(['inspect', 'recover', 'inspect-tool-leases', 'recover-tool-leases', 'inspect-publication', 'recover-publication'].includes(action));
|
|
339
472
|
const values = {};
|
|
340
473
|
let confirmed = false;
|
|
341
474
|
for (let index = 0; index < options.length; index++) {
|
|
@@ -345,7 +478,18 @@ function scratchRecoveryCommand(args) {
|
|
|
345
478
|
scratchAssert(typeof options[index + 1] === 'string' && !options[index + 1].startsWith('--'));
|
|
346
479
|
values[name] = options[++index];
|
|
347
480
|
}
|
|
348
|
-
scratchAssert(values['--cwd'] && values['--owner']);
|
|
481
|
+
scratchAssert(values['--cwd'] && (action.endsWith('-publication') ? !values['--owner'] : values['--owner']));
|
|
482
|
+
if(action.endsWith('-publication')) {
|
|
483
|
+
if(action==='inspect-publication') {
|
|
484
|
+
scratchAssert(!confirmed && !values['--expect']);
|
|
485
|
+
process.stdout.write(JSON.stringify({schemaVersion:1,status:'confirmationRequired',token:scratchPublicationSnapshot(values['--cwd']).token})+'\n');
|
|
486
|
+
} else {
|
|
487
|
+
scratchAssert(confirmed && values['--expect']);
|
|
488
|
+
scratchRecoverPublication(values['--cwd'],values['--expect']);
|
|
489
|
+
process.stdout.write(JSON.stringify({schemaVersion:1,status:'recovered'})+'\n');
|
|
490
|
+
}
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
349
493
|
if (action === 'inspect' || action === 'inspect-tool-leases') {
|
|
350
494
|
scratchAssert(!confirmed && !values['--expect']);
|
|
351
495
|
const snapshot = action === 'inspect' ? scratchContainmentSnapshot(values['--cwd'], values['--owner'])
|
|
@@ -360,6 +504,7 @@ function scratchRecoveryCommand(args) {
|
|
|
360
504
|
}
|
|
361
505
|
}
|
|
362
506
|
function scratchWithContainment(workspace, publish) {
|
|
507
|
+
return scratchWorkspacePublication(workspace,()=>{
|
|
363
508
|
scratchCanonical(workspace);
|
|
364
509
|
const selected = scratchDirectoryIdentity(workspace), ancestors = scratchManagedAncestors(workspace), claims = [];
|
|
365
510
|
try {
|
|
@@ -402,6 +547,7 @@ function scratchWithContainment(workspace, publish) {
|
|
|
402
547
|
}
|
|
403
548
|
if (failure) throw failure;
|
|
404
549
|
}
|
|
550
|
+
});
|
|
405
551
|
}
|
|
406
552
|
function scratchAllocate(workspace,kind,consumer) {
|
|
407
553
|
scratchAssert(['cli-session','workspace-service'].includes(kind)&&scratchId(consumer));
|
|
@@ -414,6 +560,10 @@ function scratchAllocate(workspace,kind,consumer) {
|
|
|
414
560
|
const leaseId=scratchCrypto.randomUUID(),time=new Date().toISOString();
|
|
415
561
|
const lease={schemaVersion:1,ownerId,workspacePath:workspace,leaseId,state:'active',processIdentity:scratchCrypto.randomUUID(),createdAt:time,updatedAt:time,consumers:[consumer]};
|
|
416
562
|
const marker={schemaVersion:1,ownerKind:kind,ownerId,workspacePath:workspace,sessionId:ownerId,createdAt:time,authority:{kind:'lease',leaseId},providerThreads:[]};
|
|
563
|
+
if(process.platform!=='win32') {
|
|
564
|
+
marker.schemaVersion=2;marker.runtime=scratchAllocateRuntime(marker);
|
|
565
|
+
context.schemaVersion=2;context.runtime=marker.runtime;
|
|
566
|
+
}
|
|
417
567
|
scratchPublish(scratchPath.join(context.directory,'leases',leaseId+'.json'),lease,true);scratchPublish(context.markerPath,marker,true);
|
|
418
568
|
scratchContext({[scratchVariable]:JSON.stringify(context)});return {context,lease,lock};
|
|
419
569
|
});
|
|
@@ -437,6 +587,7 @@ function scratchRelease(ownership) {
|
|
|
437
587
|
});
|
|
438
588
|
}
|
|
439
589
|
function scratchMetadata(context, operation, waitMs = 0) {
|
|
590
|
+
return scratchWorkspacePublication(context.workspacePath,()=>{
|
|
440
591
|
scratchContext({[scratchVariable]: JSON.stringify(context)});
|
|
441
592
|
const mobile = scratchJson(context.markerPath).ownerKind === 'mobile-session';
|
|
442
593
|
// Mobile cleanup/association use this same controller fence. CLI/service
|
|
@@ -457,6 +608,7 @@ function scratchMetadata(context, operation, waitMs = 0) {
|
|
|
457
608
|
if (mobile) scratchAssert(!scratchFs.existsSync(scratchPath.join(context.directory, '.association-lock')));
|
|
458
609
|
return operation();
|
|
459
610
|
} finally {scratchFs.rmdirSync(lock);}
|
|
611
|
+
});
|
|
460
612
|
}
|
|
461
613
|
function scratchBorrow(context, consumer) {
|
|
462
614
|
scratchAssert(scratchId(consumer));
|
|
@@ -633,7 +785,7 @@ async function scratchCli(manager, args) {
|
|
|
633
785
|
}
|
|
634
786
|
// END SESSION SCRATCH RUNTIME
|
|
635
787
|
if (process.argv[1] === 'validate') {
|
|
636
|
-
try {const context = scratchContext(); process.stdout.write(scratchJson(context.markerPath).ownerKind + '\n' + context
|
|
788
|
+
try {const context = scratchContext(); process.stdout.write(scratchJson(context.markerPath).ownerKind + '\n' + scratchTemporaryDirectory(context));}
|
|
637
789
|
catch { process.stderr.write('gestalt: invalid managed session temporary context\n'); process.exitCode = 1; }
|
|
638
790
|
}
|
|
639
791
|
if (process.argv[1] === 'scratch') {
|
|
@@ -4365,8 +4517,12 @@ async function managedPlaywright(launchArgs, reportDiagnostic = () => {}, checkC
|
|
|
4365
4517
|
const {constants} = await import('node:fs');
|
|
4366
4518
|
const {join} = await import('node:path');
|
|
4367
4519
|
const endpoint = join(directory, 'frontend.sock');
|
|
4368
|
-
|
|
4520
|
+
const capacity = ({linux:108,darwin:104})[process.platform];
|
|
4521
|
+
if (!capacity) throw new Error('UNIX_SOCKET_PLATFORM_UNSUPPORTED: no verified pathname capacity for this platform');
|
|
4522
|
+
if (Buffer.byteLength(endpoint) + 1 <= capacity)
|
|
4369
4523
|
return {endpoint, address:endpoint, close:async () => {}};
|
|
4524
|
+
if (process.platform !== 'linux')
|
|
4525
|
+
throw new Error('UNIX_SOCKET_PATH_TOO_LONG: use a bounded managed runtime root or shorten the endpoint name');
|
|
4370
4526
|
const handle = await fs.open(directory, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
4371
4527
|
try {
|
|
4372
4528
|
const info = await handle.stat();
|
|
@@ -4376,6 +4532,8 @@ async function managedPlaywright(launchArgs, reportDiagnostic = () => {}, checkC
|
|
|
4376
4532
|
// Keep the actual socket in its private owner. Linux resolves this short
|
|
4377
4533
|
// descriptor address to that same directory for bind and native connect.
|
|
4378
4534
|
const address = `/proc/${process.pid}/fd/${handle.fd}/frontend.sock`;
|
|
4535
|
+
if (Buffer.byteLength(address) + 1 > capacity)
|
|
4536
|
+
throw new Error('UNIX_SOCKET_PATH_TOO_LONG: shorten the endpoint name');
|
|
4379
4537
|
const target = await fs.stat(`/proc/${process.pid}/fd/${handle.fd}`);
|
|
4380
4538
|
if (target.dev !== info.dev || target.ino !== info.ino) throw new Error('managed-browser-socket-directory-changed');
|
|
4381
4539
|
return {endpoint, address, close:() => handle.close()};
|
|
@@ -4814,7 +4972,11 @@ if (playwrightConsent && interactivePlaywright && playwrightSkill && playwrightR
|
|
|
4814
4972
|
!playwrightConfig.env && !playwrightConfig.env_vars?.length) {
|
|
4815
4973
|
playwrightController = async launchArgs => {
|
|
4816
4974
|
try { return await managedPlaywright(launchArgs, undefined, refreshPlaywrightConsent); }
|
|
4817
|
-
catch {
|
|
4975
|
+
catch (error) {
|
|
4976
|
+
if (error?.message?.startsWith('UNIX_SOCKET_PATH_TOO_LONG'))
|
|
4977
|
+
process.stderr.write('gestalt: Unix socket pathname exceeds the platform byte limit; create a new v2 session or shorten the endpoint name.\n');
|
|
4978
|
+
if (error?.message?.startsWith('UNIX_SOCKET_PLATFORM_UNSUPPORTED'))
|
|
4979
|
+
process.stderr.write('gestalt: no verified Unix socket pathname capacity for this platform.\n');
|
|
4818
4980
|
playwrightNotice('managed-runtime-unavailable'); playwrightController = undefined;
|
|
4819
4981
|
return launch(['--no-daemon', ...launchArgs]);
|
|
4820
4982
|
}
|
|
@@ -5724,6 +5886,9 @@ main() {
|
|
|
5724
5886
|
'gestalt scratch inspect-tool-leases --cwd ROOT --owner ID' \
|
|
5725
5887
|
'gestalt scratch recover-tool-leases --cwd ROOT --owner ID --expect TOKEN --confirm-quiescent' \
|
|
5726
5888
|
'Use the token from inspect-tool-leases to release abandoned Mobile Serena/Playwright borrowers.' \
|
|
5889
|
+
'gestalt scratch inspect-publication --cwd ROOT' \
|
|
5890
|
+
'gestalt scratch recover-publication --cwd ROOT --expect TOKEN --confirm-quiescent' \
|
|
5891
|
+
'Use the token from inspect-publication to clear an abandoned empty workspace publication fence.' \
|
|
5727
5892
|
'Never use these overrides on a live session. Payload and provider history are retained.'
|
|
5728
5893
|
else
|
|
5729
5894
|
require_command node
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaromil/gestalt",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Manage Gestalt's isolated Codex profile, agent skills and Mobile installation",
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"author": "Dyne.org foundation",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"access": "public",
|
|
43
43
|
"registry": "https://registry.npmjs.org/"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "cdfd254efa475f1e959a7bb64b49777e4ae5d8ce"
|
|
46
46
|
}
|