@waffle-os/runtime 0.0.156 → 0.0.157

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.
Files changed (75) hide show
  1. package/browser/filesystem-backend.ts +11 -1
  2. package/browser/preview-protocol.ts +2 -0
  3. package/browser/preview.ts +128 -18
  4. package/browser/runtime-terminals.ts +65 -24
  5. package/browser/shared-fs.ts +141 -14
  6. package/browser/worker.ts +73 -6
  7. package/core/descriptors.ts +19 -2
  8. package/core/devices.ts +237 -2
  9. package/core/fd-reopen.ts +105 -20
  10. package/core/filesystem.ts +71 -0
  11. package/core/index.ts +4 -0
  12. package/core/open-file.ts +212 -18
  13. package/core/wasi.ts +397 -46
  14. package/dist/browser/filesystem-backend.js +4 -2
  15. package/dist/browser/preview.js +120 -17
  16. package/dist/browser/runtime-terminals.js +53 -10
  17. package/dist/browser/shared-fs.js +124 -11
  18. package/dist/browser/worker.js +59 -6
  19. package/dist/core/descriptors.js +9 -1
  20. package/dist/core/devices.js +211 -1
  21. package/dist/core/fd-reopen.js +79 -18
  22. package/dist/core/filesystem.js +13 -0
  23. package/dist/core/open-file.js +166 -13
  24. package/dist/core/wasi.js +353 -27
  25. package/dist/fs/backend.js +29 -2
  26. package/dist/fs/client.js +199 -6
  27. package/dist/fs/index.js +21 -1
  28. package/dist/fs/indexeddb.js +30 -2
  29. package/dist/fs/locks.js +1112 -0
  30. package/dist/fs/memory.js +109 -1
  31. package/dist/fs/multitab-backend.js +315 -195
  32. package/dist/fs/multitab-protocol.js +1 -0
  33. package/dist/fs/persistent.js +13 -6
  34. package/dist/fs/protocol.js +9 -3
  35. package/dist/fs/service.js +386 -22
  36. package/dist/fs/shared.js +54 -1
  37. package/dist/fs/storage-geometry.js +2 -0
  38. package/dist/interrupt/rewriter-internal.js +4 -1
  39. package/dist/proc/abi.js +80 -6
  40. package/dist/proc/errors.js +1 -0
  41. package/dist/proc/filesystem-codec.js +40 -9
  42. package/dist/proc/index.js +10 -1
  43. package/dist/proc/pty.js +193 -0
  44. package/dist/proc/worker-client.js +11 -2
  45. package/dist/proc/worker-pipes.js +51 -0
  46. package/dist/runtime.js +11 -2
  47. package/dist/search/engine.js +53 -0
  48. package/dist/tooling/program/program-transformer.json +1 -1
  49. package/fs/backend.ts +33 -1
  50. package/fs/client.ts +225 -6
  51. package/fs/index.ts +22 -1
  52. package/fs/indexeddb.ts +36 -2
  53. package/fs/locks.ts +1406 -0
  54. package/fs/memory.ts +114 -1
  55. package/fs/multitab-backend.ts +561 -303
  56. package/fs/multitab-protocol.ts +1 -0
  57. package/fs/persistent.ts +14 -3
  58. package/fs/protocol.ts +17 -5
  59. package/fs/service.ts +468 -23
  60. package/fs/shared.ts +60 -2
  61. package/fs/storage-geometry.ts +3 -0
  62. package/index.ts +2 -0
  63. package/interrupt/rewriter-internal.ts +4 -1
  64. package/package.json +2 -2
  65. package/proc/abi.ts +79 -6
  66. package/proc/errors.ts +1 -0
  67. package/proc/filesystem-codec.ts +39 -9
  68. package/proc/index.ts +11 -0
  69. package/proc/pty.ts +227 -0
  70. package/proc/worker-client.ts +28 -6
  71. package/proc/worker-pipes.ts +57 -0
  72. package/runtime.ts +12 -2
  73. package/search/engine.ts +49 -0
  74. package/testing/indexeddb-storage-browser.ts +173 -2
  75. package/tooling/program/program-transformer.json +1 -1
@@ -186,6 +186,7 @@ const PURE_STATELESS_READ_OPS = new Set<string>([
186
186
  "lookup",
187
187
  "listFiles",
188
188
  "resolvePath",
189
+ "statPath",
189
190
  "stat",
190
191
  "permissions",
191
192
  "read",
package/fs/persistent.ts CHANGED
@@ -103,8 +103,9 @@ export class PersistentBackend extends MemoryBackend {
103
103
  private readonly dirtyLimits: Partial<DirtyLimits> | false = {},
104
104
  startupRoot?: MemoryBudget,
105
105
  sharedRoot?: MemoryBackendSharedRoot,
106
+ machineId?: string,
106
107
  ) {
107
- super(fs, reservation, startupRoot, undefined, sharedRoot);
108
+ super(fs, reservation, startupRoot, undefined, sharedRoot, machineId);
108
109
  this.initialWorkspaceId = reservation.workspace;
109
110
  this.initialEra = reservation.era;
110
111
  this.loadedIndex = index !== undefined;
@@ -180,7 +181,10 @@ export class PersistentBackend extends MemoryBackend {
180
181
  return this.storage.terminalFailureReason?.();
181
182
  }
182
183
  setTerminalFailureListener(listener: (reason: unknown) => void): void {
183
- this.storage.setTerminalFailureListener?.(listener);
184
+ this.storage.setTerminalFailureListener?.((reason) => {
185
+ this.cancelTimer();
186
+ listener(reason);
187
+ });
184
188
  }
185
189
  private hasPendingChanges(): boolean {
186
190
  if (this.dirty.size > 0 || this.removed.size > 0 || this.shared.publication) return true;
@@ -192,7 +196,11 @@ export class PersistentBackend extends MemoryBackend {
192
196
  private startTimer(intervalMs: number): void {
193
197
  if (intervalMs > 0)
194
198
  this.timer = setInterval(() => {
195
- if (!this.stopped && !this.pendingCheckpoints && this.hasPendingChanges())
199
+ if (this.stopped || this.isTerminallyFailed()) {
200
+ this.cancelTimer();
201
+ return;
202
+ }
203
+ if (!this.pendingCheckpoints && this.hasPendingChanges())
196
204
  void this.checkpoint().catch(() => {});
197
205
  }, intervalMs);
198
206
  }
@@ -204,6 +212,7 @@ export class PersistentBackend extends MemoryBackend {
204
212
  dirtyLimits?: Partial<DirtyLimits> | false;
205
213
  startupRoot?: MemoryBudget;
206
214
  sharedRoot?: MemoryBackendSharedRoot;
215
+ machineId?: string;
207
216
  signal?: AbortSignal;
208
217
  } = {},
209
218
  ): Promise<PersistentBackend> {
@@ -225,6 +234,7 @@ export class PersistentBackend extends MemoryBackend {
225
234
  options.dirtyLimits,
226
235
  options.startupRoot,
227
236
  options.sharedRoot,
237
+ options.machineId,
228
238
  );
229
239
  const fs = restoreTree(index);
230
240
  const root = fs.root;
@@ -239,6 +249,7 @@ export class PersistentBackend extends MemoryBackend {
239
249
  options.dirtyLimits,
240
250
  options.startupRoot,
241
251
  options.sharedRoot,
252
+ options.machineId,
242
253
  );
243
254
  try {
244
255
  if (!index.nodes[0]?.identity) {
package/fs/protocol.ts CHANGED
@@ -134,6 +134,8 @@ export interface FilesystemConnection {
134
134
  sections: SharedArrayBuffer;
135
135
  /** Nonzero lock owner token; service clears it when this identity is reaped. */
136
136
  owner: number;
137
+ /** Optional logical-process POSIX lock owner token (shared by exec successors and thread members). */
138
+ posixOwner?: number;
137
139
  maxBytes: number;
138
140
  /** Service revocation in word 0, then per-owner liveness for independent process identities. */
139
141
  ownerStates: SharedArrayBuffer;
@@ -149,6 +151,8 @@ export interface FilesystemReservation {
149
151
  targetOwner: number;
150
152
  /** Closed once; transfer state: 0 pending, 1 adopted, 2 cancelled. */
151
153
  state: SharedArrayBuffer;
154
+ /** Shared open-file control block when transferring a file or directory description. */
155
+ ofd?: SharedArrayBuffer;
152
156
  }
153
157
  export type FilesystemIdentity = Omit<FilesystemConnection, "port" | "requests">;
154
158
  export interface FilesystemOwnerConstruction {
@@ -278,15 +282,20 @@ function identityPublication(
278
282
  return domain;
279
283
  }
280
284
  /** Processes share storage, not the lifetime of the process that spawned them. */
281
- export function createProcessFilesystemIdentity(parent: FilesystemIdentity): FilesystemIdentity {
285
+ export function createProcessFilesystemIdentity(
286
+ parent: FilesystemIdentity,
287
+ posixOwner?: number,
288
+ ): FilesystemIdentity {
282
289
  const identity = createFilesystemIdentity(parent);
283
290
  identity.revocations = identity.revocations.slice(0, 1);
291
+ if (posixOwner !== undefined) identity.posixOwner = posixOwner;
284
292
  return identity;
285
293
  }
286
- /** Idempotent across the controller and guest copies of a transferred description. */
287
- export function releaseFilesystemReservation(reservation: FilesystemReservation): void {
294
+ /** Idempotent across the controller and guest copies of a transferred description.
295
+ * Returns true for the single call that transitioned the reservation to closed. */
296
+ export function releaseFilesystemReservation(reservation: FilesystemReservation): boolean {
288
297
  const state = new Int32Array(reservation.state);
289
- if (Atomics.exchange(state, 0, 1)) return;
298
+ if (Atomics.exchange(state, 0, 1)) return false;
290
299
  const target = new Int32ArrayConstructor(reservation.target, 0, CAPABILITY_LENGTH);
291
300
  for (;;) {
292
301
  const count = Atomics.load(target, reservation.targetKey + 1);
@@ -296,12 +305,15 @@ export function releaseFilesystemReservation(reservation: FilesystemReservation)
296
305
  )
297
306
  break;
298
307
  }
299
- if (Atomics.compareExchange(state, 1, 0, 2) === 0)
308
+ if (Atomics.compareExchange(state, 1, 0, 2) === 0) {
309
+ if (reservation.ofd) Atomics.sub(new Int32ArrayConstructor(reservation.ofd), 6, 1);
300
310
  Atomics.sub(
301
311
  new Int32ArrayConstructor(reservation.source, 0, CAPABILITY_LENGTH),
302
312
  reservation.sourceKey + 2,
303
313
  1,
304
314
  );
315
+ }
316
+ return true;
305
317
  }
306
318
  export function reserveIdentityCapability(
307
319
  source: FilesystemIdentity,