@tiangong-lca/foundry 0.1.17 → 0.1.18

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 (111) hide show
  1. package/README.md +23 -7
  2. package/docs/architecture.md +15 -3
  3. package/docs/foundry-task-contracts.md +27 -3
  4. package/docs/package-distribution-contract.md +45 -13
  5. package/docs/public-runtime-contract.md +73 -5
  6. package/docs/runtime-context-contract.md +20 -4
  7. package/docs/task-authorization-contract.md +15 -3
  8. package/docs/workspace-migration-contract.md +5 -3
  9. package/package-dist/assets/foundry-package-descriptor.json +333 -139
  10. package/package-dist/scripts/foundry-facade.d.ts +5 -0
  11. package/package-dist/scripts/foundry-facade.js +258 -16
  12. package/package-dist/scripts/foundry-runtime.d.ts +1 -1
  13. package/package-dist/scripts/lib/bundle-sample-utils.d.ts +4 -4
  14. package/package-dist/scripts/lib/bundle-source-context.d.ts +6 -4
  15. package/package-dist/scripts/lib/bundle-source-context.js +10 -8
  16. package/package-dist/scripts/lib/decision-owners/identity-preflight.js +16 -6
  17. package/package-dist/scripts/lib/finalize-owners/post-authoring.d.ts +2 -1
  18. package/package-dist/scripts/lib/finalize-owners/post-authoring.js +28 -1
  19. package/package-dist/scripts/lib/foundry-assessment-producer.d.ts +6 -0
  20. package/package-dist/scripts/lib/foundry-assessment-producer.js +167 -0
  21. package/package-dist/scripts/lib/foundry-command-metadata.js +6 -1
  22. package/package-dist/scripts/lib/foundry-decision-owners.d.ts +1 -1
  23. package/package-dist/scripts/lib/foundry-decision-owners.js +15 -7
  24. package/package-dist/scripts/lib/foundry-execution-admission.js +4 -1
  25. package/package-dist/scripts/lib/foundry-finalize-owners.js +64 -17
  26. package/package-dist/scripts/lib/foundry-identity-stage-input.d.ts +24 -0
  27. package/package-dist/scripts/lib/foundry-identity-stage-input.js +122 -0
  28. package/package-dist/scripts/lib/foundry-identity-stage-state.d.ts +17 -0
  29. package/package-dist/scripts/lib/foundry-identity-stage-state.js +48 -0
  30. package/package-dist/scripts/lib/foundry-installed-entry.d.ts +2 -0
  31. package/package-dist/scripts/lib/foundry-installed-entry.js +173 -0
  32. package/package-dist/scripts/lib/foundry-managed-adoption.d.ts +12 -0
  33. package/package-dist/scripts/lib/foundry-managed-adoption.js +108 -0
  34. package/package-dist/scripts/lib/foundry-managed-authentication.d.ts +4 -0
  35. package/package-dist/scripts/lib/foundry-managed-authentication.js +28 -0
  36. package/package-dist/scripts/lib/foundry-managed-host.js +14 -2
  37. package/package-dist/scripts/lib/foundry-migration-transfer-io.d.ts +2 -0
  38. package/package-dist/scripts/lib/foundry-migration-transfer-io.js +27 -3
  39. package/package-dist/scripts/lib/foundry-operation-result.d.ts +1 -1
  40. package/package-dist/scripts/lib/foundry-operation-result.js +1 -0
  41. package/package-dist/scripts/lib/foundry-package-contract.d.ts +4 -4
  42. package/package-dist/scripts/lib/foundry-package-contract.js +10 -2
  43. package/package-dist/scripts/lib/foundry-preparation-cli-validation.d.ts +2 -0
  44. package/package-dist/scripts/lib/foundry-preparation-cli-validation.js +25 -3
  45. package/package-dist/scripts/lib/foundry-quality-review-context.d.ts +3 -0
  46. package/package-dist/scripts/lib/foundry-quality-review-context.js +18 -0
  47. package/package-dist/scripts/lib/foundry-quality-review-input.d.ts +48 -0
  48. package/package-dist/scripts/lib/foundry-quality-review-input.js +284 -0
  49. package/package-dist/scripts/lib/foundry-quality-review-lineage.d.ts +13 -0
  50. package/package-dist/scripts/lib/foundry-quality-review-lineage.js +123 -0
  51. package/package-dist/scripts/lib/foundry-quality-review.d.ts +112 -0
  52. package/package-dist/scripts/lib/foundry-quality-review.js +487 -0
  53. package/package-dist/scripts/lib/foundry-runtime-identity.js +3 -1
  54. package/package-dist/scripts/lib/foundry-runtime-qualification.js +2 -2
  55. package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
  56. package/package-dist/scripts/lib/foundry-task-authorization.d.ts +2 -1
  57. package/package-dist/scripts/lib/foundry-task-authorization.js +32 -11
  58. package/package-dist/scripts/lib/foundry-task-registration.js +4 -5
  59. package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.d.ts +28 -0
  60. package/package-dist/scripts/lib/foundry-task-runtime-adoption-write.js +250 -0
  61. package/package-dist/scripts/lib/foundry-task-runtime-adoption.d.ts +60 -0
  62. package/package-dist/scripts/lib/foundry-task-runtime-adoption.js +549 -0
  63. package/package-dist/scripts/lib/foundry-task-store.d.ts +4 -1
  64. package/package-dist/scripts/lib/foundry-task-store.js +113 -4
  65. package/package-dist/scripts/lib/foundry-task-types.d.ts +2 -1
  66. package/package-dist/scripts/lib/foundry-validation-reference-context.d.ts +8 -0
  67. package/package-dist/scripts/lib/foundry-validation-reference-context.js +115 -0
  68. package/package-dist/scripts/lib/foundry-workflow-assessment.d.ts +1 -0
  69. package/package-dist/scripts/lib/foundry-workflow-assessment.js +115 -22
  70. package/package-dist/scripts/lib/foundry-workflow-authorization.js +17 -4
  71. package/package-dist/scripts/lib/foundry-workflow-child-failure.d.ts +44 -0
  72. package/package-dist/scripts/lib/foundry-workflow-child-failure.js +439 -0
  73. package/package-dist/scripts/lib/foundry-workflow-context.js +37 -8
  74. package/package-dist/scripts/lib/foundry-workflow-finalize.js +37 -0
  75. package/package-dist/scripts/lib/foundry-workflow-identity-recovery.d.ts +6 -0
  76. package/package-dist/scripts/lib/foundry-workflow-identity-recovery.js +450 -0
  77. package/package-dist/scripts/lib/foundry-workflow-identity-stage.d.ts +9 -0
  78. package/package-dist/scripts/lib/foundry-workflow-identity-stage.js +676 -0
  79. package/package-dist/scripts/lib/foundry-workflow-identity.js +10 -1
  80. package/package-dist/scripts/lib/foundry-workflow-io.d.ts +7 -1
  81. package/package-dist/scripts/lib/foundry-workflow-io.js +76 -11
  82. package/package-dist/scripts/lib/foundry-workflow-semantic.js +27 -13
  83. package/package-dist/scripts/lib/foundry-workflow-state.d.ts +4 -0
  84. package/package-dist/scripts/lib/foundry-workflow-state.js +165 -22
  85. package/package-dist/scripts/lib/identity-preflight-artifacts.d.ts +4 -7
  86. package/package-dist/scripts/lib/identity-preflight-artifacts.js +18 -5
  87. package/package-dist/scripts/lib/identity-preflight-proof.d.ts +5 -0
  88. package/package-dist/scripts/lib/identity-preflight-proof.js +73 -1
  89. package/package-dist/scripts/lib/identity-preflight-recovery-proof.d.ts +78 -0
  90. package/package-dist/scripts/lib/identity-preflight-recovery-proof.js +415 -0
  91. package/package-dist/scripts/lib/import-curation/curation-cleanup.d.ts +9 -1
  92. package/package-dist/scripts/lib/import-curation/curation-cleanup.js +39 -2
  93. package/package-dist/scripts/lib/import-curation/curation-gate.d.ts +1 -0
  94. package/package-dist/scripts/lib/import-curation/curation-gate.js +19 -1
  95. package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
  96. package/package-dist/scripts/lib/import-curation/internal/workflow-identity-preflight.js +11 -2
  97. package/package-dist/scripts/lib/import-curation/internal/workflow-reference-closure.js +4 -1
  98. package/package-dist/scripts/package-entry.js +2 -3
  99. package/package-dist/scripts/public-api.d.ts +5 -0
  100. package/package-dist/scripts/public-api.js +2 -0
  101. package/package-dist/scripts/runtime-entry.d.ts +2 -0
  102. package/package-dist/scripts/runtime-entry.js +42 -15
  103. package/package.json +6 -2
  104. package/specs/schemas/foundry-identity-stage-input.schema.json +47 -0
  105. package/specs/schemas/foundry-managed-adoption.schema.json +40 -0
  106. package/specs/schemas/foundry-managed-runtime.schema.json +1 -1
  107. package/specs/schemas/foundry-operation-result.schema.json +1 -0
  108. package/specs/schemas/foundry-package-descriptor.schema.json +6 -2
  109. package/specs/schemas/foundry-quality-review-draft.schema.json +271 -0
  110. package/specs/schemas/foundry-quality-review-input.schema.json +271 -0
  111. package/specs/schemas/runtime-qualification.schema.json +1 -1
@@ -2,6 +2,7 @@ import path from "node:path";
2
2
  import { datasetTypeFromOptions, datasetTypePlural } from "./internal/dataset-types.js";
3
3
  import { datasetIdentity } from "./internal/dataset-payload.js";
4
4
  import { sha256Json } from "./internal/hash-utils.js";
5
+ import { projectFoundryValidationReferences } from "../foundry-validation-reference-context.js";
5
6
  import { annualSupplyFieldPath, applyDeterministicSourceExchangeCompletenessProofs, buildSourceRowsByIdentity, ensureFoundryTraceNamespaces, externalizeImportTraceMetadata, normalizeAnnualSupplyEvidence, normalizeDateTimeMetadata, sanitizeFoundryTraceEvidenceLocators, } from "./internal/prewrite-cleanup.js";
6
7
  import { fileExists, jsonLines, nowIso, readRows, repoRelativePath, resolveRepoPath, writeJson, writeText, } from "./internal/runtime-io.js";
7
8
  function dateTimeBlockersFromError(error) {
@@ -13,13 +14,15 @@ function dateTimeBlockersFromError(error) {
13
14
  }
14
15
  return record.blockers.filter((blocker) => Boolean(blocker) && typeof blocker === "object" && !Array.isArray(blocker));
15
16
  }
16
- export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {}) {
17
+ export function runDatasetCurationCleanup({ repoRoot, options = {}, processValidationReferences, io, } = {}) {
17
18
  const readInputRows = io?.readRows ?? readRows;
18
19
  const hasFile = io?.fileExists ?? fileExists;
19
20
  const writeReport = io?.writeJson ?? writeJson;
20
21
  const writeRows = io?.writeText ?? writeText;
21
22
  const capturedAt = io?.nowIso ?? nowIso;
22
23
  const datasetType = datasetTypeFromOptions(options);
24
+ if (processValidationReferences && datasetType !== "process")
25
+ throw new Error("Selected Flow validation evidence belongs only to Process cleanup.");
23
26
  if (options.help) {
24
27
  return {
25
28
  schema_version: 2,
@@ -53,6 +56,18 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
53
56
  const sourceRowsByKey = sourceRows.length > 0 ? buildSourceRowsByIdentity(sourceRows) : null;
54
57
  const rows = readInputRows(rowsFile);
55
58
  const cleanedRows = rows.map((row) => JSON.parse(JSON.stringify(row)));
59
+ // Supplemental validation evidence is not candidate metadata. In particular, a
60
+ // complete referenced Flow must retain its exact body across recursive cleanup.
61
+ const validationContexts = cleanedRows.map((value) => {
62
+ if (datasetType !== "process" || !value || typeof value !== "object" || Array.isArray(value))
63
+ return null;
64
+ const row = value;
65
+ if (!Object.hasOwn(row, "semantic_context"))
66
+ return null;
67
+ const context = { value: row.semantic_context };
68
+ delete row.semantic_context;
69
+ return context;
70
+ });
56
71
  let normalizedDateTimeValues = 0;
57
72
  const invalidDateTimeBlockers = [];
58
73
  cleanedRows.forEach((cleaned, rowIndex) => {
@@ -167,6 +182,10 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
167
182
  redactedFoundryTraceEvidenceLocators += sanitizeFoundryTraceEvidenceLocators(cleaned);
168
183
  addedFoundryTraceNamespaces += ensureFoundryTraceNamespaces(cleaned);
169
184
  });
185
+ validationContexts.forEach((context, index) => {
186
+ if (context)
187
+ cleanedRows[index].semantic_context = context.value;
188
+ });
170
189
  // Bound only after every other cleanup transform has run, so the output hash describes the
171
190
  // exact unwrapped payload the caller will write, with no row metadata mixed in.
172
191
  const annualSupplyEvidenceGaps = pendingAnnualSupplyGaps.map((pending) => {
@@ -184,7 +203,12 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
184
203
  output_payload_sha256: sha256Json(outputIdentity.payload),
185
204
  };
186
205
  });
187
- writeRows(outFile, jsonLines(cleanedRows));
206
+ // Project only after cleanup, so selected reference bodies never enter its
207
+ // recursive candidate transforms. All later owners use this same final file.
208
+ const finalRows = processValidationReferences
209
+ ? projectFoundryValidationReferences(cleanedRows, processValidationReferences.rows)
210
+ : cleanedRows;
211
+ writeRows(outFile, jsonLines(finalRows));
188
212
  const report = {
189
213
  schema_version: 2,
190
214
  generated_at_utc: capturedAt(),
@@ -194,6 +218,19 @@ export function runDatasetCurationCleanup({ repoRoot, options = {}, io, } = {})
194
218
  remote_write_mode: "read-only",
195
219
  rows_file: repoRelativePath(root, rowsFile),
196
220
  cleaned_rows_file: repoRelativePath(root, outFile),
221
+ ...(processValidationReferences
222
+ ? {
223
+ process_validation_references: {
224
+ files: processValidationReferences.files,
225
+ rows: finalRows.map((row, rowIndex) => ({
226
+ row_index: rowIndex,
227
+ input_payload_sha256: sha256Json(datasetIdentity(cleanedRows[rowIndex], rowIndex, datasetType).payload),
228
+ output_payload_sha256: sha256Json(datasetIdentity(row, rowIndex, datasetType).payload),
229
+ flow_documents_sha256: sha256Json(row.semantic_context.flow_documents),
230
+ })),
231
+ },
232
+ }
233
+ : {}),
197
234
  counts: {
198
235
  rows: cleanedRows.length,
199
236
  blockers: 0,
@@ -45,6 +45,7 @@ interface CurationGateArgs {
45
45
  cliValidation?: {
46
46
  report: string;
47
47
  exit: number;
48
+ input?: import("../foundry-runtime-context.ts").FoundryInputFact;
48
49
  };
49
50
  }
50
51
  export declare function runDatasetCurationGate({ repoRoot, options, routeAction, requireIdentityPreflight, cliValidation, }?: CurationGateArgs): JsonRecord;
@@ -1,5 +1,6 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { reviewedFoundryQualityFindings } from "../foundry-quality-review.js";
3
4
  import { readPreparationCliEvidence, preparationValidationActions, preparationValidationEvidence, } from "../foundry-preparation-cli-validation.js";
4
5
  import * as curationGateWorkflow from "./internal/curation-gate-workflow.js";
5
6
  const { authoringQueueRowsForIdentity, buildIdentityPreflightAuthoringContext, buildQueueAuthoringContext, classificationQueueActionItem, classificationQueueRowStillNeedsAuthoring, collectBundledSchemaContextFiles, collectContextDirFiles, collectExplicitContextFiles, collectProfileSemanticActionItems, contextFileDetails, datasetIdentity, datasetTypeFromOptions, datasetTypePlural, ensureArray, entityIdFromFinding, fileExists, fullContextAiCompletionRequirement, fullContextGateItems, identityDecisionApplyContextDecisionsForIdentity, identityDecisionApplyReportOptionValues, identityKey, identityPreflightAuthoringActionItems, identityPreflightGateItems, jsonLines, locationQueueActionItem, locationQueueRowStillNeedsAuthoring, mapRowsByIdentity, nowIso, profileFor, qaFindingCode, qaFindingCurationAction, readAuthoringQueueContext, readCanonicalSupportRewriteContext, readClassificationDecisionApplyContext, readCleanupTransformContext, readContextFiles, readCurationQueueContext, readIdentityDecisionApplyContexts, readIdentityPreflightContext, readIdentityReferenceRewriteContext, readJson, readJsonArtifactsIfOption, readJsonIfOption, readQaFindings, readRows, readSourceContactRewriteContext, readText, readUnresolvedExchangeExternalizationContext, repoRelativePath, resolveRepoPath, sanitizeFileName, schemaIssueCurationAction, sha256Text, unresolvedExchangeExternalizationRowsForIdentity, writeJson, writeText, } = curationGateWorkflow;
@@ -55,6 +56,9 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
55
56
  const schemaReport = readJson(schemaReportPath);
56
57
  const qaReport = readJson(qaReportPath);
57
58
  const qaFindings = readQaFindings(root, qaReport, qaReportPath, datasetType);
59
+ const qualityReviews = options.qualityReview && datasetType === "process"
60
+ ? reviewedFoundryQualityFindings(options.qualityReview, rowsFile, qaReport, qaFindings, options.cleanupReport)
61
+ : [];
58
62
  const profileContext = readContextFiles(root, profile.docs.map((filePath) => [
59
63
  "profile",
60
64
  filePath,
@@ -174,7 +178,11 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
174
178
  const schemaIssues = ensureArray(schemaRow?.issues);
175
179
  const entityQaFindings = qaFindingsById.get(identity.id) ?? [];
176
180
  const waivedFindings = entityQaFindings.filter((finding) => waivedQaCodes.has(qaFindingCode(finding)));
177
- const actionableQaFindings = entityQaFindings.filter((finding) => !waivedQaCodes.has(qaFindingCode(finding)));
181
+ const reviewedFindings = qualityReviews.filter((review) => review.row_index === index &&
182
+ review.id === identity.id &&
183
+ review.version === identity.version);
184
+ const actionableQaFindings = entityQaFindings.filter((finding) => !waivedQaCodes.has(qaFindingCode(finding)) &&
185
+ !reviewedFindings.some((review) => review.finding === finding));
178
186
  const schemaActionItems = schemaIssues.map((issue) => schemaIssueCurationAction(issue));
179
187
  const qaActionItems = actionableQaFindings.map((finding) => qaFindingCurationAction(finding, datasetType));
180
188
  const semanticActionItems = collectProfileSemanticActionItems({
@@ -306,6 +314,7 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
306
314
  }
307
315
  : {}),
308
316
  qa_findings: entityQaFindings,
317
+ ...(reviewedFindings.length ? { reviewed_findings: reviewedFindings } : {}),
309
318
  waived_findings: waivedFindings.map((finding) => ({
310
319
  ...finding,
311
320
  waiver_basis: profile.waiverReasons?.[qaFindingCode(finding)] ?? null,
@@ -389,6 +398,12 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
389
398
  qa_finding_count: entityQaFindings.length,
390
399
  ...(datasetType === "process" ? { process_qa_finding_count: entityQaFindings.length } : {}),
391
400
  waived_finding_count: waivedFindings.length,
401
+ ...(reviewedFindings.length
402
+ ? {
403
+ reviewed_finding_count: reviewedFindings.length,
404
+ quality_review_receipt_sha256: reviewedFindings[0].receipt_sha256,
405
+ }
406
+ : {}),
392
407
  action_item_count: actionItems.length,
393
408
  identity_action_item_count: identityPreflightActionItems.length,
394
409
  identity_decision_apply_count: identityDecisionApplyRows.length,
@@ -432,6 +447,9 @@ export function runDatasetCurationGate({ repoRoot, options = {}, routeAction, re
432
447
  }
433
448
  : {}),
434
449
  qa_report: repoRelativePath(root, qaReportPath),
450
+ ...(qualityReviews.length
451
+ ? { quality_review_receipt_sha256: qualityReviews[0].receipt_sha256 }
452
+ : {}),
435
453
  policy: {
436
454
  cli_qa_role: "deterministic_qa_report_only",
437
455
  ...(cliValidation
@@ -6,7 +6,7 @@ import { asText, directoryExists, ensureArray, fileExists, readJson, readText, r
6
6
  function asJsonRecord(value) {
7
7
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
8
8
  }
9
- export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.1.27/assets/tidas-schemas"];
9
+ export const tidasSchemaSearchRoots = ["@tiangong-lca/cli@0.1.28/assets/tidas-schemas"];
10
10
  export function tidasSchemaPath(repoRoot, schemaFile) {
11
11
  void repoRoot;
12
12
  const candidate = path.join(resolveInstalledTiangongLcaCliPackage().schemaDir, schemaFile);
@@ -1,5 +1,6 @@
1
1
  import path from "node:path";
2
2
  import { validateIdentityPreflightEvidence } from "../../identity-preflight-proof.js";
3
+ import { validateIdentityPreflightRecoveryEvidence } from "../../identity-preflight-recovery-proof.js";
3
4
  import { readJsonLinesIfExists, resolveArtifactPath } from "./artifact-inputs.js";
4
5
  import { dataSetInformation, datasetRoot, identityFreshnessIdentityKey, } from "./dataset-payload.js";
5
6
  import { sha256Json } from "./hash-utils.js";
@@ -51,7 +52,9 @@ export function readIdentityPreflightIndexRow(repoRoot, indexPath, row) {
51
52
  const resultPath = identityPreflightResultFile(repoRoot, indexPath, row);
52
53
  const result = resultPath ? readJsonIfExists(resultPath) : null;
53
54
  const resultText = resultPath && fileExists(resultPath) ? readText(resultPath) : null;
54
- const executionManifestPath = resolveArtifactPath(repoRoot, asText(typedRow.execution_manifest_file ?? typedRow.executionManifestFile), baseDir) ??
55
+ const executionManifestPath = resolveArtifactPath(repoRoot, asText(typedRow.recovery_manifest_file ??
56
+ typedRow.execution_manifest_file ??
57
+ typedRow.executionManifestFile), baseDir) ??
55
58
  (resultPath
56
59
  ? path.join(path.dirname(resultPath), "foundry-identity-preflight-execution.json")
57
60
  : null);
@@ -61,7 +64,13 @@ export function readIdentityPreflightIndexRow(repoRoot, indexPath, row) {
61
64
  const targetSha256 = typedRow.target_sha256 ??
62
65
  typedRow.targetSha256 ??
63
66
  (request ? sha256Json(request.target ?? null) : null);
64
- const executionEvidence = validateIdentityPreflightEvidence(executionManifest, {
67
+ const validateEvidence = typedRow.recovery_manifest_file
68
+ ? validateIdentityPreflightRecoveryEvidence
69
+ : validateIdentityPreflightEvidence;
70
+ const executionEvidence = validateEvidence(executionManifest, {
71
+ ...(typedRow.recovery_manifest_file
72
+ ? { expectedRetainedCliContentSha256: asText(typedRow.recovery_cli_content_sha256) }
73
+ : {}),
65
74
  requestText,
66
75
  reportText: resultText,
67
76
  datasetType,
@@ -444,7 +444,10 @@ export function buildReferenceClosureBlockers({ repoRoot, rows, datasetType, rem
444
444
  const blockers = [];
445
445
  const seen = new Set();
446
446
  rows.forEach((row, rowIndex) => {
447
- for (const ref of collectDatasetReferences(row)) {
447
+ // Supplemental validation documents stay bound to the row envelope, but
448
+ // business closure follows the same payload used by the write candidate.
449
+ const payload = datasetIdentity(row, rowIndex, datasetType).payload;
450
+ for (const ref of collectDatasetReferences(payload)) {
448
451
  if (!ref.table) {
449
452
  const key = `unsupported\u0000${rowIndex}\u0000${ref.id}\u0000${ref.path}`;
450
453
  if (seen.has(key))
@@ -1,4 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import { runFoundryPublicCommand } from "./runtime-entry.js";
3
- import { receiveFoundryManagedHost } from "./lib/foundry-managed-host.js";
4
- void runFoundryPublicCommand(process.argv, {}, receiveFoundryManagedHost);
2
+ import { runFoundryInstalledCommand } from "./lib/foundry-installed-entry.js";
3
+ void runFoundryInstalledCommand();
@@ -9,6 +9,7 @@ export declare function createFoundryWorkspaceAccess(input: {
9
9
  export type FoundryPackageFacadeOptions = Omit<FoundryFacadeOptions, "moduleUrl">;
10
10
  export type { FoundryFacadeRuntimeSelection } from "./foundry-facade.ts";
11
11
  export { FOUNDRY_AUTHORIZATION_INPUT_SCHEMA, type FoundryAuthorizationInput, } from "./lib/foundry-authorization-input.ts";
12
+ export { FOUNDRY_QUALITY_REVIEW_INPUT_SCHEMA, type FoundryQualityReviewInput, type FoundryQualityReviewEvidence, } from "./lib/foundry-quality-review-input.ts";
12
13
  export type { FoundryAuthentication, FoundryPublicOAuthConfiguration, } from "./lib/foundry-runtime-identity.ts";
13
14
  export { FOUNDRY_SEMANTIC_INPUT_SCHEMA, type FoundrySemanticInput, type SemanticPatchInput, type SemanticDecisionInput, type SemanticSubmission, } from "./lib/foundry-semantic-input.ts";
14
15
  export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, type FoundryInteractionInput, type FoundryInteractionState, } from "./lib/foundry-interaction-input.ts";
@@ -17,6 +18,7 @@ export { FOUNDRY_RUNTIME_SELECTION_SCHEMA, type FoundryRuntimeSelectionRecord, }
17
18
  export type { FoundryRuntimeManagerOptions } from "./lib/foundry-runtime-selection.ts";
18
19
  /** Public host factory with package/source identity bound by this module, never caller input. */
19
20
  export declare function createFoundryFacade(options: FoundryPackageFacadeOptions): Readonly<{
21
+ adoptTaskRuntime(input: import("./lib/foundry-task-runtime-adoption.ts").FoundryTaskRuntimeAdoptionInput): Promise<import("./lib/foundry-operation-result.ts").FoundryOperationResult>;
20
22
  runtimeUse(input: {
21
23
  manifest: import("@tiangong-lca/cli/runtime").TrustedRuntimeManifest;
22
24
  requestId: string;
@@ -66,6 +68,8 @@ export declare function createFoundryFacade(options: FoundryPackageFacadeOptions
66
68
  interactionInputFile?: string;
67
69
  authorizationInputFile?: string;
68
70
  referenceInputFile?: string;
71
+ identityStageInputFile?: string;
72
+ qualityReviewInputFile?: string;
69
73
  }): Promise<import("./lib/foundry-operation-result.ts").FoundryOperationResult>;
70
74
  requestBinding(input: {
71
75
  taskId: string;
@@ -81,3 +85,4 @@ export { FOUNDRY_MIGRATION_TRANSFER_RECEIPT_SCHEMA, type FoundryMigrationTransfe
81
85
  export { FOUNDRY_MIGRATION_ADOPTION_PLAN_SCHEMA, type FoundryMigrationAdoptionPlan, type MigrationAdoptionSelection, } from "./lib/foundry-migration-adoption-plan.ts";
82
86
  export { FOUNDRY_MIGRATION_ACTIVATION_SCHEMA, FOUNDRY_MIGRATED_WORKSPACE_SCHEMA, type FoundryMigrationActivation, type MigrationTaskAuthority, } from "./lib/foundry-migration-authority.ts";
83
87
  export { FOUNDRY_PACKAGE_DESCRIPTOR_SCHEMA, FoundryPackageError, assertFoundryPackage, assertFoundryPackageDescriptor, type FoundryPackageDescriptor, type FoundryPackageFileFact, } from "./lib/foundry-package-contract.ts";
88
+ export { createFoundryRuntimeAdoptionQualification, type TrustedFoundryRuntimeAdoptionQualification, type FoundryTaskRuntimeAdoptionInput, } from "./lib/foundry-task-runtime-adoption.ts";
@@ -11,6 +11,7 @@ export function createFoundryWorkspaceAccess(input) {
11
11
  });
12
12
  }
13
13
  export { FOUNDRY_AUTHORIZATION_INPUT_SCHEMA, } from "./lib/foundry-authorization-input.js";
14
+ export { FOUNDRY_QUALITY_REVIEW_INPUT_SCHEMA, } from "./lib/foundry-quality-review-input.js";
14
15
  export { FOUNDRY_SEMANTIC_INPUT_SCHEMA, } from "./lib/foundry-semantic-input.js";
15
16
  export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, } from "./lib/foundry-interaction-input.js";
16
17
  export { FOUNDRY_RUNTIME_SELECTION_SCHEMA, } from "./lib/foundry-runtime-selection-record.js";
@@ -27,3 +28,4 @@ export { FOUNDRY_MIGRATION_TRANSFER_RECEIPT_SCHEMA, } from "./lib/foundry-migrat
27
28
  export { FOUNDRY_MIGRATION_ADOPTION_PLAN_SCHEMA, } from "./lib/foundry-migration-adoption-plan.js";
28
29
  export { FOUNDRY_MIGRATION_ACTIVATION_SCHEMA, FOUNDRY_MIGRATED_WORKSPACE_SCHEMA, } from "./lib/foundry-migration-authority.js";
29
30
  export { FOUNDRY_PACKAGE_DESCRIPTOR_SCHEMA, FoundryPackageError, assertFoundryPackage, assertFoundryPackageDescriptor, } from "./lib/foundry-package-contract.js";
31
+ export { createFoundryRuntimeAdoptionQualification, } from "./lib/foundry-task-runtime-adoption.js";
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import type { TrustedFoundryRuntimeAdoptionQualification } from "./lib/foundry-task-runtime-adoption.ts";
2
3
  import type { TrustedRuntimeManifest } from "@tiangong-lca/cli/runtime";
3
4
  import type { FoundryRuntimeManagerOptions } from "./lib/foundry-runtime-selection.ts";
4
5
  import type { FoundryAuthentication } from "./lib/foundry-runtime-identity.ts";
@@ -13,6 +14,7 @@ export interface FoundryRuntimeCommandHost {
13
14
  readonly authentication?: FoundryAuthentication;
14
15
  readonly runtimeTarget?: TrustedRuntimeManifest;
15
16
  readonly runtimeManager?: FoundryRuntimeManagerOptions;
17
+ readonly runtimeAdoptionQualification?: TrustedFoundryRuntimeAdoptionQualification;
16
18
  readonly signal?: AbortSignal;
17
19
  readonly writeStdout?: (text: string) => void;
18
20
  readonly setExitCode?: (code: number) => void;
@@ -34,7 +34,7 @@ function publicCommand(argv) {
34
34
  return { operation: "workspace.init", args: parseArgs(rest) };
35
35
  if (group === "workspace" && action === "migrate")
36
36
  return { operation: "workspace.migrate", args: parseArgs(rest) };
37
- if (group === "task" && ["start", "status", "resume"].includes(action))
37
+ if (group === "task" && ["start", "status", "resume", "adopt-runtime"].includes(action))
38
38
  return { operation: `task.${action}`, args: parseArgs(rest) };
39
39
  if (group === "workspace" || group === "task")
40
40
  return { operation: "unknown", args: parseArgs([action, ...rest].filter(Boolean)) };
@@ -126,10 +126,14 @@ async function runPublicCommand(parsed, host) {
126
126
  "authorizationInput",
127
127
  "referenceInput",
128
128
  "interactionInput",
129
+ "identityStageInput",
130
+ "qualityReviewInput",
129
131
  ]
130
- : parsed.operation === "task.status"
131
- ? ["task", "actor"]
132
- : []),
132
+ : parsed.operation === "task.adopt-runtime"
133
+ ? ["task", "actor", "dryRun", "apply", "audit", "selection", "plan"]
134
+ : parsed.operation === "task.status"
135
+ ? ["task", "actor"]
136
+ : []),
133
137
  ]);
134
138
  const unknownOption = Object.keys(parsed.args).find((key) => !allowed.has(key));
135
139
  if (unknownOption)
@@ -147,6 +151,7 @@ async function runPublicCommand(parsed, host) {
147
151
  authentication: host.authentication,
148
152
  workspaceAccess: host.workspaceAccess,
149
153
  runtimeManager: host.runtimeManager,
154
+ runtimeAdoptionQualification: host.runtimeAdoptionQualification,
150
155
  accountIntent: parsed.operation === "doctor"
151
156
  ? (doctorAccountIntent(parsed.args) ?? host.accountIntent)
152
157
  : host.accountIntent,
@@ -298,17 +303,39 @@ async function runPublicCommand(parsed, host) {
298
303
  const actorId = option(parsed.args.actor, "--actor");
299
304
  if (!taskId || !actorId)
300
305
  return invalidResult(parsed.operation, taskId, "argument_task_actor_required", "Task status and resume require exact --task and --actor values.");
301
- result =
302
- parsed.operation === "task.status"
303
- ? await facade.status({ taskId, actorId })
304
- : await facade.resume({
305
- taskId,
306
- actorId,
307
- semanticInputFile: option(parsed.args.semanticInput, "--semantic-input") ?? undefined,
308
- interactionInputFile: option(parsed.args.interactionInput, "--interaction-input") ?? undefined,
309
- referenceInputFile: option(parsed.args.referenceInput, "--reference-input") ?? undefined,
310
- authorizationInputFile: option(parsed.args.authorizationInput, "--authorization-input") ?? undefined,
311
- });
306
+ if (parsed.operation === "task.adopt-runtime") {
307
+ const modes = [parsed.args.dryRun, parsed.args.apply, parsed.args.audit];
308
+ if (modes.filter((value) => value === true).length !== 1 ||
309
+ modes.some((value) => value !== undefined && value !== true))
310
+ throw new FoundryContextError("runtime_adoption_mode_invalid", "Select exactly one of --dry-run, --apply or --audit.");
311
+ const selection = option(parsed.args.selection, "--selection"), plan = option(parsed.args.plan, "--plan");
312
+ const readSelected = (file) => {
313
+ if (migrationCredentialPath(file))
314
+ throw new FoundryContextError("credential_input_forbidden", "Private files cannot select runtime adoption.");
315
+ return JSON.parse(transferRead(path.resolve(file), 8 * 1024 * 1024).toString("utf8"));
316
+ };
317
+ result = await facade.adoptTaskRuntime({
318
+ taskId,
319
+ actorId,
320
+ mode: parsed.args.dryRun === true ? "plan" : parsed.args.apply === true ? "apply" : "audit",
321
+ ...(selection ? { selection: readSelected(selection) } : {}),
322
+ ...(plan ? { plan: readSelected(plan) } : {}),
323
+ });
324
+ }
325
+ else
326
+ result =
327
+ parsed.operation === "task.status"
328
+ ? await facade.status({ taskId, actorId })
329
+ : await facade.resume({
330
+ taskId,
331
+ actorId,
332
+ semanticInputFile: option(parsed.args.semanticInput, "--semantic-input") ?? undefined,
333
+ interactionInputFile: option(parsed.args.interactionInput, "--interaction-input") ?? undefined,
334
+ referenceInputFile: option(parsed.args.referenceInput, "--reference-input") ?? undefined,
335
+ identityStageInputFile: option(parsed.args.identityStageInput, "--identity-stage-input") ?? undefined,
336
+ qualityReviewInputFile: option(parsed.args.qualityReviewInput, "--quality-review-input") ?? undefined,
337
+ authorizationInputFile: option(parsed.args.authorizationInput, "--authorization-input") ?? undefined,
338
+ });
312
339
  }
313
340
  return result;
314
341
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiangong-lca/foundry",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "description": "Control plane for TianGong LCA external dataset import and TIDAS authoring work.",
6
6
  "repository": {
@@ -44,6 +44,9 @@
44
44
  "specs/schemas/foundry-interaction-input.schema.json",
45
45
  "specs/schemas/foundry-authorization-input.schema.json",
46
46
  "specs/schemas/foundry-reference-input.schema.json",
47
+ "specs/schemas/foundry-identity-stage-input.schema.json",
48
+ "specs/schemas/foundry-quality-review-input.schema.json",
49
+ "specs/schemas/foundry-quality-review-draft.schema.json",
47
50
  "specs/schemas/foundry-workspace-migration-plan.schema.json",
48
51
  "specs/schemas/foundry-workspace-migration-transfer-plan.schema.json",
49
52
  "specs/schemas/foundry-migration-transfer-receipt.schema.json",
@@ -53,6 +56,7 @@
53
56
  "specs/schemas/foundry-workspace-v2.schema.json",
54
57
  "specs/schemas/foundry-runtime-selection.schema.json",
55
58
  "specs/schemas/foundry-managed-runtime.schema.json",
59
+ "specs/schemas/foundry-managed-adoption.schema.json",
56
60
  "specs/schemas/runtime-qualification.schema.json",
57
61
  "specs/schemas/task-authorization.schema.json",
58
62
  "specs/schemas/tidas-runtime-expectation.schema.json",
@@ -82,7 +86,7 @@
82
86
  },
83
87
  "license": "MIT",
84
88
  "dependencies": {
85
- "@tiangong-lca/cli": "0.1.27"
89
+ "@tiangong-lca/cli": "0.1.28"
86
90
  },
87
91
  "foundryRuntime": {
88
92
  "schema": "tiangong-foundry.runtime-layout.v2",
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "title": "Foundry Explicit New Read-only Identity Stage Input v1",
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "required": [
7
+ "schema",
8
+ "intent_id",
9
+ "task_id",
10
+ "actor_id",
11
+ "rows_report_sha256",
12
+ "predecessor_identity_sha256",
13
+ "targets"
14
+ ],
15
+ "properties": {
16
+ "schema": { "const": "tiangong-foundry.identity-stage-input.v1" },
17
+ "intent_id": { "$ref": "#/$defs/token" },
18
+ "task_id": { "type": "string", "pattern": "^task-[0-9a-f]{64}-r[0-9]{4}$" },
19
+ "actor_id": { "$ref": "#/$defs/token" },
20
+ "rows_report_sha256": { "$ref": "#/$defs/sha256" },
21
+ "predecessor_identity_sha256": { "$ref": "#/$defs/sha256" },
22
+ "targets": {
23
+ "type": "array",
24
+ "minItems": 1,
25
+ "maxItems": 64,
26
+ "uniqueItems": true,
27
+ "items": {
28
+ "type": "object",
29
+ "additionalProperties": false,
30
+ "required": ["dataset_type", "dataset_id", "dataset_version", "source_row_sha256"],
31
+ "properties": {
32
+ "dataset_type": { "enum": ["flow", "process"] },
33
+ "dataset_id": {
34
+ "type": "string",
35
+ "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
36
+ },
37
+ "dataset_version": { "type": "string", "pattern": "^[0-9]{2}\\.[0-9]{2}\\.[0-9]{3}$" },
38
+ "source_row_sha256": { "$ref": "#/$defs/sha256" }
39
+ }
40
+ }
41
+ }
42
+ },
43
+ "$defs": {
44
+ "token": { "type": "string", "pattern": "^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$" },
45
+ "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
46
+ }
47
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "https://tiangong-lca.local/foundry/foundry-managed-adoption.schema.json",
4
+ "title": "Foundry inventory-bound managed adoption carrier",
5
+ "$comment": "Structural shape only. The package-owned host verifies the independently trusted carrier, complete successor runtime equality, non-executable control component and same-package qualification brand.",
6
+ "type": "object",
7
+ "additionalProperties": false,
8
+ "required": ["schema", "platform", "successor_manifest", "launches"],
9
+ "properties": {
10
+ "schema": { "const": "tiangong-foundry.managed-adoption.v1" },
11
+ "platform": { "enum": ["linux-x64", "linux-arm64", "darwin-arm64", "win32-x64"] },
12
+ "successor_manifest": {
13
+ "$ref": "https://tiangong-lca.local/foundry/foundry-managed-runtime.schema.json#/$defs/componentReference"
14
+ },
15
+ "launches": {
16
+ "type": "array",
17
+ "minItems": 1,
18
+ "maxItems": 16,
19
+ "uniqueItems": true,
20
+ "items": {
21
+ "type": "object",
22
+ "additionalProperties": false,
23
+ "required": ["id", "qualification"],
24
+ "properties": {
25
+ "id": {
26
+ "$ref": "https://tiangong-lca.local/foundry/foundry-managed-runtime.schema.json#/$defs/identifier"
27
+ },
28
+ "qualification": {
29
+ "anyOf": [
30
+ { "type": "null" },
31
+ {
32
+ "$ref": "https://tiangong-lca.local/foundry/foundry-managed-runtime.schema.json#/$defs/componentReference"
33
+ }
34
+ ]
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
@@ -29,7 +29,7 @@
29
29
  "const": "tiangong-lca.cli-runtime-expectation.v1"
30
30
  },
31
31
  "package_version": {
32
- "const": "0.1.27"
32
+ "const": "0.1.28"
33
33
  },
34
34
  "platform": {
35
35
  "$ref": "#/$defs/platform"
@@ -25,6 +25,7 @@
25
25
  "task.start",
26
26
  "task.status",
27
27
  "task.resume",
28
+ "task.adopt-runtime",
28
29
  "workspace.migrate"
29
30
  ]
30
31
  },
@@ -18,7 +18,7 @@
18
18
  "const": "@tiangong-lca/foundry"
19
19
  },
20
20
  "version": {
21
- "const": "0.1.17"
21
+ "const": "0.1.18"
22
22
  },
23
23
  "cli_dependency": {
24
24
  "type": "object",
@@ -29,7 +29,7 @@
29
29
  "const": "@tiangong-lca/cli"
30
30
  },
31
31
  "version": {
32
- "const": "0.1.27"
32
+ "const": "0.1.28"
33
33
  }
34
34
  }
35
35
  },
@@ -76,6 +76,9 @@
76
76
  "tiangong-foundry.interaction-input.v1",
77
77
  "tiangong-foundry.authorization-input.v1",
78
78
  "tiangong-foundry.reference-input.v1",
79
+ "tiangong-foundry.identity-stage-input.v1",
80
+ "tiangong-foundry.quality-review-input.v1",
81
+ "tiangong-foundry.quality-review-draft.v1",
79
82
  "tiangong-foundry.facade-request-index.v1",
80
83
  "tiangong-foundry.workspace-migration-plan.v1",
81
84
  "tiangong-foundry.workspace-migration-transfer-plan.v2",
@@ -86,6 +89,7 @@
86
89
  "tiangong-foundry.workspace.v2",
87
90
  "tiangong-foundry.workspace-runtime-selection.v1",
88
91
  "tiangong-foundry.managed-runtime.v1",
92
+ "tiangong-foundry.managed-adoption.v1",
89
93
  "tiangong-foundry.runtime-qualification.v1",
90
94
  "tiangong-foundry.tidas-runtime-expectation.v1",
91
95
  "tiangong-foundry.execution-context.v1",