gestalt-mobile 0.65.6 → 0.65.8

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.
@@ -16,7 +16,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
16
16
  <link rel="icon" href="/icons/gestalt-mobile-192.png" />
17
17
  <link rel="apple-touch-icon" href="/icons/gestalt-mobile-180.png" />
18
18
  <title>Gestalt Mobile</title>
19
- <script type="module" crossorigin src="/assets/index-DGK0NUPm.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-CKJWzSwH.js"></script>
20
20
  <link rel="stylesheet" crossorigin href="/assets/index-VDRT2Esv.css">
21
21
  </head>
22
22
  <body>
@@ -483,7 +483,13 @@ export class AutopilotCoordinator {
483
483
  ...state,
484
484
  supervision: {
485
485
  ...nextProtocol,
486
- wakeCause: { condition: wake.condition, leaseId: wake.leaseId },
486
+ wakeCause: {
487
+ condition: wake.condition,
488
+ leaseId: wake.leaseId,
489
+ ...(state.supervision.waitLease?.runId
490
+ ? { runId: state.supervision.waitLease.runId }
491
+ : {}),
492
+ },
487
493
  },
488
494
  updatedAt: now,
489
495
  }, undefined, [
@@ -1926,7 +1932,14 @@ export class AutopilotCoordinator {
1926
1932
  const observedAt = this.deps.now();
1927
1933
  this.persist({
1928
1934
  ...state,
1929
- supervision: { ...protocol, wakeCause: { condition: 'deadline', leaseId } },
1935
+ supervision: {
1936
+ ...protocol,
1937
+ wakeCause: {
1938
+ condition: 'deadline',
1939
+ leaseId,
1940
+ ...(lease.runId ? { runId: lease.runId } : {}),
1941
+ },
1942
+ },
1930
1943
  updatedAt: observedAt,
1931
1944
  }, undefined, [
1932
1945
  {
@@ -2078,6 +2091,10 @@ export class AutopilotCoordinator {
2078
2091
  !state.checkpoints.terminalReviewAccepted);
2079
2092
  }
2080
2093
  requiresRootBoundary(state, plan) {
2094
+ // Host tests are root-owned. Preserve that ownership across wake, backoff
2095
+ // and restart until the next root turn is accepted and consumes wakeCause.
2096
+ if (state.supervision?.wakeCause?.runId)
2097
+ return true;
2081
2098
  if (state.providerRetry?.resumeRoot)
2082
2099
  return true;
2083
2100
  // Completed milestone reports do not complete terminal review or its fixes.
@@ -312,9 +312,12 @@ export function parseSupervisionProtocolState(value) {
312
312
  !wake.leaseId ||
313
313
  wake.leaseId.length > 256)
314
314
  return undefined;
315
+ if (wake.runId !== undefined && !validRunWait(wake.runId, ['processResultAvailable']))
316
+ return undefined;
315
317
  parsedWake = {
316
318
  condition: wake.condition,
317
319
  leaseId: wake.leaseId,
320
+ ...(typeof wake.runId === 'string' ? { runId: wake.runId } : {}),
318
321
  };
319
322
  }
320
323
  if (acknowledgement !== undefined) {
@@ -6,9 +6,78 @@
6
6
  import { createHash, randomUUID } from 'node:crypto';
7
7
  import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
8
8
  import { join } from 'node:path';
9
- /** Classify bounded native prose; never retain it or copy arbitrary native fields. */
9
+ /** Read only error-bearing fields, never request bodies or arbitrary object values. */
10
+ function errorText(value, depth = 0) {
11
+ if (depth > 5)
12
+ return '';
13
+ if (typeof value === 'string') {
14
+ const text = value.slice(0, 16_384).trim();
15
+ if (text.startsWith('{') || (text.startsWith('[') && !/^\[[\w-]+\]\s+/.test(text))) {
16
+ try {
17
+ return errorText(JSON.parse(text), depth + 1);
18
+ }
19
+ catch {
20
+ return ''; // A partial structured payload is not safe display text.
21
+ }
22
+ }
23
+ return text;
24
+ }
25
+ if (!value || typeof value !== 'object' || Array.isArray(value))
26
+ return '';
27
+ const error = value;
28
+ for (const key of ['caused_by', 'error', 'reason', 'message']) {
29
+ const text = errorText(error[key], depth + 1);
30
+ if (text)
31
+ return text;
32
+ }
33
+ return '';
34
+ }
35
+ /** Reduce an error to one cause before persisting or publishing any native prose. */
36
+ export function xerjErrorSummary(message) {
37
+ let text = errorText(message)
38
+ .replace(/\x1b\[[0-?]*[ -/]*[@-~]/g, '')
39
+ .replace(/-----BEGIN [^-]+-----[\s\S]*?(?:-----END [^-]+-----|$)/g, '[redacted]');
40
+ const lines = text.split(/[\r\n]+/).map((line) => line.trim());
41
+ const causeIndex = lines.findLastIndex((line) => /^(?:\d+:\s*)?caused by:/i.test(line));
42
+ text =
43
+ causeIndex >= 0
44
+ ? lines[causeIndex].replace(/^(?:\d+:\s*)?caused by:\s*/i, '') ||
45
+ lines.slice(causeIndex + 1).find(Boolean) ||
46
+ ''
47
+ : (lines.find((line) => line && !/^at\s+\S+/.test(line)) ?? '');
48
+ text = text
49
+ .replace(/^watch:\s*pass \d+ FAILED after [\d.]+s:\s*/i, '')
50
+ .replace(/^(?:(?:\d+:\s*)?(?:error|fatal|warning|caused by):\s*)+/i, '')
51
+ .replace(/\b(?:still watching|waiting for (?:a |the )?(?:source |file )?change)[\s\S]*$/i, '')
52
+ // Payloads can contain indexed text, prompts and model output. Drop the tail.
53
+ .replace(/\b(?:request|response|headers|body|payload|document|source|prompt|model output|environment|preview of (?:field'?s? )?value)\s*[:=][\s\S]*$/i, '')
54
+ .replace(/\b(?:authorization|proxy-authorization|cookie|set-cookie)\s*[:=][\s\S]*$/i, '')
55
+ .replace(/\b(?:password|passwd|token|access[_-]?token|api[_ -]?key|secret|client[_-]?secret|credentials?)\s*[:=][\s\S]*$/gi, '[redacted]')
56
+ .replace(/\b(?:Bearer|Basic|ApiKey)\s+[^\s,;]+/gi, '[redacted]')
57
+ .replace(/\b[A-Z][A-Z0-9_]+\s*=\s*(?:"[^"\n]*"|'[^'\n]*'|[^\s,;]+)/g, '[redacted]')
58
+ .replace(/\b[a-z][a-z0-9+.-]*:\/\/[^\s<>"']+/gi, '[endpoint]')
59
+ .replace(/(?:"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`[^`]*`)/g, '[redacted]')
60
+ .replace(/(?:[A-Za-z]:[\\/]|~?\/)[^\s,:;)"']*(?::\d+(?::\d+)?)?/g, '[path]')
61
+ .replace(/\b(file|path|directory)\s+[^\s:;,]+(?=:)/gi, '$1 [path]')
62
+ .replace(/\b[^\s@]+@[^\s@]+\.[^\s,;]+/g, '[redacted]')
63
+ .replace(/\b(?:\d{1,3}\.){3}\d{1,3}(?::\d+)?\b/g, '[endpoint]')
64
+ .replace(/\b(?:sk-[\w-]+|gh[pousr]_[\w]+|github_pat_[\w]+|AKIA[A-Z0-9]+)\b/g, '[redacted]')
65
+ .replace(/\b[A-Za-z0-9_+/=-]{32,}\b/g, '[redacted]')
66
+ .replace(/\b\d{4}-\d\d-\d\d[T ][\d:.]+(?:Z|[+-]\d\d:\d\d)?\b/g, '')
67
+ .replace(/\b(?:request|trace|correlation)[_-]?id\s*[:=]\s*[^\s,;]+/gi, '')
68
+ .replace(/\b(?:after|in|elapsed|duration|took)\s*[:=]?\s*\d+(?:\.\d+)?\s*(?:ms|s|secs?|seconds?|minutes?)\b/gi, '')
69
+ .replace(/\b\d+(?:\.\d+)?\s*(?:ms|s|secs?|seconds?|minutes?)\b/gi, '')
70
+ .replace(/[\x00-\x1f\x7f]/g, '')
71
+ .replace(/\s+/g, ' ')
72
+ .replace(/^[\s:;,.-]+|[\s:;,.-]+$/g, '');
73
+ if (!/[a-z]/i.test(text.replace(/\[(?:redacted|path|endpoint)\]/g, '')))
74
+ return undefined;
75
+ return text.length <= 200 ? text : `${text.slice(0, 197).replace(/\s+\S*$/, '')}…`;
76
+ }
77
+ /** Classify bounded errors; retain only the reduced, redacted cause. */
10
78
  export function xerjIndexDiagnostic(message) {
11
- const text = typeof message === 'string' ? message.slice(0, 16_384) : '';
79
+ const text = errorText(message);
80
+ const summary = xerjErrorSummary(message);
12
81
  const pass = /^watch: pass (\d+) FAILED after (\d+(?:\.\d+)?)s:/.exec(text);
13
82
  const number = pass ? Number(pass[1]) : Number.NaN;
14
83
  const durationSeconds = pass ? Number(pass[2]) : Number.NaN;
@@ -35,6 +104,7 @@ export function xerjIndexDiagnostic(message) {
35
104
  occurredAt: new Date().toISOString(),
36
105
  code,
37
106
  messageDigest: text ? createHash('sha256').update(text).digest('hex') : null,
107
+ ...(summary ? { summary } : {}),
38
108
  ...(Number.isSafeInteger(number) && Number.isFinite(durationSeconds)
39
109
  ? { watchPass: { number, durationSeconds } }
40
110
  : {}),
@@ -70,6 +70,8 @@ export class XerjIndexer {
70
70
  diagnosticDirectory;
71
71
  pendingDiagnostic;
72
72
  diagnosticSaved;
73
+ diskBudgetRefused = false;
74
+ currentFailure;
73
75
  constructor(root, mode, capability, environment = process.env, report = console.warn) {
74
76
  this.capability = capability;
75
77
  this.environment = environment;
@@ -82,9 +84,9 @@ export class XerjIndexer {
82
84
  start() {
83
85
  if (this.task || this.closed || this.value.mode === 'off')
84
86
  return;
85
- this.task = this.launch().catch(() => {
87
+ this.task = this.launch().catch((error) => {
86
88
  if (!this.closed)
87
- this.fail('Could not start XERJ indexing. Check root access and run gestalt doctor.');
89
+ this.reportFailure(error);
88
90
  });
89
91
  }
90
92
  fail(message) {
@@ -92,6 +94,23 @@ export class XerjIndexer {
92
94
  this.value = { ...this.value, state: 'error', phase: undefined, percent: undefined, message };
93
95
  this.report(message);
94
96
  }
97
+ rememberDiagnostic(diagnostic) {
98
+ this.currentFailure = diagnostic;
99
+ this.value = { ...this.value, diagnostic };
100
+ this.pendingDiagnostic = diagnostic;
101
+ this.diagnosticSaved ??= this.saveDiagnostics();
102
+ }
103
+ reportFailure(message) {
104
+ const diagnostic = xerjIndexDiagnostic(message);
105
+ if (this.currentFailure?.summary && this.genericFailure(diagnostic))
106
+ return;
107
+ this.rememberDiagnostic(diagnostic);
108
+ this.fail(`XERJ indexing failed: ${diagnostic.summary ?? 'No error cause was supplied'}. Index freshness is unverified.`);
109
+ }
110
+ genericFailure(diagnostic) {
111
+ return (!diagnostic.summary ||
112
+ /^(?:needs-decision|unknown (?:error|cause)|(?:indexing|autoindex|operation|pass) failed)$/i.test(diagnostic.summary));
113
+ }
95
114
  async launch() {
96
115
  const root = await realpath(this.value.root);
97
116
  const namespace = `ax-${createHash('sha256').update(root).digest('hex').slice(0, 16)}`;
@@ -167,24 +186,29 @@ export class XerjIndexer {
167
186
  '2000',
168
187
  '--progress',
169
188
  'json',
170
- ], { cwd: root, env: this.environment, shell: false, stdio: ['ignore', 'ignore', 'pipe'] });
189
+ ], { cwd: root, env: this.environment, shell: false, stdio: ['ignore', 'pipe', 'pipe'] });
171
190
  this.child = child;
172
191
  this.value = { ...this.value, state: 'indexing' };
173
- // Never retain raw tool output or filenames. The status contains only an
174
- // allowlist of counters/phases; bound even a malformed unterminated line.
175
- let pending = '';
176
- child.stderr?.on('data', (data) => {
177
- pending += data.toString();
178
- const lines = pending.split('\n');
179
- pending = lines.pop() ?? '';
180
- if (pending.length > 16_384)
181
- pending = '';
182
- for (const line of lines)
183
- this.progress(line);
184
- });
185
- child.once('error', () => {
192
+ // Retain only redacted error summaries and allowlisted counters/phases;
193
+ // bound even a malformed unterminated line.
194
+ // Native budget decisions use stdout; progress and watch failures use stderr.
195
+ // Keep separate line buffers so interleaved streams cannot corrupt JSON.
196
+ for (const stream of [child.stdout, child.stderr]) {
197
+ let pending = '';
198
+ stream?.on('data', (data) => {
199
+ pending += data.toString();
200
+ const lines = pending.split('\n');
201
+ pending = lines.pop() ?? '';
202
+ if (pending.length > 16_384)
203
+ pending = '';
204
+ for (const line of lines)
205
+ if (line.length <= 16_384)
206
+ this.progress(line);
207
+ });
208
+ }
209
+ child.once('error', (error) => {
186
210
  if (!this.closed)
187
- this.fail('Could not launch XERJ. Check the Gestalt manager and flock/setpriv installation.');
211
+ this.reportFailure(error);
188
212
  });
189
213
  child.once('close', (code) => {
190
214
  this.child = undefined;
@@ -199,7 +223,7 @@ export class XerjIndexer {
199
223
  };
200
224
  }
201
225
  else {
202
- this.fail(`XERJ watcher stopped (exit ${code ?? 'signal'}). Run gestalt doctor; verify flock and setpriv are installed, then restart Mobile.`);
226
+ this.fail(`XERJ watcher stopped${this.currentFailure?.summary ? `: ${this.currentFailure.summary}` : ` (exit ${code ?? 'signal'})`}. Run gestalt doctor before restarting Mobile.`);
203
227
  }
204
228
  });
205
229
  }
@@ -208,7 +232,26 @@ export class XerjIndexer {
208
232
  return;
209
233
  try {
210
234
  const event = JSON.parse(line);
211
- if (event.event === 'progress') {
235
+ if (event.xerj === 'autoindex-budget' && event.decision_required === true) {
236
+ const disk = event.disk;
237
+ if (disk?.threshold_enabled === true &&
238
+ typeof disk.used_percent === 'number' &&
239
+ typeof disk.flood_stage === 'number' &&
240
+ disk.flood_stage > 0 &&
241
+ disk.used_percent <= 100 &&
242
+ disk.used_percent >= disk.flood_stage) {
243
+ this.diskBudgetRefused = true;
244
+ const diagnostic = xerjIndexDiagnostic('no space left: disk flood-stage budget');
245
+ this.rememberDiagnostic(diagnostic);
246
+ this.fail('XERJ indexing refused: disk flood-stage threshold reached. Free space or move the index to a larger volume. Index freshness is unverified.');
247
+ }
248
+ else {
249
+ this.reportFailure(event.error ?? event.refused ?? 'Indexing requires an operator decision');
250
+ }
251
+ }
252
+ else if (event.event === 'progress') {
253
+ this.diskBudgetRefused = false;
254
+ this.currentFailure = undefined;
212
255
  this.evidence.invalidate();
213
256
  this.evidence.connection('ready');
214
257
  this.evidence.coverage(this.value.lastUpdate ? 'stale' : 'unknown');
@@ -228,7 +271,11 @@ export class XerjIndexer {
228
271
  }
229
272
  else if (event.event === 'done') {
230
273
  if (event.ok !== true) {
231
- this.fail('XERJ indexing failed. Check the index with gestalt xerj autoindex status; the next source change retries it.');
274
+ if (this.diskBudgetRefused)
275
+ return;
276
+ const detail = event.error ?? event.message;
277
+ if (detail || !this.currentFailure)
278
+ this.reportFailure(detail ?? event.reason);
232
279
  return;
233
280
  }
234
281
  if (this.saveConfiguration && !this.configurationSaved) {
@@ -246,19 +293,23 @@ export class XerjIndexer {
246
293
  ...(count(event.files) !== undefined ? { files: count(event.files) } : {}),
247
294
  ...(count(event.records) !== undefined ? { records: count(event.records) } : {}),
248
295
  };
296
+ this.diskBudgetRefused = false;
297
+ this.currentFailure = undefined;
249
298
  const records = count(event.records);
250
299
  this.evidence.coverage(records === undefined ? 'unknown' : records === 0 ? 'unavailable' : 'ready', {
251
300
  files: count(event.files),
252
301
  records,
253
302
  });
254
303
  }
255
- else if (event.event === 'warning') {
256
- const diagnostic = xerjIndexDiagnostic(event.message);
257
- this.value = { ...this.value, diagnostic };
258
- this.pendingDiagnostic = diagnostic;
259
- this.diagnosticSaved ??= this.saveDiagnostics();
260
- const reference = ` Diagnostic: ${diagnostic.id} (${diagnostic.code}).`;
304
+ else if (event.event === 'warning' || event.event === 'error') {
305
+ const diagnostic = xerjIndexDiagnostic(event.error ?? event.message ?? event.reason);
306
+ if ((this.currentFailure?.summary && this.genericFailure(diagnostic)) ||
307
+ (this.diskBudgetRefused &&
308
+ ['watch-pass-failed', 'unknown-warning'].includes(diagnostic.code)))
309
+ return;
310
+ this.rememberDiagnostic(diagnostic);
261
311
  if (diagnostic.code === 'watch-rescan') {
312
+ this.currentFailure = undefined;
262
313
  // Native XERJ already schedules a full pass after dropped watch events.
263
314
  // This invalidates coverage, but is not a failed pass or lost connection.
264
315
  this.evidence.coverage(this.value.lastUpdate ? 'stale' : 'unknown');
@@ -272,13 +323,11 @@ export class XerjIndexer {
272
323
  return;
273
324
  }
274
325
  if (diagnostic.code === 'rebuild-required') {
275
- this.fail('XERJ cannot update the saved index with the current indexing configuration. A new index generation is required; source changes alone cannot repair it. See the XERJ recovery guide.' +
276
- reference);
326
+ this.fail(`XERJ indexing failed: ${diagnostic.summary ?? 'Saved index configuration changed'}. A new index generation is required; source changes alone cannot repair it.`);
277
327
  return;
278
328
  }
279
329
  if (diagnostic.code === 'ambiguous-assignment') {
280
- this.fail('XERJ incremental dataset assignment failed; the index is stale. See the XERJ recovery guide for this upstream limitation.' +
281
- reference);
330
+ this.fail(`XERJ indexing failed: ${diagnostic.summary ?? 'Ambiguous dataset assignment'}. The index is stale; see the XERJ recovery guide.`);
282
331
  return;
283
332
  }
284
333
  const cause = {
@@ -289,17 +338,14 @@ export class XerjIndexer {
289
338
  'watch-pass-failed': 'The underlying cause could not be classified.',
290
339
  'unknown-warning': 'The warning could not be classified.',
291
340
  }[diagnostic.code];
292
- const pass = diagnostic.watchPass;
293
- this.fail((pass
294
- ? `XERJ watch pass ${pass.number} failed after ${pass.durationSeconds}s. `
295
- : 'XERJ indexing reported a warning. ') +
296
- cause +
297
- ' The watcher is still running and is waiting for a source change to retry; index coverage is unverified until an update succeeds.' +
298
- reference);
341
+ this.fail(`XERJ indexing failed: ${diagnostic.summary ?? cause.replace(/\.$/, '')}. The watcher is still running; index freshness is unverified.`);
299
342
  }
300
343
  }
301
344
  catch {
302
- /* Native diagnostics are not public status or application logs. */
345
+ // Ignore ordinary stdout and partial payloads. Only explicit error lines
346
+ // are eligible for redaction and display.
347
+ if (/^\s*(?:error|fatal|caused by):/i.test(line))
348
+ this.reportFailure(line);
303
349
  }
304
350
  }
305
351
  async saveDiagnostics() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.65.6",
3
+ "version": "0.65.8",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",