@tiangong-lca/foundry 0.1.18 → 0.1.19
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/docs/package-distribution-contract.md +5 -5
- package/docs/public-runtime-contract.md +12 -0
- package/docs/runtime-context-contract.md +2 -0
- package/package-dist/assets/foundry-package-descriptor.json +268 -98
- package/package-dist/scripts/foundry-facade.js +3 -0
- package/package-dist/scripts/foundry-runtime.d.ts +1 -1
- package/package-dist/scripts/lib/decision-owners/identity-preflight.js +3 -1
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.d.ts +72 -1
- package/package-dist/scripts/lib/finalize-owners/cli-wrappers.js +123 -3
- package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +9 -0
- package/package-dist/scripts/lib/finalize-owners/post-authoring.js +37 -8
- package/package-dist/scripts/lib/foundry-authentication-environment.js +1 -1
- package/package-dist/scripts/lib/foundry-curation-queue.d.ts +73 -0
- package/package-dist/scripts/lib/foundry-curation-queue.js +261 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.d.ts +17 -0
- package/package-dist/scripts/lib/foundry-edge-draft-admission.js +94 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.d.ts +47 -0
- package/package-dist/scripts/lib/foundry-edge-identity-preflight.js +268 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.d.ts +4 -0
- package/package-dist/scripts/lib/foundry-edge-oauth.js +154 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.d.ts +51 -0
- package/package-dist/scripts/lib/foundry-edge-reference-intent.js +184 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.d.ts +21 -0
- package/package-dist/scripts/lib/foundry-edge-repair-preparation.js +120 -0
- package/package-dist/scripts/lib/foundry-edge-session.d.ts +15 -0
- package/package-dist/scripts/lib/foundry-edge-session.js +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.d.ts +69 -0
- package/package-dist/scripts/lib/foundry-edge-support-plan.js +245 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.d.ts +115 -0
- package/package-dist/scripts/lib/foundry-edge-support-planning.js +259 -0
- package/package-dist/scripts/lib/foundry-edge-support.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-edge-support.js +188 -0
- package/package-dist/scripts/lib/foundry-execution-admission.d.ts +4 -2
- package/package-dist/scripts/lib/foundry-execution-admission.js +24 -2
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.d.ts +30 -0
- package/package-dist/scripts/lib/foundry-finalize-edge-identity.js +102 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-finalize-owners.js +68 -2
- package/package-dist/scripts/lib/foundry-managed-authentication.js +1 -1
- package/package-dist/scripts/lib/foundry-owner-execution-store.d.ts +16 -16
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +34 -7
- package/package-dist/scripts/lib/foundry-owner-readback.d.ts +20 -0
- package/package-dist/scripts/lib/foundry-owner-readback.js +42 -0
- package/package-dist/scripts/lib/foundry-package-contract.d.ts +2 -2
- package/package-dist/scripts/lib/foundry-package-contract.js +2 -2
- package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +71 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.d.ts +64 -0
- package/package-dist/scripts/lib/foundry-process-mass-balance.js +224 -0
- package/package-dist/scripts/lib/foundry-process-qa.d.ts +19 -0
- package/package-dist/scripts/lib/foundry-process-qa.js +423 -0
- package/package-dist/scripts/lib/foundry-repair-execution.js +13 -2
- package/package-dist/scripts/lib/foundry-runtime-environment.d.ts +2 -0
- package/package-dist/scripts/lib/foundry-runtime-environment.js +18 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-identity.js +19 -1
- package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.d.ts +1 -0
- package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.d.ts +76 -0
- package/package-dist/scripts/lib/foundry-typed-authoring-patch.js +237 -0
- package/package-dist/scripts/lib/foundry-typed-context.d.ts +11 -0
- package/package-dist/scripts/lib/foundry-typed-context.js +79 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.d.ts +166 -0
- package/package-dist/scripts/lib/foundry-typed-flow-qa.js +226 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.d.ts +6 -0
- package/package-dist/scripts/lib/foundry-typed-model-write.js +59 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +67 -29
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +82 -1
- package/package-dist/scripts/lib/foundry-workflow-context.js +59 -18
- package/package-dist/scripts/lib/foundry-workflow-execution.js +54 -5
- package/package-dist/scripts/lib/foundry-workflow-finalize.js +27 -3
- package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +202 -161
- package/package-dist/scripts/lib/foundry-workflow-identity.js +16 -10
- package/package-dist/scripts/lib/foundry-workflow-io.js +27 -6
- package/package-dist/scripts/lib/foundry-workflow-reference-verify.js +102 -29
- package/package-dist/scripts/lib/foundry-workflow-repair.js +53 -2
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +41 -21
- package/package-dist/scripts/lib/identity-preflight-proof.d.ts +1 -0
- package/package-dist/scripts/lib/identity-preflight-proof.js +19 -12
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package.json +2 -2
- package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
- package/specs/schemas/foundry-package-descriptor.schema.json +2 -2
- package/specs/schemas/runtime-qualification.schema.json +1 -1
|
@@ -7,6 +7,7 @@ import { captureFoundryInput, FoundryContextError, readFoundryInput, resolveFoun
|
|
|
7
7
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
8
8
|
import { assertVerifiedFoundryIdentity, verifyFoundryRuntimeIdentity, } from "./foundry-runtime-identity.js";
|
|
9
9
|
import { createFoundryAuthenticationEnvironment } from "./foundry-authentication-environment.js";
|
|
10
|
+
import { readRetainedFoundryEdgeIdentity, runFoundryEdgeIdentityPreflight, } from "./foundry-edge-identity-preflight.js";
|
|
10
11
|
import { createFoundryIdentityOwners } from "./foundry-identity-owners.js";
|
|
11
12
|
import { inspectOwnerExecutions } from "./foundry-owner-execution-store.js";
|
|
12
13
|
import { currentFoundryInteractionState, currentFoundryQuestions, currentFoundryInvestigations, } from "./foundry-interaction-input.js";
|
|
@@ -188,118 +189,129 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
188
189
|
state.identity?.value.stage_id !== stageId)
|
|
189
190
|
reject("current-predecessor-changed");
|
|
190
191
|
};
|
|
191
|
-
|
|
192
|
+
const retainedStageFile = (file, command) => withFoundryTaskMetadata(context, (_, index) => {
|
|
193
|
+
validateCurrent(index);
|
|
194
|
+
const entry = index.findLast((item) => item.command === command && path.resolve(context.taskRoot, item.path) === file);
|
|
195
|
+
return entry ? readWorkflowArtifact(context, entry).value : null;
|
|
196
|
+
});
|
|
192
197
|
const environment = createFoundryAuthenticationEnvironment(authentication, context.accountIntent.sessionReference, process.env);
|
|
193
198
|
environment.FOUNDRY_VERIFIED_PROJECT_REF = context.accountIntent.projectRef;
|
|
194
199
|
environment.FOUNDRY_VERIFIED_USER_ID = context.accountIntent.userId;
|
|
195
200
|
fs.mkdirSync(output, { recursive: true, mode: 0o700 });
|
|
196
201
|
try {
|
|
197
|
-
const prepare = await
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
validateCurrent,
|
|
206
|
-
}, (operation) => {
|
|
207
|
-
const identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
208
|
-
const cli = assertCliRuntimeMatches(qualified.cli.expectation);
|
|
209
|
-
const installed = resolveInstalledTiangongLcaCliPackage();
|
|
210
|
-
const root = path.dirname(prepareFile);
|
|
211
|
-
operation.writeText(path.join(root, "selected-intent.json"), selectedBytes(selected));
|
|
212
|
-
operation.writeJson(path.join(root, "identity-receipt.json"), identity.receipt);
|
|
213
|
-
operation.writeJson(path.join(root, "roster.json"), targets);
|
|
214
|
-
operation.writeJson(path.join(root, "runtime-cli-inventory.json"), {
|
|
215
|
-
qualification: qualified,
|
|
216
|
-
cli: {
|
|
217
|
-
root: installed.packageRoot,
|
|
218
|
-
bin: captureFoundryInput(installed.binPath),
|
|
219
|
-
files: cli.files,
|
|
202
|
+
const prepare = (await retainedStageFile(prepareFile, prepareCommand)) ??
|
|
203
|
+
(await runFoundryTaskOperation(context, {
|
|
204
|
+
command: prepareCommand,
|
|
205
|
+
options: {
|
|
206
|
+
stage_id: stageId,
|
|
207
|
+
intent_sha256: intentSha256,
|
|
208
|
+
rows_report_sha256: intent.rows_report_sha256,
|
|
209
|
+
predecessor_identity_sha256: intent.predecessor_identity_sha256,
|
|
220
210
|
},
|
|
221
|
-
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
211
|
+
validateCurrent,
|
|
212
|
+
}, (operation) => {
|
|
213
|
+
const identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
214
|
+
const cli = assertCliRuntimeMatches(qualified.cli.expectation);
|
|
215
|
+
const installed = resolveInstalledTiangongLcaCliPackage();
|
|
216
|
+
const root = path.dirname(prepareFile);
|
|
217
|
+
operation.writeText(path.join(root, "selected-intent.json"), selectedBytes(selected));
|
|
218
|
+
operation.writeJson(path.join(root, "identity-receipt.json"), identity.receipt);
|
|
219
|
+
operation.writeJson(path.join(root, "roster.json"), targets);
|
|
220
|
+
operation.writeJson(path.join(root, "runtime-cli-inventory.json"), {
|
|
221
|
+
qualification: qualified,
|
|
222
|
+
cli: {
|
|
223
|
+
root: installed.packageRoot,
|
|
224
|
+
bin: captureFoundryInput(installed.binPath),
|
|
225
|
+
files: cli.files,
|
|
226
|
+
},
|
|
227
|
+
executable: captureFoundryInput(process.execPath),
|
|
238
228
|
});
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
outDir,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
229
|
+
const preparedTargets = [];
|
|
230
|
+
for (const target of targets) {
|
|
231
|
+
const type = target.dataset_type;
|
|
232
|
+
// The published owner names outputs by ID. A separate version-bound parent prevents collisions.
|
|
233
|
+
const outDir = path.join(root, "targets", sha256Json(target));
|
|
234
|
+
const sourceIndex = path.join(outDir, "source-context.jsonl");
|
|
235
|
+
const rowFile = path.join(outDir, "selected-row.jsonl");
|
|
236
|
+
const row = readRows(target.source_file).find((value) => sha256Json(value) === target.source_row_sha256);
|
|
237
|
+
if (!row)
|
|
238
|
+
reject("prepared-source-row");
|
|
239
|
+
operation.writeText(rowFile, JSON.stringify(row) + "\n");
|
|
240
|
+
operation.writeText(sourceIndex, JSON.stringify({ ...target, source_file: rowFile }) + "\n");
|
|
241
|
+
const owner = createFoundryIdentityOwners(context, qualified, type, {
|
|
242
|
+
environment,
|
|
243
|
+
cwd: root,
|
|
244
|
+
});
|
|
245
|
+
const built = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRequestsBuild({
|
|
246
|
+
type,
|
|
247
|
+
rowsFile: rowFile,
|
|
248
|
+
sourceIndex,
|
|
249
|
+
outDir,
|
|
250
|
+
})));
|
|
251
|
+
const indexFile = resolveFoundryOutput(context, path.resolve(context.assetRoot, String(workflowObject(built.files).identity_preflight_requests)));
|
|
252
|
+
const audited = workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightQueryAudit({
|
|
253
|
+
index: indexFile,
|
|
254
|
+
outDir: path.join(outDir, "query-audit"),
|
|
255
|
+
})));
|
|
256
|
+
if (built.status !== "ready" || audited.status !== "passed")
|
|
257
|
+
reject(`request-query-audit:${JSON.stringify({ prepare: built.blockers, audit: audited.blockers })}`);
|
|
258
|
+
const indexRows = jsonLines(indexFile);
|
|
259
|
+
if (indexRows.length !== 1 ||
|
|
260
|
+
key(indexRows[0]) !== key(target))
|
|
261
|
+
reject("prepared-roster-count");
|
|
262
|
+
const admittedRow = {
|
|
263
|
+
...indexRows[0],
|
|
264
|
+
relevant_input_hashes: {
|
|
265
|
+
registered_rows: captureFoundryInput(target.source_file).sha256,
|
|
266
|
+
source_row: target.source_row_sha256,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
const admittedIndex = path.join(outDir, "admitted-identity-preflight-requests.jsonl");
|
|
270
|
+
operation.writeText(admittedIndex, JSON.stringify(admittedRow) + "\n");
|
|
271
|
+
preparedTargets.push({
|
|
272
|
+
...target,
|
|
273
|
+
owner_source_file: rowFile,
|
|
274
|
+
index: admittedIndex,
|
|
275
|
+
row: admittedRow,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
registerWorkflowStageFiles(context, operation, root);
|
|
279
|
+
const report = {
|
|
280
|
+
schema: "tiangong-foundry.identity-stage-preparation.v1",
|
|
281
|
+
stage_id: stageId,
|
|
282
|
+
intent_id: intent.intent_id,
|
|
283
|
+
descriptor_sha256: selected.descriptor.sha256,
|
|
284
|
+
intent_sha256: intentSha256,
|
|
285
|
+
task_id: context.taskId,
|
|
286
|
+
actor_id: context.actorId,
|
|
287
|
+
rows_report: rowsFile,
|
|
288
|
+
rows_report_sha256: intent.rows_report_sha256,
|
|
289
|
+
predecessor_identity: {
|
|
290
|
+
path: predecessorFile,
|
|
291
|
+
sha256: intent.predecessor_identity_sha256,
|
|
261
292
|
},
|
|
293
|
+
predecessor_identity_sha256: intent.predecessor_identity_sha256,
|
|
294
|
+
qualification_sha256: qualified.qualification_sha256,
|
|
295
|
+
authentication_mode: identity.mode,
|
|
296
|
+
targets: preparedTargets,
|
|
297
|
+
account: {
|
|
298
|
+
project_ref: context.accountIntent.projectRef,
|
|
299
|
+
user_id: context.accountIntent.userId,
|
|
300
|
+
},
|
|
301
|
+
prepared_at_utc: operation.nowIso(),
|
|
262
302
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
...target,
|
|
267
|
-
owner_source_file: rowFile,
|
|
268
|
-
index: admittedIndex,
|
|
269
|
-
row: admittedRow,
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
registerWorkflowStageFiles(context, operation, root);
|
|
273
|
-
const report = {
|
|
274
|
-
schema: "tiangong-foundry.identity-stage-preparation.v1",
|
|
275
|
-
stage_id: stageId,
|
|
276
|
-
intent_id: intent.intent_id,
|
|
277
|
-
descriptor_sha256: selected.descriptor.sha256,
|
|
278
|
-
intent_sha256: intentSha256,
|
|
279
|
-
task_id: context.taskId,
|
|
280
|
-
actor_id: context.actorId,
|
|
281
|
-
rows_report: rowsFile,
|
|
282
|
-
rows_report_sha256: intent.rows_report_sha256,
|
|
283
|
-
predecessor_identity: {
|
|
284
|
-
path: predecessorFile,
|
|
285
|
-
sha256: intent.predecessor_identity_sha256,
|
|
286
|
-
},
|
|
287
|
-
predecessor_identity_sha256: intent.predecessor_identity_sha256,
|
|
288
|
-
qualification_sha256: qualified.qualification_sha256,
|
|
289
|
-
authentication_mode: identity.mode,
|
|
290
|
-
targets: preparedTargets,
|
|
291
|
-
account: {
|
|
292
|
-
project_ref: context.accountIntent.projectRef,
|
|
293
|
-
user_id: context.accountIntent.userId,
|
|
294
|
-
},
|
|
295
|
-
prepared_at_utc: operation.nowIso(),
|
|
296
|
-
};
|
|
297
|
-
operation.writeJson(prepareFile, report);
|
|
298
|
-
return report;
|
|
299
|
-
});
|
|
303
|
+
operation.writeJson(prepareFile, report);
|
|
304
|
+
return report;
|
|
305
|
+
}));
|
|
300
306
|
const preparedTargets = prepare.targets;
|
|
301
|
-
if (
|
|
307
|
+
if (prepare.schema !== "tiangong-foundry.identity-stage-preparation.v1" ||
|
|
308
|
+
prepare.stage_id !== stageId ||
|
|
309
|
+
prepare.intent_sha256 !== intentSha256 ||
|
|
310
|
+
prepare.qualification_sha256 !== qualified.qualification_sha256 ||
|
|
311
|
+
!Array.isArray(preparedTargets) ||
|
|
312
|
+
preparedTargets.length !== targets.length)
|
|
302
313
|
reject("retained-preparation");
|
|
314
|
+
const usesEdge = qualified.cli.expectation.package_version === "0.4.0";
|
|
303
315
|
const accepted = [];
|
|
304
316
|
const blockers = [];
|
|
305
317
|
let invocations = 0;
|
|
@@ -311,55 +323,57 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
311
323
|
const authFile = path.join(targetRoot, "identity-receipt.json"), runDir = path.join(targetRoot, "run");
|
|
312
324
|
let newlyClaimed = false;
|
|
313
325
|
let identity = null;
|
|
314
|
-
const claim = await
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
validateCurrent(index)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
326
|
+
const claim = (await retainedStageFile(claimFile, dispatchCommand)) ??
|
|
327
|
+
(await runFoundryTaskOperation(context, {
|
|
328
|
+
command: dispatchCommand,
|
|
329
|
+
options: { stage_id: stageId, target_id: targetId, intent_sha256: intentSha256 },
|
|
330
|
+
validateCurrent(index) {
|
|
331
|
+
validateCurrent(index);
|
|
332
|
+
// Verify after expensive locked metadata; serialized receipts never extend permission.
|
|
333
|
+
if (!fs.existsSync(claimFile))
|
|
334
|
+
identity = verifyFoundryRuntimeIdentity(context, authentication, process.env, qualified);
|
|
335
|
+
},
|
|
336
|
+
}, (operation) => {
|
|
337
|
+
if (fs.existsSync(claimFile)) {
|
|
338
|
+
// An orphan file without its completed native receipt cannot prove dispatch admission.
|
|
339
|
+
const orphaned = {
|
|
340
|
+
schema: "tiangong-foundry.identity-stage-orphan-observation.v1",
|
|
341
|
+
stage_id: stageId,
|
|
342
|
+
target_id: targetId,
|
|
343
|
+
target,
|
|
344
|
+
claim: captureFoundryInput(claimFile),
|
|
345
|
+
admission_status: "ORPHANED_CLAIM_UNPROVEN",
|
|
346
|
+
};
|
|
347
|
+
operation.writeJson(path.join(targetRoot, "orphaned-claim.json"), orphaned);
|
|
348
|
+
return orphaned;
|
|
349
|
+
}
|
|
350
|
+
if (!identity)
|
|
351
|
+
reject("fresh-dispatch-identity");
|
|
352
|
+
assertVerifiedFoundryIdentity(context, identity, qualified);
|
|
353
|
+
operation.writeJson(authFile, identity.receipt);
|
|
354
|
+
const value = {
|
|
355
|
+
schema: "tiangong-foundry.identity-stage-dispatch.v1",
|
|
328
356
|
stage_id: stageId,
|
|
329
357
|
target_id: targetId,
|
|
358
|
+
intent_id: intent.intent_id,
|
|
330
359
|
target,
|
|
331
|
-
|
|
332
|
-
|
|
360
|
+
auth_receipt: captureFoundryInput(authFile),
|
|
361
|
+
qualification_sha256: qualified.qualification_sha256,
|
|
362
|
+
authentication_mode: identity.mode,
|
|
363
|
+
max_attempts: 1,
|
|
364
|
+
dispatch_state: "CLAIMED_OUTCOME_UNPROVEN",
|
|
365
|
+
claimed_at_utc: new Date().toISOString(),
|
|
333
366
|
};
|
|
334
|
-
operation.writeJson(
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
reject("fresh-dispatch-identity");
|
|
339
|
-
assertVerifiedFoundryIdentity(context, identity, qualified);
|
|
340
|
-
operation.writeJson(authFile, identity.receipt);
|
|
341
|
-
const value = {
|
|
342
|
-
schema: "tiangong-foundry.identity-stage-dispatch.v1",
|
|
343
|
-
stage_id: stageId,
|
|
344
|
-
target_id: targetId,
|
|
345
|
-
intent_id: intent.intent_id,
|
|
346
|
-
target,
|
|
347
|
-
auth_receipt: captureFoundryInput(authFile),
|
|
348
|
-
qualification_sha256: qualified.qualification_sha256,
|
|
349
|
-
authentication_mode: identity.mode,
|
|
350
|
-
max_attempts: 1,
|
|
351
|
-
dispatch_state: "CLAIMED_OUTCOME_UNPROVEN",
|
|
352
|
-
claimed_at_utc: new Date().toISOString(),
|
|
353
|
-
};
|
|
354
|
-
operation.writeJson(claimFile, value);
|
|
355
|
-
newlyClaimed = true;
|
|
356
|
-
return value;
|
|
357
|
-
});
|
|
367
|
+
operation.writeJson(claimFile, value);
|
|
368
|
+
newlyClaimed = true;
|
|
369
|
+
return value;
|
|
370
|
+
}));
|
|
358
371
|
if (newlyClaimed) {
|
|
359
372
|
signal?.throwIfAborted();
|
|
360
|
-
|
|
373
|
+
const fresh = identity;
|
|
374
|
+
if (!fresh)
|
|
361
375
|
reject("fresh-dispatch-identity");
|
|
362
|
-
assertVerifiedFoundryIdentity(context,
|
|
376
|
+
assertVerifiedFoundryIdentity(context, fresh, qualified);
|
|
363
377
|
// Keep CLI startup independent of digest paths and the workspace's .env.
|
|
364
378
|
const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "foundry-identity-stage-"));
|
|
365
379
|
try {
|
|
@@ -371,16 +385,24 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
371
385
|
try {
|
|
372
386
|
if (thisInvocation !== null)
|
|
373
387
|
thisInvocation += 1;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
388
|
+
if (usesEdge)
|
|
389
|
+
await runFoundryEdgeIdentityPreflight(context, qualified, authentication, target.dataset_type, target.index, runDir, {
|
|
390
|
+
dispatchSha256: sha256Json(claim),
|
|
391
|
+
sourceSha256: captureFoundryInput(target.owner_source_file).sha256,
|
|
392
|
+
claimedAt: String(claim.claimed_at_utc),
|
|
393
|
+
receipt: fresh.receipt,
|
|
394
|
+
});
|
|
395
|
+
else
|
|
396
|
+
owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRun({
|
|
397
|
+
index: target.index,
|
|
398
|
+
outDir: runDir,
|
|
399
|
+
authReceipt: authFile,
|
|
400
|
+
expectedProjectRef: context.accountIntent.projectRef,
|
|
401
|
+
expectedUserId: context.accountIntent.userId,
|
|
402
|
+
maxAttempts: 1,
|
|
403
|
+
timeoutMs: 60_000,
|
|
404
|
+
authReceiptMaxAgeMs: 60_000,
|
|
405
|
+
}));
|
|
384
406
|
}
|
|
385
407
|
catch {
|
|
386
408
|
// Retained logs may prove the original result; no new invocation follows this claim.
|
|
@@ -394,7 +416,7 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
394
416
|
await withFoundryTaskMetadata(context, (_, index) => validateCurrent(index));
|
|
395
417
|
try {
|
|
396
418
|
const run = acceptRetainedTarget(context, qualified, target, claim, authFile, runDir, authentication.mode);
|
|
397
|
-
accepted.push({ target, run, runDir });
|
|
419
|
+
accepted.push({ target, ...run, runDir });
|
|
398
420
|
if (invocations !== null)
|
|
399
421
|
invocations += 1;
|
|
400
422
|
}
|
|
@@ -434,8 +456,7 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
434
456
|
}
|
|
435
457
|
registerWorkflowStageFiles(context, operation, retainedDirectories);
|
|
436
458
|
const combined = path.join(resultRoot, "identity-preflight-requests.jsonl");
|
|
437
|
-
operation.writeText(combined, accepted.map(({
|
|
438
|
-
(accepted.length ? "\n" : ""));
|
|
459
|
+
operation.writeText(combined, accepted.map(({ row }) => JSON.stringify(row)).join("\n") + (accepted.length ? "\n" : ""));
|
|
439
460
|
const sets = [];
|
|
440
461
|
const grouped = new Map();
|
|
441
462
|
for (const item of accepted) {
|
|
@@ -445,7 +466,7 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
445
466
|
for (const [groupKey, items] of grouped) {
|
|
446
467
|
const groupRoot = path.join(resultRoot, "sets", sha256Text(groupKey));
|
|
447
468
|
const index = path.join(groupRoot, "identity-preflight-requests.jsonl");
|
|
448
|
-
operation.writeText(index, items.map(({
|
|
469
|
+
operation.writeText(index, items.map(({ row }) => JSON.stringify(row)).join("\n") + "\n");
|
|
449
470
|
const summary = {
|
|
450
471
|
schema: "tiangong-foundry.identity-stage-set.v1",
|
|
451
472
|
remote_write_mode: "read-only",
|
|
@@ -472,7 +493,14 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
472
493
|
status: blockers.length ? "blocked" : "completed",
|
|
473
494
|
mode: "explicit-new-read-only-stage",
|
|
474
495
|
explicit_new_stage: true,
|
|
475
|
-
new_cli_execution:
|
|
496
|
+
new_cli_execution: usesEdge
|
|
497
|
+
? false
|
|
498
|
+
: accepted.length
|
|
499
|
+
? true
|
|
500
|
+
: invocations === null
|
|
501
|
+
? null
|
|
502
|
+
: false,
|
|
503
|
+
...(usesEdge ? { execution_transport: "edge" } : {}),
|
|
476
504
|
stage_id: stageId,
|
|
477
505
|
intent_id: intent.intent_id,
|
|
478
506
|
task_id: context.taskId,
|
|
@@ -488,7 +516,8 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
488
516
|
counts: {
|
|
489
517
|
admitted_targets: preparedTargets.length,
|
|
490
518
|
accepted_targets: accepted.length,
|
|
491
|
-
cli_invocations: invocations,
|
|
519
|
+
cli_invocations: usesEdge ? 0 : invocations,
|
|
520
|
+
...(usesEdge ? { edge_invocations: invocations } : {}),
|
|
492
521
|
underlying_retrievals: null,
|
|
493
522
|
},
|
|
494
523
|
sets,
|
|
@@ -499,7 +528,11 @@ async function runLocked(context, qualified, prefix, selected, authentication, s
|
|
|
499
528
|
});
|
|
500
529
|
return {
|
|
501
530
|
...report,
|
|
502
|
-
this_invocation: {
|
|
531
|
+
this_invocation: {
|
|
532
|
+
cli_invocations: usesEdge ? 0 : thisInvocation,
|
|
533
|
+
...(usesEdge ? { edge_invocations: thisInvocation } : {}),
|
|
534
|
+
underlying_retrievals: null,
|
|
535
|
+
},
|
|
503
536
|
};
|
|
504
537
|
}
|
|
505
538
|
finally {
|
|
@@ -528,6 +561,14 @@ function acceptRetainedTarget(context, qualified, target, claim, authFile, runDi
|
|
|
528
561
|
expectedUserId: context.accountIntent.userId,
|
|
529
562
|
sessionMode: originalMode,
|
|
530
563
|
});
|
|
564
|
+
if (qualified.cli.expectation.package_version === "0.4.0") {
|
|
565
|
+
return readRetainedFoundryEdgeIdentity(context, target.dataset_type, target.row, runDir, originalMode, {
|
|
566
|
+
dispatchSha256: sha256Json(claim),
|
|
567
|
+
sourceSha256: captureFoundryInput(target.owner_source_file).sha256,
|
|
568
|
+
claimedAt: String(claim.claimed_at_utc),
|
|
569
|
+
receipt,
|
|
570
|
+
});
|
|
571
|
+
}
|
|
531
572
|
const runFile = path.join(runDir, "dataset-identity-preflight-run-report.json"), run = readJson(runFile);
|
|
532
573
|
const resolve = (value) => {
|
|
533
574
|
if (typeof value !== "string")
|
|
@@ -672,5 +713,5 @@ function acceptRetainedTarget(context, qualified, target, claim, authFile, runDi
|
|
|
672
713
|
if (!validateBoundExecutionManifest(manifest, binding, reportText).ok ||
|
|
673
714
|
stableJson(manifest) !== stableJson(checked.manifest))
|
|
674
715
|
reject("retained-execution-manifest");
|
|
675
|
-
return run;
|
|
716
|
+
return { run, row: target.row };
|
|
676
717
|
}
|
|
@@ -13,6 +13,7 @@ import { datasetIdentity } from "./import-curation/internal/dataset-payload.js";
|
|
|
13
13
|
import { readRows } from "./import-curation/internal/runtime-io.js";
|
|
14
14
|
import { recoverFoundryWorkflowIdentity } from "./foundry-workflow-identity-recovery.js";
|
|
15
15
|
import { assertNoPendingFoundryIdentityStage } from "./foundry-identity-stage-state.js";
|
|
16
|
+
import { runFoundryEdgeIdentityPreflight } from "./foundry-edge-identity-preflight.js";
|
|
16
17
|
/** Run the existing read-only owner first; the local transaction only records its captured evidence. */
|
|
17
18
|
export async function runFoundryWorkflowIdentity(context, qualified, entries, authentication = { mode: "oauth" }) {
|
|
18
19
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
@@ -90,21 +91,26 @@ export async function runFoundryWorkflowIdentity(context, qualified, entries, au
|
|
|
90
91
|
});
|
|
91
92
|
continue;
|
|
92
93
|
}
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
const runDir = path.join(outDir, "run");
|
|
95
|
+
const edgeResult = qualified.cli.expectation.package_version === "0.4.0"
|
|
96
|
+
? await runFoundryEdgeIdentityPreflight(context, qualified, authentication, set.type, index, runDir)
|
|
97
|
+
: null;
|
|
98
|
+
const result = edgeResult ??
|
|
99
|
+
workflowObject(owner.invoke(() => owner.preflight.runDatasetIdentityPreflightRun({
|
|
100
|
+
index,
|
|
101
|
+
outDir: runDir,
|
|
102
|
+
authReceipt: receipt,
|
|
103
|
+
expectedProjectRef: context.accountIntent.projectRef,
|
|
104
|
+
expectedUserId: context.accountIntent.userId,
|
|
105
|
+
maxAttempts: 1,
|
|
106
|
+
timeoutMs: 60_000,
|
|
107
|
+
})));
|
|
102
108
|
if (!["completed", "completed_with_identity_findings"].includes(String(result.status)))
|
|
103
109
|
blockers.push({ code: "identity_preflight_failed", type: set.type, report: result });
|
|
104
110
|
sets.push({
|
|
105
111
|
type: set.type,
|
|
106
112
|
rows: set.file,
|
|
107
|
-
index,
|
|
113
|
+
index: edgeResult?.index ?? index,
|
|
108
114
|
status: result.status,
|
|
109
115
|
report: workflowObject(result.files).report,
|
|
110
116
|
});
|
|
@@ -5,7 +5,7 @@ import { randomUUID } from "node:crypto";
|
|
|
5
5
|
import { FoundryContextError, assertFoundryWorkspaceWrite, resolveFoundryOutput, } from "./foundry-runtime-context.js";
|
|
6
6
|
import { assertQualifiedFoundryRuntime, } from "./foundry-runtime-qualification.js";
|
|
7
7
|
import { resolveInstalledTiangongLcaCliPackage } from "./foundry-runtime-utils.js";
|
|
8
|
-
import {
|
|
8
|
+
import { withFoundryIsolatedLocalCliEnvironment } from "./foundry-runtime-environment.js";
|
|
9
9
|
import { bindWorkflowChildExecution, workflowChildFailure, WorkflowChildFailure, } from "./foundry-workflow-child-failure.js";
|
|
10
10
|
export function createWorkflowDirectory(context, prefix) {
|
|
11
11
|
assertFoundryWorkspaceWrite(context);
|
|
@@ -64,7 +64,18 @@ export function runWorkflowLocalCli(context, qualified, temporary, argv) {
|
|
|
64
64
|
return result.report;
|
|
65
65
|
}
|
|
66
66
|
export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
67
|
-
const
|
|
67
|
+
const typedDatasetValidation = qualified.cli.expectation.package_version === "0.4.0" &&
|
|
68
|
+
argv[0] === "dataset" &&
|
|
69
|
+
["flow", "process", "model"].includes(argv[1]) &&
|
|
70
|
+
argv[argv.indexOf("--checks") + 1] === "schema,business" &&
|
|
71
|
+
argv[2] === "validate";
|
|
72
|
+
const typedPatch = qualified.cli.expectation.package_version === "0.4.0" &&
|
|
73
|
+
argv[0] === "dataset" &&
|
|
74
|
+
["flow", "process", "model", "contact", "source", "unitgroup", "flowproperty"].includes(argv[1]) &&
|
|
75
|
+
argv[2] === "patch";
|
|
76
|
+
const local = typedDatasetValidation ||
|
|
77
|
+
typedPatch ||
|
|
78
|
+
(argv[0] === "dataset" && argv[1] === "validate") ||
|
|
68
79
|
(argv[0] === "qa" && ["flow", "process", "lifecyclemodel"].includes(argv[1])) ||
|
|
69
80
|
(argv[0] === "dataset" && argv[1] === "curation-queue" && argv[2] === "build") ||
|
|
70
81
|
(argv[0] === "dataset" &&
|
|
@@ -76,14 +87,14 @@ export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
|
76
87
|
assertQualifiedFoundryRuntime(context, qualified);
|
|
77
88
|
const cli = resolveInstalledTiangongLcaCliPackage();
|
|
78
89
|
const execution = bindWorkflowChildExecution(context, qualified, cli.binPath, argv);
|
|
79
|
-
const child = spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
90
|
+
const child = withFoundryIsolatedLocalCliEnvironment(temporary, (env) => spawnSync(process.execPath, [cli.binPath, ...argv], {
|
|
80
91
|
cwd: context.workspaceRoot,
|
|
81
|
-
env
|
|
92
|
+
env,
|
|
82
93
|
encoding: "utf8",
|
|
83
94
|
shell: false,
|
|
84
95
|
timeout: 120_000,
|
|
85
96
|
maxBuffer: 8 * 1024 * 1024,
|
|
86
|
-
});
|
|
97
|
+
}));
|
|
87
98
|
const kind = child.error
|
|
88
99
|
? "spawn_error"
|
|
89
100
|
: child.signal
|
|
@@ -104,7 +115,17 @@ export function runWorkflowLocalCliResult(context, qualified, temporary, argv) {
|
|
|
104
115
|
}
|
|
105
116
|
if (!report || typeof report !== "object" || Array.isArray(report))
|
|
106
117
|
throw workflowChildFailure(execution, child, "invalid_report");
|
|
107
|
-
|
|
118
|
+
const envelope = report;
|
|
119
|
+
const patchError = typedPatch &&
|
|
120
|
+
envelope.status === "failed" &&
|
|
121
|
+
envelope.outcome === "invalid_input" &&
|
|
122
|
+
typeof envelope.error === "object" &&
|
|
123
|
+
envelope.error !== null &&
|
|
124
|
+
Object.hasOwn(envelope.error, "code") &&
|
|
125
|
+
Object.hasOwn(envelope.error, "message");
|
|
126
|
+
if (("error" in report &&
|
|
127
|
+
!((typedDatasetValidation || typedPatch) && report.error === null) &&
|
|
128
|
+
!patchError) ||
|
|
108
129
|
!("status" in report) ||
|
|
109
130
|
typeof report.status !== "string" ||
|
|
110
131
|
!report.status.trim())
|