@jini-ai/desktop-host 0.7.3-next.2 → 0.7.3-next.3

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 (117) hide show
  1. package/README.md +217 -1
  2. package/dist/electron/electron-shell.js +5 -7
  3. package/dist/electron/handoff/index.d.ts +54 -0
  4. package/dist/electron/handoff/index.js +32 -0
  5. package/dist/electron/memory-sampler.d.ts +28 -0
  6. package/dist/electron/memory-sampler.js +41 -0
  7. package/dist/electron/partitions/cache-maintenance.d.ts +280 -0
  8. package/dist/electron/partitions/cache-maintenance.js +239 -0
  9. package/dist/electron/partitions/claim-sources.d.ts +54 -0
  10. package/dist/electron/partitions/claim-sources.js +36 -0
  11. package/dist/electron/partitions/holder-registry.d.ts +116 -0
  12. package/dist/electron/partitions/holder-registry.js +130 -0
  13. package/dist/electron/partitions/index.d.ts +10 -0
  14. package/dist/electron/partitions/index.js +10 -0
  15. package/dist/electron/partitions/maintenance-marker.d.ts +61 -0
  16. package/dist/electron/partitions/maintenance-marker.js +85 -0
  17. package/dist/electron/partitions/partition-inventory.d.ts +23 -0
  18. package/dist/electron/partitions/partition-inventory.js +19 -0
  19. package/dist/electron/partitions/partition-pass.d.ts +114 -0
  20. package/dist/electron/partitions/partition-pass.js +414 -0
  21. package/dist/electron/partitions/partition-root.d.ts +42 -0
  22. package/dist/electron/partitions/partition-root.js +52 -0
  23. package/dist/electron/partitions/profile-interlock.d.ts +141 -0
  24. package/dist/electron/partitions/profile-interlock.js +273 -0
  25. package/dist/electron/partitions/retirement-ledger.d.ts +116 -0
  26. package/dist/electron/partitions/retirement-ledger.js +149 -0
  27. package/dist/electron/preferences/index.d.ts +5 -0
  28. package/dist/electron/preferences/index.js +5 -0
  29. package/dist/electron/preferences/ipc.d.ts +35 -0
  30. package/dist/electron/preferences/ipc.js +21 -0
  31. package/dist/electron/preferences/menu.d.ts +103 -0
  32. package/dist/electron/preferences/menu.js +67 -0
  33. package/dist/electron/preferences/preference-file.d.ts +63 -0
  34. package/dist/electron/preferences/preference-file.js +51 -0
  35. package/dist/electron/preferences/values.d.ts +25 -0
  36. package/dist/electron/preferences/values.js +18 -0
  37. package/dist/electron/preload/index.d.ts +3 -0
  38. package/dist/electron/preload/index.js +2 -0
  39. package/dist/electron/preload/ipc-subscribe.d.ts +34 -0
  40. package/dist/electron/preload/ipc-subscribe.js +18 -0
  41. package/dist/electron/selftest/index.d.ts +3 -0
  42. package/dist/electron/selftest/index.js +3 -0
  43. package/dist/electron/selftest/selftest-tracker.d.ts +82 -0
  44. package/dist/electron/selftest/selftest-tracker.js +67 -0
  45. package/dist/electron/session-bootstrap/exchange.d.ts +50 -0
  46. package/dist/electron/session-bootstrap/exchange.js +41 -0
  47. package/dist/electron/session-bootstrap/header-arming.d.ts +18 -0
  48. package/dist/electron/session-bootstrap/header-arming.js +13 -0
  49. package/dist/electron/session-bootstrap/index.d.ts +11 -0
  50. package/dist/electron/session-bootstrap/index.js +10 -0
  51. package/dist/electron/session-bootstrap/partition.d.ts +17 -0
  52. package/dist/electron/session-bootstrap/partition.js +24 -0
  53. package/dist/electron/session-bootstrap/probe.d.ts +40 -0
  54. package/dist/electron/session-bootstrap/probe.js +29 -0
  55. package/dist/electron/session-bootstrap/types.d.ts +62 -0
  56. package/dist/electron/session-bootstrap/types.js +7 -0
  57. package/dist/electron/updates/desktop-updater.d.ts +90 -0
  58. package/dist/electron/updates/desktop-updater.js +124 -0
  59. package/dist/electron/updates/index.d.ts +4 -0
  60. package/dist/electron/updates/index.js +4 -0
  61. package/dist/electron/updates/instance-presence-strict.d.ts +27 -0
  62. package/dist/electron/updates/instance-presence-strict.js +46 -0
  63. package/dist/electron/updates/native-notices.d.ts +89 -0
  64. package/dist/electron/updates/native-notices.js +41 -0
  65. package/dist/electron/updates/update-check-now.d.ts +117 -0
  66. package/dist/electron/updates/update-check-now.js +88 -0
  67. package/dist/electron/usability/find-in-page-ipc.d.ts +3 -6
  68. package/dist/electron/usability/window-bounds-store.js +14 -12
  69. package/dist/electron/usability/zoom-menu.d.ts +1 -1
  70. package/dist/electron/webview/index.d.ts +2 -0
  71. package/dist/electron/webview/index.js +2 -0
  72. package/dist/electron/webview/webview-types.d.ts +66 -0
  73. package/dist/electron/webview/webview-types.js +12 -0
  74. package/dist/electron/windows/app-window.d.ts +83 -0
  75. package/dist/electron/windows/app-window.js +62 -0
  76. package/dist/electron/windows/dock-icon.d.ts +34 -0
  77. package/dist/electron/windows/dock-icon.js +32 -0
  78. package/dist/electron/windows/index.d.ts +3 -0
  79. package/dist/electron/windows/index.js +3 -0
  80. package/dist/logging.js +3 -1
  81. package/dist/node-toolchain/boot-setup.d.ts +63 -0
  82. package/dist/node-toolchain/boot-setup.js +59 -0
  83. package/dist/node-toolchain/index.d.ts +2 -0
  84. package/dist/node-toolchain/index.js +1 -0
  85. package/dist/shell/auto-update-controller.d.ts +34 -0
  86. package/dist/shell/auto-update-controller.js +27 -0
  87. package/dist/shell/copied-site-databases.d.ts +71 -0
  88. package/dist/shell/copied-site-databases.js +60 -0
  89. package/dist/shell/find-in-page-verify.d.ts +33 -0
  90. package/dist/shell/find-in-page-verify.js +30 -0
  91. package/dist/shell/find-menu.d.ts +33 -0
  92. package/dist/shell/find-menu.js +36 -0
  93. package/dist/shell/guest-navigation.d.ts +47 -0
  94. package/dist/shell/guest-navigation.js +58 -0
  95. package/dist/shell/instance-presence.d.ts +20 -0
  96. package/dist/shell/instance-presence.js +26 -0
  97. package/dist/shell/js-backslide-guard.d.ts +42 -0
  98. package/dist/shell/js-backslide-guard.js +44 -0
  99. package/dist/shell/node-toolchain.d.ts +34 -0
  100. package/dist/shell/node-toolchain.js +50 -0
  101. package/dist/shell/pty-helpers.d.ts +25 -0
  102. package/dist/shell/pty-helpers.js +50 -0
  103. package/dist/shell/site-presence.d.ts +32 -0
  104. package/dist/shell/site-presence.js +42 -0
  105. package/dist/shell/speech/mac-on-device-transcriber.d.ts +24 -0
  106. package/dist/shell/speech/mac-on-device-transcriber.js +81 -0
  107. package/dist/shell/speech/speech-ipc.d.ts +52 -0
  108. package/dist/shell/speech/speech-ipc.js +40 -0
  109. package/dist/shell/spellcheck-menu.d.ts +84 -0
  110. package/dist/shell/spellcheck-menu.js +63 -0
  111. package/dist/shell/supervised-site-url.d.ts +20 -0
  112. package/dist/shell/supervised-site-url.js +22 -0
  113. package/dist/speech/macos/mac-on-device-transcriber.d.ts +2 -1
  114. package/dist/speech/speech-bridge.d.ts +1 -8
  115. package/dist/speech/transcription-port.d.ts +1 -9
  116. package/dist/tauri/tauri-shell.js +8 -10
  117. package/package.json +153 -6
@@ -0,0 +1,116 @@
1
+ import type { StrictRead } from './claim-sources.js';
2
+ /**
3
+ * Filesystem the interlock uses. Sync writes exist only for startup registration, which must finish
4
+ * before the host's ready event; async `writeFile` is expected to flush (fsync) before resolving.
5
+ */
6
+ export interface PartitionFsPort {
7
+ mkdirSync(required: {
8
+ path: string;
9
+ }, optional?: {
10
+ recursive?: boolean;
11
+ }): unknown;
12
+ writeFileSync(required: {
13
+ path: string;
14
+ data: string;
15
+ }): void;
16
+ renameSync(required: {
17
+ oldPath: string;
18
+ newPath: string;
19
+ }): void;
20
+ unlinkSync(required: {
21
+ path: string;
22
+ }): void;
23
+ writeFile(required: {
24
+ path: string;
25
+ data: string;
26
+ }): Promise<void>;
27
+ rename(required: {
28
+ oldPath: string;
29
+ newPath: string;
30
+ }): Promise<void>;
31
+ readFile(required: {
32
+ path: string;
33
+ }): Promise<string>;
34
+ readdir(required: {
35
+ path: string;
36
+ }): Promise<string[]>;
37
+ lstat(required: {
38
+ path: string;
39
+ }): Promise<{
40
+ isDirectory(): boolean;
41
+ isSymbolicLink(): boolean;
42
+ }>;
43
+ realpath(required: {
44
+ path: string;
45
+ }): Promise<string>;
46
+ }
47
+ export interface PartitionProcessPort {
48
+ pid: number;
49
+ bootId: string;
50
+ hostname: string;
51
+ isAlive(required: {
52
+ pid: number;
53
+ }): boolean;
54
+ /** Lowercase hex; names this process's holder file. */
55
+ newToken(): string;
56
+ }
57
+ export interface PartitionSchedulerPort {
58
+ sleep(required: {
59
+ ms: number;
60
+ }): Promise<void>;
61
+ every(required: {
62
+ ms: number;
63
+ run: () => void;
64
+ }): {
65
+ cancel(): void;
66
+ };
67
+ }
68
+ export interface HolderRecord {
69
+ v: 1;
70
+ pid: number;
71
+ token: string;
72
+ bootId: string;
73
+ hostname: string;
74
+ profile: string;
75
+ startedAt: number;
76
+ seq: number;
77
+ intents: string[];
78
+ held: string[];
79
+ }
80
+ export interface HolderRegistryInput {
81
+ interlockDir: string;
82
+ fs: PartitionFsPort;
83
+ process: PartitionProcessPort;
84
+ clock: {
85
+ now(): number;
86
+ };
87
+ }
88
+ /** This process's own holder record: the only file it ever writes in `holders/`. @complexity O(1) per call. */
89
+ export declare function createHolderRegistry({ interlockDir, fs, process, clock }: HolderRegistryInput): {
90
+ file: string;
91
+ token: string;
92
+ intents: Set<string>;
93
+ held: Set<string>;
94
+ readonly registered: boolean;
95
+ register(): void;
96
+ /**
97
+ * Publishes are chained and each serializes state when it runs, not when it is requested. Without
98
+ * the chain a heartbeat snapshot taken before an intent was added could rename over the record
99
+ * after it and silently withdraw the intent a sibling's pass relies on.
100
+ */
101
+ publish(): Promise<void>;
102
+ unregister(): void;
103
+ };
104
+ export type HolderRegistry = ReturnType<typeof createHolderRegistry>;
105
+ /**
106
+ * Every live holder of this profile, or `unknown`. A bad record is re-read once after a short pause
107
+ * (a writer on a filesystem without atomic rename), then fails the whole read closed.
108
+ * @complexity O(n) records, at most two reads each.
109
+ */
110
+ export declare function readHoldersStrict({ interlockDir, fs, process, scheduler }: {
111
+ interlockDir: string;
112
+ fs: PartitionFsPort;
113
+ process: PartitionProcessPort;
114
+ scheduler: PartitionSchedulerPort;
115
+ }, _optional?: Record<string, never>): Promise<StrictRead<HolderRecord[]>>;
116
+ //# sourceMappingURL=holder-registry.d.ts.map
@@ -0,0 +1,130 @@
1
+ import path from 'node:path';
2
+ const HOLDER_NAME = /^(\d+)-([0-9a-f]+)\.json$/;
3
+ const RETRY_MS = 20;
4
+ const code = (error) => error?.code;
5
+ /** This process's own holder record: the only file it ever writes in `holders/`. @complexity O(1) per call. */
6
+ export function createHolderRegistry({ interlockDir, fs, process, clock }) {
7
+ const dir = path.join(interlockDir, 'holders');
8
+ const token = process.newToken();
9
+ const file = path.join(dir, `${process.pid}-${token}.json`);
10
+ const intents = new Set(), held = new Set();
11
+ let seq = 0, startedAt = 0, writes = 0, registered = false;
12
+ let queue = Promise.resolve();
13
+ const snapshot = () => JSON.stringify({
14
+ v: 1, pid: process.pid, token, bootId: process.bootId, hostname: process.hostname, profile: interlockDir,
15
+ startedAt, seq, intents: [...intents].sort(), held: [...held].sort(),
16
+ });
17
+ const temporary = () => { writes += 1; return `${file}.${writes}.tmp`; };
18
+ return {
19
+ file, token, intents, held,
20
+ get registered() { return registered; },
21
+ register() {
22
+ startedAt = clock.now();
23
+ fs.mkdirSync({ path: dir }, { recursive: true });
24
+ const temp = temporary();
25
+ fs.writeFileSync({ path: temp, data: snapshot() });
26
+ fs.renameSync({ oldPath: temp, newPath: file });
27
+ registered = true;
28
+ },
29
+ /**
30
+ * Publishes are chained and each serializes state when it runs, not when it is requested. Without
31
+ * the chain a heartbeat snapshot taken before an intent was added could rename over the record
32
+ * after it and silently withdraw the intent a sibling's pass relies on.
33
+ */
34
+ publish() {
35
+ const run = async () => {
36
+ seq += 1;
37
+ const temp = temporary();
38
+ await fs.writeFile({ path: temp, data: snapshot() });
39
+ await fs.rename({ oldPath: temp, newPath: file });
40
+ };
41
+ const next = queue.then(run, run);
42
+ queue = next.catch(() => { });
43
+ return next;
44
+ },
45
+ unregister() {
46
+ registered = false;
47
+ try {
48
+ fs.unlinkSync({ path: file });
49
+ }
50
+ catch { /* A crash leaves the file too; readers prove it dead. */ }
51
+ },
52
+ };
53
+ }
54
+ const isStringArray = (v) => Array.isArray(v) && v.every(item => typeof item === 'string');
55
+ function hasHolderShape(r) {
56
+ return [r.bootId, r.hostname].every(v => typeof v === 'string') && Number.isFinite(r.seq) && isStringArray(r.intents) && isStringArray(r.held);
57
+ }
58
+ function parseHolder(text, pid, token) {
59
+ try {
60
+ const r = JSON.parse(text);
61
+ const named = r?.v === 1 && String(r.pid) === pid && r.token === token;
62
+ return named && hasHolderShape(r) ? r : null;
63
+ }
64
+ catch {
65
+ return null;
66
+ }
67
+ }
68
+ /** Liveness never uses record age: another host is unknown (kept), an earlier boot is dead, else the PID probe. */
69
+ function holderAlive(record, process) {
70
+ if (record.hostname !== process.hostname)
71
+ return true;
72
+ if (record.bootId !== process.bootId)
73
+ return false;
74
+ return record.pid === process.pid || process.isAlive({ pid: record.pid });
75
+ }
76
+ async function readOne(file, match, fs) {
77
+ try {
78
+ const record = parseHolder(await fs.readFile({ path: file }), match[1], match[2]);
79
+ return record ? { state: 'record', record } : { state: 'bad', reason: `holder ${path.basename(file)} malformed` };
80
+ }
81
+ catch (error) {
82
+ // Only the owner unlinks its record (on quit), so a vanished file is proof the holder left.
83
+ if (code(error) === 'ENOENT')
84
+ return { state: 'gone' };
85
+ return { state: 'bad', reason: `holder ${path.basename(file)} unreadable (${code(error) ?? 'error'})` };
86
+ }
87
+ }
88
+ async function listHolderNames(dir, fs) {
89
+ try {
90
+ return { state: 'ok', value: await fs.readdir({ path: dir }) };
91
+ }
92
+ catch (error) {
93
+ // No holders directory means no process of this profile ever registered: genuinely empty.
94
+ if (code(error) === 'ENOENT')
95
+ return { state: 'ok', value: [] };
96
+ return { state: 'unknown', reason: `holders directory unreadable (${code(error) ?? 'error'})` };
97
+ }
98
+ }
99
+ async function readWithRetry(file, match, fs, scheduler) {
100
+ const first = await readOne(file, match, fs);
101
+ if (first.state !== 'bad')
102
+ return first;
103
+ await scheduler.sleep({ ms: RETRY_MS });
104
+ return readOne(file, match, fs);
105
+ }
106
+ /**
107
+ * Every live holder of this profile, or `unknown`. A bad record is re-read once after a short pause
108
+ * (a writer on a filesystem without atomic rename), then fails the whole read closed.
109
+ * @complexity O(n) records, at most two reads each.
110
+ */
111
+ export async function readHoldersStrict({ interlockDir, fs, process, scheduler }, _optional = {}) {
112
+ const dir = path.join(interlockDir, 'holders');
113
+ const listed = await listHolderNames(dir, fs);
114
+ if (listed.state === 'unknown')
115
+ return listed;
116
+ const names = listed.value;
117
+ const live = [];
118
+ for (const name of names) {
119
+ const match = HOLDER_NAME.exec(name);
120
+ if (!match)
121
+ continue;
122
+ const read = await readWithRetry(path.join(dir, name), match, fs, scheduler);
123
+ if (read.state === 'bad')
124
+ return { state: 'unknown', reason: read.reason };
125
+ if (read.state === 'record' && holderAlive(read.record, process))
126
+ live.push(read.record);
127
+ }
128
+ return { state: 'ok', value: live };
129
+ }
130
+ //# sourceMappingURL=holder-registry.js.map
@@ -0,0 +1,10 @@
1
+ export * from './claim-sources.js';
2
+ export * from './holder-registry.js';
3
+ export * from './partition-root.js';
4
+ export * from './profile-interlock.js';
5
+ export * from './retirement-ledger.js';
6
+ export * from './partition-pass.js';
7
+ export { listAmbiguousPartitions, type PartitionInventory } from './partition-inventory.js';
8
+ export * from './cache-maintenance.js';
9
+ export * from './maintenance-marker.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,10 @@
1
+ export * from './claim-sources.js';
2
+ export * from './holder-registry.js';
3
+ export * from './partition-root.js';
4
+ export * from './profile-interlock.js';
5
+ export * from './retirement-ledger.js';
6
+ export * from './partition-pass.js';
7
+ export { listAmbiguousPartitions } from './partition-inventory.js';
8
+ export * from './cache-maintenance.js';
9
+ export * from './maintenance-marker.js';
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,61 @@
1
+ import type { CacheClearMark } from './cache-maintenance.js';
2
+ export interface MaintenanceMarkerFs {
3
+ readFile(required: {
4
+ path: string;
5
+ }): Promise<string>;
6
+ writeFile(required: {
7
+ path: string;
8
+ data: string;
9
+ }): Promise<void>;
10
+ rename(required: {
11
+ oldPath: string;
12
+ newPath: string;
13
+ }): Promise<void>;
14
+ }
15
+ export type CodeCacheMark = {
16
+ state: 'ok';
17
+ lastLaunchVersion: string | null;
18
+ forVersion: string | null;
19
+ pending: string[];
20
+ } | {
21
+ state: 'unknown';
22
+ reason: string;
23
+ };
24
+ /**
25
+ * The per-profile maintenance record (`maintenance.json` in that profile's folder, so each profile keeps
26
+ * its own). Writes are temp-then-rename and serialized within the process. Two processes can still lose
27
+ * each other's update; that only ever leaves a partition pending again, never falsely done, because a
28
+ * done mark is honoured only for the current `capBytes` and done → pending happens only when it changes.
29
+ * @complexity O(partitions) per write (whole-document rewrite).
30
+ */
31
+ export declare function createMaintenanceMarker({ file, fs }: {
32
+ file: string;
33
+ fs: MaintenanceMarkerFs;
34
+ }, _optional?: Record<string, never>): {
35
+ readCacheClear: ({ partition }: {
36
+ partition: string;
37
+ }) => Promise<CacheClearMark>;
38
+ markCacheClear: (required: {
39
+ partition: string;
40
+ capBytes: number;
41
+ outcome: {
42
+ state: "done";
43
+ } | {
44
+ state: "pending";
45
+ reason: string;
46
+ };
47
+ }) => Promise<void>;
48
+ readCodeCache: () => Promise<CodeCacheMark>;
49
+ writeCodeCachePending: ({ forVersion, pending }: {
50
+ forVersion: string;
51
+ pending: string[];
52
+ }) => Promise<void>;
53
+ writeLaunchVersion: ({ version }: {
54
+ version: string;
55
+ }) => Promise<void>;
56
+ settleCodeCache: ({ partition }: {
57
+ partition: string;
58
+ }) => Promise<void>;
59
+ };
60
+ export type MaintenanceMarker = ReturnType<typeof createMaintenanceMarker>;
61
+ //# sourceMappingURL=maintenance-marker.d.ts.map
@@ -0,0 +1,85 @@
1
+ const code = (error) => error?.code;
2
+ const empty = () => ({ v: 1, partitions: {} });
3
+ function parse(text) {
4
+ try {
5
+ const doc = JSON.parse(text);
6
+ const ok = doc.v === 1 && typeof doc.partitions === 'object' && doc.partitions !== null && !Array.isArray(doc.partitions);
7
+ return ok ? doc : null;
8
+ }
9
+ catch {
10
+ return null;
11
+ }
12
+ }
13
+ function createMarkerDocumentStore({ file, fs }) {
14
+ let queue = Promise.resolve();
15
+ let seq = 0;
16
+ const load = async () => {
17
+ let text;
18
+ try {
19
+ text = await fs.readFile({ path: file });
20
+ }
21
+ catch (error) {
22
+ return code(error) === 'ENOENT' ? { doc: empty() } : { unknown: String(code(error) ?? error) };
23
+ }
24
+ const doc = parse(text);
25
+ return doc ? { doc } : { unknown: 'corrupt maintenance record' };
26
+ };
27
+ /** A corrupt or unreadable record restarts empty: every partition becomes pending and is re-measured. */
28
+ const update = (change) => {
29
+ const next = queue.catch(() => { }).then(async () => {
30
+ const loaded = await load();
31
+ const doc = 'doc' in loaded ? loaded.doc : empty();
32
+ change(doc);
33
+ const temp = `${file}.${++seq}.tmp`;
34
+ await fs.writeFile({ path: temp, data: JSON.stringify(doc) });
35
+ await fs.rename({ oldPath: temp, newPath: file });
36
+ });
37
+ queue = next;
38
+ return next;
39
+ };
40
+ return { load, update };
41
+ }
42
+ /**
43
+ * The per-profile maintenance record (`maintenance.json` in that profile's folder, so each profile keeps
44
+ * its own). Writes are temp-then-rename and serialized within the process. Two processes can still lose
45
+ * each other's update; that only ever leaves a partition pending again, never falsely done, because a
46
+ * done mark is honoured only for the current `capBytes` and done → pending happens only when it changes.
47
+ * @complexity O(partitions) per write (whole-document rewrite).
48
+ */
49
+ export function createMaintenanceMarker({ file, fs }, _optional = {}) {
50
+ const { load, update } = createMarkerDocumentStore({ file, fs });
51
+ const readCacheClear = async ({ partition }) => {
52
+ const loaded = await load();
53
+ if ('unknown' in loaded)
54
+ return { state: 'unknown', reason: loaded.unknown };
55
+ const rec = loaded.doc.partitions[partition]?.cacheClear;
56
+ if (!rec)
57
+ return { state: 'absent' };
58
+ if (rec.state === 'done')
59
+ return { state: 'done', capBytes: rec.capBytes };
60
+ return { state: 'pending', capBytes: rec.capBytes, attempts: rec.attempts, lastReason: rec.lastReason ?? 'unknown' };
61
+ };
62
+ const markCacheClear = ({ partition, capBytes, outcome }) => update(doc => {
63
+ const prev = doc.partitions[partition]?.cacheClear;
64
+ const attempts = (prev?.state === 'pending' ? prev.attempts : 0) + (outcome.state === 'pending' ? 1 : 0);
65
+ const cacheClear = outcome.state === 'done'
66
+ ? { state: 'done', capBytes, attempts: 0 }
67
+ : { state: 'pending', capBytes, attempts, lastReason: outcome.reason };
68
+ doc.partitions[partition] = { ...doc.partitions[partition], cacheClear };
69
+ });
70
+ const readCodeCache = async () => {
71
+ const loaded = await load();
72
+ if ('unknown' in loaded)
73
+ return { state: 'unknown', reason: loaded.unknown };
74
+ const { lastLaunchVersion, codeCache } = loaded.doc;
75
+ return { state: 'ok', lastLaunchVersion: lastLaunchVersion ?? null, forVersion: codeCache?.forVersion ?? null, pending: [...(codeCache?.pending ?? [])] };
76
+ };
77
+ const writeCodeCachePending = ({ forVersion, pending }) => update(doc => { doc.codeCache = { forVersion, pending: [...pending] }; });
78
+ const writeLaunchVersion = ({ version }) => update(doc => { doc.lastLaunchVersion = version; });
79
+ const settleCodeCache = ({ partition }) => update(doc => {
80
+ if (doc.codeCache)
81
+ doc.codeCache.pending = doc.codeCache.pending.filter(name => name !== partition);
82
+ });
83
+ return { readCacheClear, markCacheClear, readCodeCache, writeCodeCachePending, writeLaunchVersion, settleCodeCache };
84
+ }
85
+ //# sourceMappingURL=maintenance-marker.js.map
@@ -0,0 +1,23 @@
1
+ import type { ClaimsRead } from './claim-sources.js';
2
+ import type { CandidateList, PartitionCandidate, PartitionRootRead } from './partition-root.js';
3
+ import type { PartitionPassLedger } from './partition-pass.js';
4
+ export type PartitionInventory = {
5
+ state: 'unknown';
6
+ } | {
7
+ state: 'ok';
8
+ candidates: readonly PartitionCandidate[];
9
+ };
10
+ export declare function isAmbiguousPartitionEligible({ partition, claims, ledger }: {
11
+ partition: string;
12
+ claims: ClaimsRead;
13
+ ledger: ReturnType<PartitionPassLedger['readStrict']>;
14
+ }, _optional?: {}): boolean;
15
+ export declare function listAmbiguousPartitions({ readRoot, list, readClaims, readLedger }: {
16
+ readRoot: () => Promise<PartitionRootRead>;
17
+ list: (required: {
18
+ root: string;
19
+ }) => Promise<CandidateList>;
20
+ readClaims: () => Promise<ClaimsRead>;
21
+ readLedger: () => ReturnType<PartitionPassLedger['readStrict']>;
22
+ }, _optional?: {}): Promise<PartitionInventory>;
23
+ //# sourceMappingURL=partition-inventory.d.ts.map
@@ -0,0 +1,19 @@
1
+ export function isAmbiguousPartitionEligible({ partition, claims, ledger }, _optional = {}) {
2
+ return claims.state === 'ok' && ledger.state === 'ok' && claims.otherInstances.length === 0 &&
3
+ !claims.claimed.includes(partition) && !ledger.records.some(record => record.partition === partition && record.state === 'pending');
4
+ }
5
+ export async function listAmbiguousPartitions({ readRoot, list, readClaims, readLedger }, _optional = {}) {
6
+ const root = await readRoot();
7
+ if (root.state === 'absent')
8
+ return { state: 'ok', candidates: [] };
9
+ if (root.state === 'unknown')
10
+ return { state: 'unknown' };
11
+ const candidates = await list({ root: root.root });
12
+ if (candidates.state === 'unknown')
13
+ return { state: 'unknown' };
14
+ const claims = await readClaims(), ledger = readLedger();
15
+ if (claims.state === 'unknown' || ledger.state === 'unknown')
16
+ return { state: 'unknown' };
17
+ return { state: 'ok', candidates: candidates.candidates.filter(candidate => isAmbiguousPartitionEligible({ partition: candidate.name, claims, ledger })) };
18
+ }
19
+ //# sourceMappingURL=partition-inventory.js.map
@@ -0,0 +1,114 @@
1
+ import type { PartitionFsPort } from './holder-registry.js';
2
+ import type { PartitionInterlock, PartitionWriterContext } from './profile-interlock.js';
3
+ import type { RetirementLedger } from './retirement-ledger.js';
4
+ export interface PartitionPassStat {
5
+ isDirectory(): boolean;
6
+ isSymbolicLink(): boolean;
7
+ dev: number;
8
+ }
9
+ /** `rm` is recursive and not forced; `rename` stays on one filesystem (the aside folder is a child of the root). */
10
+ export interface PartitionPassFsPort extends Pick<PartitionFsPort, 'readdir' | 'realpath' | 'rename'> {
11
+ lstat(required: {
12
+ path: string;
13
+ }): Promise<PartitionPassStat>;
14
+ mkdir(required: {
15
+ path: string;
16
+ }): Promise<void>;
17
+ rm(required: {
18
+ path: string;
19
+ }): Promise<void>;
20
+ }
21
+ export type PartitionPassInterlock = Pick<PartitionInterlock, 'withPartitionWriter' | 'readHoldersStrict'>;
22
+ export type PartitionPassLedger = Pick<RetirementLedger, 'profile' | 'readStrict' | 'transition' | 'append'>;
23
+ export interface PartitionPassRoot {
24
+ isManaged(name: string): boolean;
25
+ }
26
+ export interface PartitionPassReport {
27
+ result: 'done' | 'skipped' | 'failed';
28
+ reason?: string;
29
+ removed: string[];
30
+ cacheCleared: string[];
31
+ restored: string[];
32
+ kept: Array<{
33
+ partition: string;
34
+ reason: string;
35
+ }>;
36
+ skipped: Array<{
37
+ name: string;
38
+ reason: string;
39
+ }>;
40
+ }
41
+ /** Boot cache work (one-time and update clears) for unheld partitions; runs under the target fence. */
42
+ /** `writer` is the pass's writer context, so cache-only renames can recheck holders and assert the lock. */
43
+ export type PartitionMaintenance = (required: {
44
+ partition: string;
45
+ path: string;
46
+ classification: 'tracked' | 'ambiguous';
47
+ writer: PartitionWriterContext;
48
+ }) => Promise<void>;
49
+ export interface PartitionPassRequired {
50
+ interlock: PartitionPassInterlock;
51
+ ledger: PartitionPassLedger;
52
+ fs: PartitionPassFsPort;
53
+ root: PartitionPassRoot;
54
+ maintenance: PartitionMaintenance;
55
+ report: (required: {
56
+ report: PartitionPassReport;
57
+ }) => void;
58
+ scheduler: {
59
+ sleep(required: {
60
+ ms: number;
61
+ }): Promise<void>;
62
+ };
63
+ newToken: () => string;
64
+ }
65
+ export interface PartitionPassOptional {
66
+ budgetMs?: number;
67
+ asideDirName?: string;
68
+ }
69
+ export type PartitionPassOutcome = {
70
+ state: 'finished';
71
+ report: PartitionPassReport;
72
+ } | {
73
+ state: 'continuing';
74
+ done: Promise<PartitionPassReport>;
75
+ };
76
+ export interface PartitionRemovalConfirmation {
77
+ partition: string;
78
+ confirmed: true;
79
+ evidence: 'owner-dialog';
80
+ }
81
+ export interface ManualRemovalRequired {
82
+ partition: string;
83
+ interlock: PartitionPassInterlock;
84
+ ledger: PartitionPassLedger;
85
+ fs: PartitionPassFsPort;
86
+ root: PartitionPassRoot;
87
+ confirmation: PartitionRemovalConfirmation;
88
+ newToken: () => string;
89
+ }
90
+ export type ManualRemovalResult = {
91
+ state: 'removed';
92
+ } | {
93
+ state: 'kept';
94
+ reason: 'protected' | 'busy' | 'unknown' | 'missing';
95
+ } | {
96
+ state: 'refused';
97
+ reason: 'unconfirmed' | 'not-managed';
98
+ };
99
+ export declare const DEFAULT_ASIDE_DIR_NAME = ".removing";
100
+ /**
101
+ * Next-start partition pass: restore uncommitted asides, then remove proven-retired partitions whole and
102
+ * clear cache folders of ambiguous ones. Resolves at the budget at the latest; the pass keeps running.
103
+ * @complexity O(candidates + asides) fs operations.
104
+ */
105
+ export declare function runPartitionPass(required: PartitionPassRequired, { budgetMs, asideDirName }?: PartitionPassOptional): Promise<PartitionPassOutcome>;
106
+ /**
107
+ * Owner-confirmed removal of one ambiguous partition (its sign-ins), with the same fence, rename,
108
+ * post-rename recheck and CAS commit as automatic removal. A missing or mismatched confirmation is refused.
109
+ * @complexity O(1) partitions; O(claims) per recheck.
110
+ */
111
+ export declare function removeAmbiguousPartition(required: ManualRemovalRequired, { asideDirName }?: {
112
+ asideDirName?: string;
113
+ }): Promise<ManualRemovalResult>;
114
+ //# sourceMappingURL=partition-pass.d.ts.map