gestalt-mobile 0.54.2 → 0.55.0
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/README.md +19 -0
- package/dist/client/assets/{index-CRxjJEwq.js → index-DdEHicWt.js} +3 -3
- package/dist/client/index.html +1 -1
- package/dist/server/server/composition.contracts.js +379 -2
- package/dist/server/server/composition.js +38 -1
- package/dist/server/server/features/autopilot/application/service.js +174 -17
- package/dist/server/server/features/autopilot/domain/supervision-protocol.js +34 -0
- package/dist/server/server/features/plans/application/executor-model-evidence.js +192 -0
- package/dist/server/server/features/plans/application/parse-model-policy.js +77 -0
- package/dist/server/server/features/plans/application/parse-supervised-plan.js +23 -4
- package/dist/server/server/features/plans/application/supervised-plan-registry.js +16 -1
- package/dist/server/server/features/plans/domain/model-policy-admission.js +43 -0
- package/dist/server/server/platform/codex/codex-model-catalog.js +38 -0
- package/dist/server/server/platform/codex/executor-configuration.js +90 -0
- package/dist/server/server/platform/codex/session-runtime.js +33 -1
- package/dist/server/server/platform/plans/filesystem-plan-status-source.js +118 -13
- package/dist/server/server/platform/plans/org-plan-capabilities.js +2 -2
- package/gestalt-supervision-capabilities.json +8 -2
- package/package.json +1 -1
- package/scripts/watch-github-run.mjs +283 -51
|
@@ -5,82 +5,314 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { execFile } from 'node:child_process';
|
|
8
|
+
import { createHash } from 'node:crypto';
|
|
9
|
+
import { mkdir, open, writeFile } from 'node:fs/promises';
|
|
10
|
+
import { dirname, join } from 'node:path';
|
|
8
11
|
import { promisify } from 'node:util';
|
|
9
12
|
import { pathToFileURL } from 'node:url';
|
|
10
13
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
11
14
|
|
|
12
15
|
const execute = promisify(execFile);
|
|
16
|
+
const statuses = ['queued', 'in_progress', 'completed', 'waiting', 'requested', 'pending'];
|
|
17
|
+
const conclusions = [
|
|
18
|
+
'success',
|
|
19
|
+
'failure',
|
|
20
|
+
'cancelled',
|
|
21
|
+
'timed_out',
|
|
22
|
+
'action_required',
|
|
23
|
+
'neutral',
|
|
24
|
+
'skipped',
|
|
25
|
+
'stale',
|
|
26
|
+
'startup_failure',
|
|
27
|
+
];
|
|
28
|
+
const passing = ['success', 'neutral', 'skipped'];
|
|
29
|
+
const iso = (value) =>
|
|
30
|
+
typeof value === 'string' && Number.isFinite(Date.parse(value))
|
|
31
|
+
? new Date(value).toISOString()
|
|
32
|
+
: null;
|
|
33
|
+
const positive = (value) => Number.isSafeInteger(value) && value > 0;
|
|
13
34
|
|
|
14
|
-
/**
|
|
35
|
+
/** One owner, one expected attempt. Only structural facts reach stdout or evidence. */
|
|
15
36
|
export async function watchGithubRun({
|
|
16
37
|
repository,
|
|
17
38
|
runId,
|
|
39
|
+
attempt,
|
|
40
|
+
candidate,
|
|
41
|
+
evidenceDirectory,
|
|
42
|
+
signal,
|
|
43
|
+
gh = 'gh',
|
|
44
|
+
pollIntervalMs = 30_000,
|
|
45
|
+
maxRetries = 3,
|
|
18
46
|
read = async () => {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
47
|
+
const timeout = AbortSignal.timeout(60_000);
|
|
48
|
+
const commandSignal = signal ? AbortSignal.any([signal, timeout]) : timeout;
|
|
49
|
+
const command = execute(
|
|
50
|
+
gh,
|
|
51
|
+
[
|
|
52
|
+
'run',
|
|
53
|
+
'view',
|
|
54
|
+
runId,
|
|
55
|
+
'--repo',
|
|
56
|
+
repository,
|
|
57
|
+
'--json',
|
|
58
|
+
'databaseId,attempt,headSha,status,conclusion,updatedAt,jobs',
|
|
59
|
+
],
|
|
60
|
+
{ maxBuffer: 4 * 1024 * 1024, signal: commandSignal },
|
|
23
61
|
);
|
|
24
|
-
|
|
62
|
+
const closed = new Promise((resolve) => command.child.once('close', resolve));
|
|
63
|
+
try {
|
|
64
|
+
const { stdout } = await command;
|
|
65
|
+
return JSON.parse(stdout);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (commandSignal.aborted) {
|
|
68
|
+
// Abort rejects before the child necessarily exits. Reap the same
|
|
69
|
+
// owned child, escalating only if it ignores the initial SIGTERM.
|
|
70
|
+
const force = setTimeout(() => command.child.kill('SIGKILL'), 1_000);
|
|
71
|
+
try {
|
|
72
|
+
await closed;
|
|
73
|
+
} finally {
|
|
74
|
+
clearTimeout(force);
|
|
75
|
+
}
|
|
76
|
+
if (timeout.aborted && !signal?.aborted) error.code = 'ETIMEDOUT';
|
|
77
|
+
}
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
25
80
|
},
|
|
26
|
-
wait = () => sleep(
|
|
81
|
+
wait = (ms) => sleep(ms, undefined, { signal }),
|
|
27
82
|
now = () => new Date().toISOString(),
|
|
28
83
|
write = (record) => process.stdout.write(`${JSON.stringify(record)}\n`),
|
|
29
84
|
}) {
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
85
|
+
if (
|
|
86
|
+
typeof repository !== 'string' ||
|
|
87
|
+
repository.length > 200 ||
|
|
88
|
+
!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(repository) ||
|
|
89
|
+
typeof runId !== 'string' ||
|
|
90
|
+
!/^[1-9]\d{0,19}$/.test(runId) ||
|
|
91
|
+
!positive(attempt) ||
|
|
92
|
+
typeof candidate !== 'string' ||
|
|
93
|
+
!/^[a-f0-9]{40}$/i.test(candidate) ||
|
|
94
|
+
typeof evidenceDirectory !== 'string' ||
|
|
95
|
+
!evidenceDirectory ||
|
|
96
|
+
Buffer.byteLength(evidenceDirectory) > 512 ||
|
|
97
|
+
Buffer.byteLength(JSON.stringify(evidenceDirectory)) > 600 ||
|
|
98
|
+
!positive(pollIntervalMs) ||
|
|
99
|
+
pollIntervalMs > 300_000 ||
|
|
100
|
+
!Number.isInteger(maxRetries) ||
|
|
101
|
+
maxRetries < 0 ||
|
|
102
|
+
maxRetries > 5
|
|
103
|
+
) {
|
|
104
|
+
throw new Error('Expected OWNER/REPO RUN_ID ATTEMPT COMMIT_SHA NEW_EVIDENCE_DIRECTORY');
|
|
105
|
+
}
|
|
106
|
+
const identity = { repository, runId, attempt, candidate: candidate.toLowerCase() };
|
|
107
|
+
let journal;
|
|
108
|
+
let bytes = 0;
|
|
109
|
+
const hash = createHash('sha256');
|
|
110
|
+
const counts = { polls: 0, changes: 0, readFailures: 0, failures: 0, jobs: null };
|
|
111
|
+
let firstFailure = null;
|
|
112
|
+
let lastObservation = null;
|
|
113
|
+
let completeness = 'partial';
|
|
114
|
+
const emit = async (event, fields = {}, visible = true) => {
|
|
115
|
+
const record = { event, observedAt: iso(now()), ...identity, ...fields };
|
|
116
|
+
const line = `${JSON.stringify(record)}\n`;
|
|
117
|
+
await journal.writeFile(line);
|
|
118
|
+
hash.update(line);
|
|
119
|
+
bytes += Buffer.byteLength(line);
|
|
120
|
+
if (visible) write(record);
|
|
121
|
+
};
|
|
122
|
+
const finish = async (reason, exitCode) => {
|
|
123
|
+
if (signal?.aborted) {
|
|
124
|
+
reason = 'cancelled';
|
|
125
|
+
exitCode = 130;
|
|
126
|
+
completeness = 'partial';
|
|
39
127
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
128
|
+
const summary = {
|
|
129
|
+
event: 'githubRunFinished',
|
|
130
|
+
observedAt: iso(now()),
|
|
131
|
+
...identity,
|
|
132
|
+
reason,
|
|
133
|
+
exitCode,
|
|
134
|
+
// This observation precedes process exit; it is not the exit timestamp.
|
|
135
|
+
processExitedAt: null,
|
|
136
|
+
completeness,
|
|
137
|
+
coverage: 'workflow-status-and-failure-identities',
|
|
138
|
+
testCounts: null,
|
|
139
|
+
counts,
|
|
140
|
+
firstFailure,
|
|
141
|
+
upstreamUpdatedAt: lastObservation?.upstreamUpdatedAt ?? null,
|
|
142
|
+
status: lastObservation?.status ?? null,
|
|
143
|
+
conclusion: lastObservation?.conclusion ?? null,
|
|
144
|
+
evidence: {
|
|
145
|
+
directory: evidenceDirectory,
|
|
146
|
+
file: 'events.jsonl',
|
|
147
|
+
bytes,
|
|
148
|
+
sha256: hash.copy().digest('hex'),
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
await journal.sync();
|
|
152
|
+
await writeFile(join(evidenceDirectory, 'summary.json'), `${JSON.stringify(summary)}\n`, {
|
|
153
|
+
flag: 'wx',
|
|
154
|
+
mode: 0o600,
|
|
155
|
+
});
|
|
156
|
+
write(summary);
|
|
157
|
+
return exitCode;
|
|
158
|
+
};
|
|
159
|
+
try {
|
|
160
|
+
await mkdir(dirname(evidenceDirectory), { recursive: true });
|
|
161
|
+
// An existing evidence directory belongs to an earlier/active owner. Never
|
|
162
|
+
// overwrite it or launch another poller on the same process evidence handle.
|
|
163
|
+
await mkdir(evidenceDirectory, { mode: 0o700 });
|
|
164
|
+
journal = await open(join(evidenceDirectory, 'events.jsonl'), 'wx', 0o600);
|
|
165
|
+
} catch {
|
|
166
|
+
write({
|
|
167
|
+
event: 'githubRunEvidenceFailed',
|
|
168
|
+
observedAt: iso(now()),
|
|
169
|
+
...identity,
|
|
170
|
+
reason: 'evidenceUnavailable',
|
|
171
|
+
});
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
let previous = null;
|
|
176
|
+
let retries = 0;
|
|
177
|
+
for (;;) {
|
|
178
|
+
if (signal?.aborted) return await finish('cancelled', 130);
|
|
179
|
+
let run;
|
|
180
|
+
try {
|
|
181
|
+
counts.polls += 1;
|
|
182
|
+
run = await read();
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (signal?.aborted) return await finish('cancelled', 130);
|
|
185
|
+
// Classify only; command diagnostics may contain credentials or output.
|
|
186
|
+
const diagnostic = String(error?.stderr ?? error?.code ?? '');
|
|
187
|
+
const rateLimited = /rate limit|HTTP 429/i.test(diagnostic);
|
|
188
|
+
const transient =
|
|
189
|
+
rateLimited ||
|
|
190
|
+
/HTTP 5\d\d|ECONN|ETIMEDOUT|ENET|EAI_AGAIN|TLS handshake|could not resolve|connection|timeout/i.test(
|
|
191
|
+
diagnostic,
|
|
192
|
+
) ||
|
|
193
|
+
error?.killed === true;
|
|
194
|
+
counts.readFailures += 1;
|
|
195
|
+
await emit('githubRunObservationFailed', {
|
|
196
|
+
reason: rateLimited ? 'rateLimited' : transient ? 'network' : 'readFailed',
|
|
197
|
+
retry: transient && retries < maxRetries,
|
|
198
|
+
});
|
|
199
|
+
if (!transient || retries >= maxRetries) return await finish('observationFailed', 1);
|
|
200
|
+
await wait(Math.min(120_000, pollIntervalMs * 2 ** retries++));
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
// A response after cancellation must not certify late success.
|
|
204
|
+
if (signal?.aborted) return await finish('cancelled', 130);
|
|
205
|
+
retries = 0;
|
|
206
|
+
if (
|
|
207
|
+
!run ||
|
|
208
|
+
String(run.databaseId) !== runId ||
|
|
209
|
+
run.attempt !== attempt ||
|
|
210
|
+
typeof run.headSha !== 'string' ||
|
|
211
|
+
run.headSha.toLowerCase() !== identity.candidate
|
|
212
|
+
) {
|
|
213
|
+
await emit('githubRunIdentityChanged', { reason: 'identityMismatch' });
|
|
214
|
+
return await finish('identityMismatch', 1);
|
|
215
|
+
}
|
|
216
|
+
if (!statuses.includes(run.status)) {
|
|
217
|
+
await emit('githubRunObservationFailed', { reason: 'unknownStatus', retry: false });
|
|
218
|
+
return await finish('unknownStatus', 1);
|
|
219
|
+
}
|
|
220
|
+
const conclusion = conclusions.includes(run.conclusion) ? run.conclusion : null;
|
|
221
|
+
lastObservation = { status: run.status, conclusion, upstreamUpdatedAt: iso(run.updatedAt) };
|
|
222
|
+
const semantic = JSON.stringify([run.status, conclusion]);
|
|
223
|
+
if (semantic !== previous) {
|
|
224
|
+
counts.changes += 1;
|
|
225
|
+
await emit('githubRunObserved', lastObservation);
|
|
226
|
+
previous = semantic;
|
|
227
|
+
}
|
|
228
|
+
if (run.status === 'completed') {
|
|
229
|
+
completeness = Array.isArray(run.jobs) ? 'complete' : 'partial';
|
|
230
|
+
counts.jobs = Array.isArray(run.jobs) ? run.jobs.length : null;
|
|
231
|
+
for (const job of Array.isArray(run.jobs) ? run.jobs : []) {
|
|
232
|
+
const jobId = positive(job?.databaseId) ? String(job.databaseId) : null;
|
|
233
|
+
if (!jobId || !conclusions.includes(job?.conclusion) || job?.status !== 'completed')
|
|
234
|
+
completeness = 'partial';
|
|
235
|
+
if (passing.includes(job?.conclusion)) continue;
|
|
236
|
+
const steps = Array.isArray(job?.steps)
|
|
237
|
+
? job.steps.filter((step) => step?.conclusion && !passing.includes(step.conclusion))
|
|
238
|
+
: [];
|
|
239
|
+
if (
|
|
240
|
+
!Array.isArray(job?.steps) ||
|
|
241
|
+
job.steps.some(
|
|
242
|
+
(step) => !positive(step?.number) || !conclusions.includes(step?.conclusion),
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
completeness = 'partial';
|
|
246
|
+
for (const step of steps.length ? steps : [null]) {
|
|
247
|
+
const failure = {
|
|
248
|
+
jobId,
|
|
249
|
+
stepNumber: positive(step?.number) ? step.number : null,
|
|
250
|
+
conclusion: conclusions.includes(step?.conclusion ?? job?.conclusion)
|
|
251
|
+
? (step?.conclusion ?? job?.conclusion)
|
|
252
|
+
: null,
|
|
253
|
+
};
|
|
254
|
+
if (step && (!positive(step.number) || !conclusions.includes(step.conclusion)))
|
|
255
|
+
completeness = 'partial';
|
|
256
|
+
counts.failures += 1;
|
|
257
|
+
firstFailure ??= failure;
|
|
258
|
+
await emit('githubJobFailed', failure, false);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (conclusion && !passing.includes(conclusion) && !firstFailure) {
|
|
262
|
+
firstFailure = { jobId: null, stepNumber: null, conclusion };
|
|
263
|
+
counts.failures += 1;
|
|
264
|
+
await emit('githubRunFailed', firstFailure, false);
|
|
265
|
+
}
|
|
266
|
+
if (!conclusion) completeness = 'partial';
|
|
267
|
+
return await finish(
|
|
268
|
+
'completed',
|
|
269
|
+
conclusion === 'success' && completeness === 'complete' && counts.failures === 0 ? 0 : 1,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
await wait(pollIntervalMs);
|
|
273
|
+
}
|
|
274
|
+
} catch {
|
|
275
|
+
if (signal?.aborted) {
|
|
276
|
+
try {
|
|
277
|
+
return await finish('cancelled', 130);
|
|
278
|
+
} catch {
|
|
279
|
+
/* Preserve incomplete evidence below. */
|
|
280
|
+
}
|
|
48
281
|
}
|
|
49
|
-
const conclusion = [
|
|
50
|
-
'success',
|
|
51
|
-
'failure',
|
|
52
|
-
'cancelled',
|
|
53
|
-
'timed_out',
|
|
54
|
-
'action_required',
|
|
55
|
-
'neutral',
|
|
56
|
-
'skipped',
|
|
57
|
-
'stale',
|
|
58
|
-
'startup_failure',
|
|
59
|
-
].includes(run.conclusion)
|
|
60
|
-
? run.conclusion
|
|
61
|
-
: null;
|
|
62
282
|
write({
|
|
63
|
-
event: '
|
|
64
|
-
observedAt: now(),
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
conclusion,
|
|
68
|
-
upstreamUpdatedAt:
|
|
69
|
-
typeof run.updatedAt === 'string' && Number.isFinite(Date.parse(run.updatedAt))
|
|
70
|
-
? new Date(run.updatedAt).toISOString()
|
|
71
|
-
: null,
|
|
283
|
+
event: 'githubRunEvidenceFailed',
|
|
284
|
+
observedAt: iso(now()),
|
|
285
|
+
...identity,
|
|
286
|
+
reason: 'evidenceIncomplete',
|
|
72
287
|
});
|
|
73
|
-
|
|
74
|
-
|
|
288
|
+
return 1;
|
|
289
|
+
} finally {
|
|
290
|
+
await journal.close();
|
|
75
291
|
}
|
|
76
292
|
}
|
|
77
293
|
|
|
78
294
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
79
|
-
const [repository, runId] = process.argv.slice(2);
|
|
295
|
+
const [repository, runId, attempt, candidate, evidenceDirectory] = process.argv.slice(2);
|
|
296
|
+
const controller = new AbortController();
|
|
297
|
+
const cancel = () => controller.abort();
|
|
298
|
+
process.once('SIGINT', cancel);
|
|
299
|
+
process.once('SIGTERM', cancel);
|
|
80
300
|
try {
|
|
81
|
-
process.exitCode = await watchGithubRun({
|
|
301
|
+
process.exitCode = await watchGithubRun({
|
|
302
|
+
repository,
|
|
303
|
+
runId,
|
|
304
|
+
attempt: Number(attempt),
|
|
305
|
+
candidate,
|
|
306
|
+
evidenceDirectory,
|
|
307
|
+
signal: controller.signal,
|
|
308
|
+
});
|
|
82
309
|
} catch {
|
|
83
|
-
process.stderr.write(
|
|
310
|
+
process.stderr.write(
|
|
311
|
+
'Usage: node watch-github-run.mjs OWNER/REPO RUN_ID ATTEMPT COMMIT_SHA NEW_EVIDENCE_DIRECTORY\n',
|
|
312
|
+
);
|
|
84
313
|
process.exitCode = 1;
|
|
314
|
+
} finally {
|
|
315
|
+
process.removeListener('SIGINT', cancel);
|
|
316
|
+
process.removeListener('SIGTERM', cancel);
|
|
85
317
|
}
|
|
86
318
|
}
|