@tiangong-lca/foundry 0.1.12 → 0.1.14
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 +6 -6
- package/docs/architecture.md +8 -6
- package/docs/foundry-task-contracts.md +5 -5
- package/docs/import-profiles/worldsteel/constraints.md +3 -3
- package/docs/import-profiles/worldsteel/import-coverage.md +3 -3
- package/docs/import-profiles/worldsteel/import-plan.md +4 -4
- package/docs/import-profiles/worldsteel/profile.md +3 -3
- package/docs/package-distribution-contract.md +14 -10
- package/docs/public-runtime-contract.md +9 -7
- package/docs/runtime-context-contract.md +4 -4
- package/docs/task-authorization-contract.md +3 -3
- package/package-dist/assets/foundry-package-descriptor.json +97 -67
- package/package-dist/scripts/foundry-facade.js +217 -9
- package/package-dist/scripts/lib/foundry-interaction-input.d.ts +4 -3
- package/package-dist/scripts/lib/foundry-interaction-input.js +40 -7
- package/package-dist/scripts/lib/foundry-interaction-projection.d.ts +21 -2
- package/package-dist/scripts/lib/foundry-interaction-projection.js +49 -8
- package/package-dist/scripts/lib/foundry-interaction-scope.d.ts +7 -0
- package/package-dist/scripts/lib/foundry-interaction-scope.js +40 -0
- package/package-dist/scripts/lib/foundry-interaction-types.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-native-validation-failure.d.ts +36 -0
- package/package-dist/scripts/lib/foundry-native-validation-failure.js +142 -0
- package/package-dist/scripts/lib/foundry-owner-execution-store.js +6 -13
- 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-runtime-qualification.js +2 -2
- package/package-dist/scripts/lib/foundry-runtime-utils.js +1 -1
- package/package-dist/scripts/lib/foundry-semantic-interaction.d.ts +11 -1
- package/package-dist/scripts/lib/foundry-semantic-interaction.js +64 -14
- package/package-dist/scripts/lib/foundry-tidas-source.js +4 -4
- package/package-dist/scripts/lib/foundry-workflow-approval-continuation.js +3 -0
- package/package-dist/scripts/lib/foundry-workflow-assessment.js +27 -2
- package/package-dist/scripts/lib/foundry-workflow-authorization.js +3 -0
- package/package-dist/scripts/lib/foundry-workflow-interaction.js +22 -3
- package/package-dist/scripts/lib/foundry-workflow-object-scope.d.ts +53 -0
- package/package-dist/scripts/lib/foundry-workflow-object-scope.js +326 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.d.ts +5 -0
- package/package-dist/scripts/lib/foundry-workflow-semantic.js +200 -6
- package/package-dist/scripts/lib/import-curation/internal/context-inputs.js +1 -1
- package/package.json +2 -2
- package/specs/import-profiles.json +1 -1
- package/specs/schemas/foundry-interaction-input.schema.json +29 -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
|
@@ -4,7 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { assertFoundryCacheRootSeparated } from "./lib/foundry-runtime-cache.js";
|
|
6
6
|
import { createFoundryRuntime } from "./foundry-runtime.js";
|
|
7
|
-
import { captureFoundryInput, assertFoundryRuntimeHost, assertFoundryWorkspaceWrite, createFoundryRuntimeContext, FoundryContextError, initializeFoundryWorkspace, pendingFoundryMigration, } from "./lib/foundry-runtime-context.js";
|
|
7
|
+
import { captureFoundryInput, assertFoundryRuntimeHost, assertFoundryWorkspaceWrite, createFoundryRuntimeContext, FoundryContextError, initializeFoundryWorkspace, pendingFoundryMigration, resolveFoundryOutput, } from "./lib/foundry-runtime-context.js";
|
|
8
8
|
import { commandNextActionBindingSha256, createFoundryOperationResult, } from "./lib/foundry-operation-result.js";
|
|
9
9
|
import { loadFoundryFacadeTaskRecord, registerFoundryFacadeTask, } from "./lib/foundry-facade-store.js";
|
|
10
10
|
import { parseFoundryTaskStartSpec, } from "./lib/foundry-task-start-spec.js";
|
|
@@ -18,12 +18,14 @@ import { applyFoundryMigrationAdoption } from "./lib/foundry-migration-adoption.
|
|
|
18
18
|
import { readFoundryMigrationAuthority } from "./lib/foundry-migration-authority.js";
|
|
19
19
|
import { selectFoundryWorkspaceRuntime, } from "./lib/foundry-runtime-selection.js";
|
|
20
20
|
import { datasetTypePlural } from "./lib/import-curation/internal/dataset-types.js";
|
|
21
|
-
import { currentWorkflowState, workflowObject } from "./lib/foundry-workflow-state.js";
|
|
21
|
+
import { currentWorkflowState, readWorkflowArtifact, workflowObject, } from "./lib/foundry-workflow-state.js";
|
|
22
|
+
import { currentNativeValidationFailure } from "./lib/foundry-native-validation-failure.js";
|
|
22
23
|
import { completedOwnerScopes, prepareFoundryOwnerExecution, } from "./lib/foundry-owner-execution-store.js";
|
|
23
24
|
import { executeFoundryOwnerScope } from "./lib/foundry-workflow-execution.js";
|
|
24
25
|
import { inspectFoundryReferences, verifyFoundryReferences, } from "./lib/foundry-workflow-reference-verify.js";
|
|
25
26
|
import { selectFoundrySemanticInput } from "./lib/foundry-semantic-input.js";
|
|
26
|
-
import { currentFoundryInteractionState, currentFoundryQuestions, currentFoundryDecisions, currentFoundryInvestigations, currentFoundryAssumptions, selectFoundryInteractionInput, } from "./lib/foundry-interaction-input.js";
|
|
27
|
+
import { currentFoundryInteractionState, currentFoundryQuestions, currentFoundryDecisions, currentFoundryInvestigations, currentFoundryAssumptions, foundryInteractionObjectKey, applicableFoundryInteractionProjectionForObject, applicableFoundryInteractionDigestForObject, selectFoundryInteractionInput, } from "./lib/foundry-interaction-input.js";
|
|
28
|
+
import { currentFoundryObjectDecisionReassessments, currentFoundryInteractionWriteBlocker, currentFoundryObjectScopes, currentFoundryObjectScopeIsBound, currentFoundryNarrowObjects, indexedFoundryRowAdoptions, } from "./lib/foundry-workflow-object-scope.js";
|
|
27
29
|
import { recordFoundryInteractionInput } from "./lib/foundry-workflow-interaction.js";
|
|
28
30
|
import { runFoundryWorkflowIdentity } from "./lib/foundry-workflow-identity.js";
|
|
29
31
|
import { finalizeFoundryWorkflow } from "./lib/foundry-workflow-finalize.js";
|
|
@@ -447,11 +449,106 @@ function currentIndexedQueueBlockers(context, workflow, entries) {
|
|
|
447
449
|
}
|
|
448
450
|
return { blockers, actions };
|
|
449
451
|
}
|
|
452
|
+
function scopedAuthoringPresentation(context, entries, workflow, interaction, objects, reassessments, staleObjects) {
|
|
453
|
+
const narrow = currentFoundryNarrowObjects(interaction.state);
|
|
454
|
+
const artifacts = [];
|
|
455
|
+
const actions = [];
|
|
456
|
+
const blockers = [];
|
|
457
|
+
for (const item of staleObjects) {
|
|
458
|
+
blockers.push({
|
|
459
|
+
code: "interaction_object_evidence_changed",
|
|
460
|
+
message: `The reviewed ${item.dataset_type} changed without a proven link to the earlier decision. Recheck only this record and its proven dependents. Record ID: ${item.entity_id}; version: ${item.version}.`,
|
|
461
|
+
scope: `${item.dataset_type}:${item.entity_id}`,
|
|
462
|
+
});
|
|
463
|
+
actions.push(human("review_object_scope", `The earlier answer may no longer fit this ${item.dataset_type}. Recheck its current row and source evidence before using that answer. Record ID: ${item.entity_id}; version: ${item.version}.`));
|
|
464
|
+
}
|
|
465
|
+
for (const item of reassessments) {
|
|
466
|
+
blockers.push({
|
|
467
|
+
code: "interaction_object_decision_changed",
|
|
468
|
+
message: `A newer answer for this ${item.dataset_type} has not been applied to its current row. Review it before authorization. Record ID: ${item.entity_id}; version: ${item.version}; decision ID: ${item.decision_id}.`,
|
|
469
|
+
scope: `${item.dataset_type}:${item.entity_id}`,
|
|
470
|
+
});
|
|
471
|
+
actions.push(human("review_corrected_object_decision", `A newer answer for this ${item.dataset_type} still needs to be reflected in the data. Check its current source evidence, then submit matching semantic work. If no matching work remains, start a revised task. Other records can continue. Record ID: ${item.entity_id}; version: ${item.version}; decision ID: ${item.decision_id}.`));
|
|
472
|
+
}
|
|
473
|
+
if (!narrow.length || !workflow.assessment)
|
|
474
|
+
return { artifacts, actions, blockers, types: [] };
|
|
475
|
+
const narrowTypes = new Set(narrow.map((item) => item.dataset_type));
|
|
476
|
+
const reassessmentKeys = new Set(reassessments.map((item) => JSON.stringify([item.dataset_type, item.entity_id, item.version])));
|
|
477
|
+
const staleKeys = new Set(staleObjects.map((item) => JSON.stringify([item.dataset_type, item.entity_id, item.version])));
|
|
478
|
+
let shown = 0;
|
|
479
|
+
for (const set of workflow.assessment.value.sets) {
|
|
480
|
+
const type = String(set.type);
|
|
481
|
+
if (!narrowTypes.has(type))
|
|
482
|
+
continue;
|
|
483
|
+
for (const raw of Array.isArray(set.decisions) ? set.decisions : []) {
|
|
484
|
+
const decision = workflowObject(raw);
|
|
485
|
+
if (typeof decision.kind !== "string" || typeof decision.task !== "string")
|
|
486
|
+
continue;
|
|
487
|
+
actions.push(human(`review_${decision.kind}_decisions`, `A ${decision.kind} decision batch needs review. Check each affected record's evidence and resolve its pending questions before submitting the batch. Registered task: ${decision.task}; status: ${String(decision.status)}.`));
|
|
488
|
+
}
|
|
489
|
+
const manifestFile = String(set.authoring_manifest);
|
|
490
|
+
const manifestEntry = entries.find((entry) => resolveFoundryOutput(context, entry.path) === manifestFile);
|
|
491
|
+
if (!manifestEntry)
|
|
492
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Current object work has no registered authoring manifest.");
|
|
493
|
+
const manifest = readWorkflowArtifact(context, manifestEntry).value;
|
|
494
|
+
if (!Array.isArray(manifest.tasks))
|
|
495
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Current authoring manifest has no bounded task list.");
|
|
496
|
+
for (const raw of manifest.tasks) {
|
|
497
|
+
if (shown >= 64) {
|
|
498
|
+
actions.push(human("review_remaining_object_work", `More object work is indexed at ${manifestFile}; inspect its exact task identities before continuing.`));
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
const task = workflowObject(raw);
|
|
502
|
+
const files = workflowObject(task.files);
|
|
503
|
+
const taskFile = path.resolve(workflow.assessment.value.owner_base, String(files.task_json));
|
|
504
|
+
const taskEntry = entries.find((entry) => resolveFoundryOutput(context, entry.path) === taskFile);
|
|
505
|
+
if (!taskEntry)
|
|
506
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Current object work has no registered authoring task.");
|
|
507
|
+
const registered = readWorkflowArtifact(context, taskEntry).value;
|
|
508
|
+
const entity = workflowObject(registered.entity);
|
|
509
|
+
if (entity.dataset_type !== type ||
|
|
510
|
+
typeof entity.entity_id !== "string" ||
|
|
511
|
+
typeof entity.version !== "string")
|
|
512
|
+
throw new FoundryContextError("workflow_assessment_invalid", "Current authoring task has no exact object identity.");
|
|
513
|
+
const current = objects.get(foundryInteractionObjectKey(type, entity.entity_id, entity.version)) ?? null;
|
|
514
|
+
const projection = applicableFoundryInteractionProjectionForObject(interaction.state, type, entity.entity_id, entity.version);
|
|
515
|
+
const decisionCurrent = !reassessmentKeys.has(JSON.stringify([type, entity.entity_id, entity.version]));
|
|
516
|
+
const bound = !staleKeys.has(JSON.stringify([type, entity.entity_id, entity.version]));
|
|
517
|
+
artifacts.push(inlineArtifact("object_interaction_context", {
|
|
518
|
+
...projection,
|
|
519
|
+
work_item_sha256: taskEntry.sha256,
|
|
520
|
+
current_row_sha256: current?.row_sha256 ?? null,
|
|
521
|
+
source_state_sha256: interaction.entry.sha256,
|
|
522
|
+
applicable_digest: applicableFoundryInteractionDigestForObject(interaction.state, type, entity.entity_id, entity.version),
|
|
523
|
+
evidence_current: bound,
|
|
524
|
+
decision_current: decisionCurrent,
|
|
525
|
+
}));
|
|
526
|
+
shown += 1;
|
|
527
|
+
if (bound &&
|
|
528
|
+
registered.status === "ready_for_ai_authoring" &&
|
|
529
|
+
!projection.pending_questions.length &&
|
|
530
|
+
!projection.investigations.length) {
|
|
531
|
+
actions.push(human("review_semantic_work", `This ${type} has independent authoring work ready. Review its remaining gaps and source evidence in the registered task and matching object_interaction_context, then cite only decisions that apply to this record. Record ID: ${entity.entity_id}; version: ${entity.version}; task: ${taskFile}. This does not grant write permission.`));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return { artifacts, actions, blockers, types: [...narrowTypes] };
|
|
536
|
+
}
|
|
450
537
|
function taskProjection(operation, context, record, inspected, identity) {
|
|
451
538
|
const artifacts = taskArtifacts(context, inspected);
|
|
452
539
|
const interaction = currentFoundryInteractionState(context, inspected.artifacts);
|
|
453
540
|
const pendingQuestions = interaction ? currentFoundryQuestions(interaction.state) : [];
|
|
454
541
|
const investigations = interaction ? currentFoundryInvestigations(interaction.state) : [];
|
|
542
|
+
const narrow = interaction ? currentFoundryNarrowObjects(interaction.state) : [];
|
|
543
|
+
const objectAdoptions = interaction && narrow.length ? indexedFoundryRowAdoptions(context, inspected.artifacts) : [];
|
|
544
|
+
const objectScopes = narrow.length
|
|
545
|
+
? currentFoundryObjectScopes(context, inspected.artifacts)
|
|
546
|
+
: new Map();
|
|
547
|
+
const reassessments = interaction
|
|
548
|
+
? currentFoundryObjectDecisionReassessments(interaction.state, objectScopes, objectAdoptions)
|
|
549
|
+
: [];
|
|
550
|
+
const staleObjects = narrow.filter((item) => !currentFoundryObjectScopeIsBound(context, inspected.artifacts, interaction.state, objectScopes, item.dataset_type, item.entity_id, item.version, objectAdoptions));
|
|
551
|
+
const objectEvidenceCurrent = staleObjects.length === 0;
|
|
455
552
|
if (record.spec.brief)
|
|
456
553
|
artifacts.push(inlineArtifact("task_brief", record.spec.brief));
|
|
457
554
|
if (interaction)
|
|
@@ -475,6 +572,28 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
475
572
|
? currentFoundryDecisions(interaction.state).map((answer) => ({
|
|
476
573
|
question_id: answer.question_id,
|
|
477
574
|
dataset_type: questions.get(String(answer.question_id))?.dataset_type ?? null,
|
|
575
|
+
...(questions.get(String(answer.question_id))?.object_scope
|
|
576
|
+
? {
|
|
577
|
+
object_scope: questions.get(String(answer.question_id))?.object_scope,
|
|
578
|
+
applied_to: objectAdoptions
|
|
579
|
+
.filter((adoption) => adoption.decision_ids.includes(String(answer.decision_id)))
|
|
580
|
+
.filter((adoption) => {
|
|
581
|
+
const scope = questions.get(String(answer.question_id))?.object_scope;
|
|
582
|
+
return (scope &&
|
|
583
|
+
adoption.dataset_type ===
|
|
584
|
+
questions.get(String(answer.question_id))?.dataset_type &&
|
|
585
|
+
adoption.object_scope.entity_id === scope.entity_id &&
|
|
586
|
+
adoption.object_scope.version === scope.version);
|
|
587
|
+
})
|
|
588
|
+
.slice(-16)
|
|
589
|
+
.map((adoption) => ({
|
|
590
|
+
work_item_sha256: adoption.work_item_sha256,
|
|
591
|
+
before_row_sha256: adoption.before_row_sha256,
|
|
592
|
+
after_row_sha256: adoption.after_row_sha256,
|
|
593
|
+
semantic_result_sha256: adoption.semantic_result_sha256,
|
|
594
|
+
})),
|
|
595
|
+
}
|
|
596
|
+
: {}),
|
|
478
597
|
impact: questions.get(String(answer.question_id))?.impact ?? null,
|
|
479
598
|
raw_answer_sha256: createHash("sha256").update(String(answer.raw_answer)).digest("hex"),
|
|
480
599
|
adopted_decision: answer.adopted_decision,
|
|
@@ -487,6 +606,7 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
487
606
|
unresolved_questions: [...pendingQuestions, ...investigations].map((question) => ({
|
|
488
607
|
id: question.id,
|
|
489
608
|
dataset_type: question.dataset_type,
|
|
609
|
+
...(question.object_scope ? { object_scope: question.object_scope } : {}),
|
|
490
610
|
missing: question.missing,
|
|
491
611
|
impact: question.impact,
|
|
492
612
|
ask: question.ask,
|
|
@@ -502,7 +622,10 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
502
622
|
: artifacts;
|
|
503
623
|
if (completionProven(context, record, inspected) &&
|
|
504
624
|
!pendingQuestions.length &&
|
|
505
|
-
!investigations.length
|
|
625
|
+
!investigations.length &&
|
|
626
|
+
!reassessments.length &&
|
|
627
|
+
objectEvidenceCurrent &&
|
|
628
|
+
!currentFoundryInteractionWriteBlocker(context, inspected.artifacts))
|
|
506
629
|
return createFoundryOperationResult({
|
|
507
630
|
operation,
|
|
508
631
|
status: "completed",
|
|
@@ -577,6 +700,41 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
577
700
|
}
|
|
578
701
|
const workflow = currentWorkflowState(context, inspected.artifacts);
|
|
579
702
|
const queueIssues = currentIndexedQueueBlockers(context, workflow, inspected.artifacts);
|
|
703
|
+
const nativeFailure = currentNativeValidationFailure(context, inspected.artifacts, workflow.rows
|
|
704
|
+
? {
|
|
705
|
+
file: workflow.rows.file,
|
|
706
|
+
sha256: workflow.rows.entry.sha256,
|
|
707
|
+
sets: workflow.rows.value.sets,
|
|
708
|
+
}
|
|
709
|
+
: null);
|
|
710
|
+
if (nativeFailure) {
|
|
711
|
+
const report = nativeFailure.result;
|
|
712
|
+
const type = String(report.dataset_type);
|
|
713
|
+
const label = `${type.slice(0, 1).toUpperCase()}${type.slice(1)}`;
|
|
714
|
+
const code = String(report.diagnostic_code);
|
|
715
|
+
const detail = String(report.diagnostic_message);
|
|
716
|
+
const normalized = detail.replace(/\s+/gu, " ").trim();
|
|
717
|
+
const preview = normalized.length > 240 ? `${normalized.slice(0, 237)}…` : normalized;
|
|
718
|
+
const rowCount = Number(report.row_count);
|
|
719
|
+
const affectedRows = `${rowCount} selected ${label} row${rowCount === 1 ? "" : "s"}`;
|
|
720
|
+
const failureKind = report.exit_class === "io"
|
|
721
|
+
? `${context.platform.startsWith("win32") ? "Windows " : ""}file I/O`
|
|
722
|
+
: "native validation";
|
|
723
|
+
const message = `Native ${label} validation stopped on ${failureKind} (${report.exit_class}/${code}): ${preview} The ${affectedRows} remain unassessed; no write can proceed. Inspect the complete indexed diagnostic at ${nativeFailure.file}, correct the native runtime or filesystem failure, and start an explicitly reviewed task revision under the replacement runtime.`;
|
|
724
|
+
return createFoundryOperationResult({
|
|
725
|
+
operation,
|
|
726
|
+
status: "blocked",
|
|
727
|
+
taskId: record.task_id,
|
|
728
|
+
artifacts,
|
|
729
|
+
blockers: [
|
|
730
|
+
{ code: "native_validation_failed", message, scope: type },
|
|
731
|
+
...queueIssues.blockers,
|
|
732
|
+
],
|
|
733
|
+
nextActions: [human("repair_native_validation", message), ...queueIssues.actions],
|
|
734
|
+
runtimeIdentity: identity,
|
|
735
|
+
permissions: noPermission(),
|
|
736
|
+
});
|
|
737
|
+
}
|
|
580
738
|
if (record.spec.repair && execution.verified.size) {
|
|
581
739
|
if (execution.requests.length !== 1 || execution.verified.size !== 1)
|
|
582
740
|
throw new FoundryContextError("repair_execution_mismatch", "A repair task must retain one exact verified execution scope.");
|
|
@@ -637,8 +795,18 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
637
795
|
: noPermission(),
|
|
638
796
|
});
|
|
639
797
|
}
|
|
640
|
-
|
|
641
|
-
|
|
798
|
+
const scoped = interaction
|
|
799
|
+
? scopedAuthoringPresentation(context, inspected.artifacts, workflow, interaction, objectScopes, reassessments, staleObjects)
|
|
800
|
+
: { artifacts: [], actions: [], blockers: [], types: [] };
|
|
801
|
+
artifacts.push(...scoped.artifacts);
|
|
802
|
+
if (pendingQuestions.length || investigations.length || scoped.blockers.length) {
|
|
803
|
+
const describe = (question) => {
|
|
804
|
+
const object = question.object_scope;
|
|
805
|
+
const target = object
|
|
806
|
+
? ` Affected ${String(question.dataset_type)}: ID ${object.entity_id}, version ${object.version}. The indexed task artifacts retain its exact row and source evidence.`
|
|
807
|
+
: "";
|
|
808
|
+
return `Question: ${String(question.ask)} Missing information: ${String(question.missing)} Why it matters: ${String(question.impact)} Suggested next step: ${String(question.recommendation)}${target}`;
|
|
809
|
+
};
|
|
642
810
|
const askActions = pendingQuestions.map((question) => human("answer_current_question", `${describe(question)}${Array.isArray(question.choices) && question.choices.length ? ` ${question.choices.join(" / ")}` : ""}`));
|
|
643
811
|
const investigationIds = new Set(investigations.map((question) => String(question.id)));
|
|
644
812
|
return createFoundryOperationResult({
|
|
@@ -652,13 +820,17 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
652
820
|
? "interaction_investigation_pending"
|
|
653
821
|
: "interaction_decision_pending",
|
|
654
822
|
message: `${String(question.missing)} ${String(question.impact)}`,
|
|
655
|
-
scope:
|
|
823
|
+
scope: question.object_scope
|
|
824
|
+
? `${String(question.dataset_type)}:${String(question.object_scope.entity_id)}`
|
|
825
|
+
: String(question.dataset_type ?? record.task_id),
|
|
656
826
|
})),
|
|
657
827
|
...queueIssues.blockers,
|
|
828
|
+
...scoped.blockers,
|
|
658
829
|
],
|
|
659
830
|
nextActions: [
|
|
660
831
|
...askActions,
|
|
661
832
|
...queueIssues.actions,
|
|
833
|
+
...scoped.actions,
|
|
662
834
|
...(independentLocalPreparationPending(record, workflow, inspected.artifacts)
|
|
663
835
|
? [resumeCommand(context, record)]
|
|
664
836
|
: []),
|
|
@@ -667,6 +839,31 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
667
839
|
permissions: noPermission(),
|
|
668
840
|
});
|
|
669
841
|
}
|
|
842
|
+
const writeBlocker = workflow.finalization
|
|
843
|
+
? currentFoundryInteractionWriteBlocker(context, inspected.artifacts)
|
|
844
|
+
: null;
|
|
845
|
+
if (writeBlocker)
|
|
846
|
+
return createFoundryOperationResult({
|
|
847
|
+
operation,
|
|
848
|
+
status: "needs_input",
|
|
849
|
+
taskId: record.task_id,
|
|
850
|
+
artifacts,
|
|
851
|
+
blockers: [
|
|
852
|
+
...queueIssues.blockers,
|
|
853
|
+
{
|
|
854
|
+
code: writeBlocker.code,
|
|
855
|
+
message: writeBlocker.message,
|
|
856
|
+
scope: writeBlocker.scope ?? record.task_id,
|
|
857
|
+
},
|
|
858
|
+
],
|
|
859
|
+
nextActions: [
|
|
860
|
+
...queueIssues.actions,
|
|
861
|
+
...scoped.actions,
|
|
862
|
+
human("review_unadopted_object_decision", `${writeBlocker.message} If this task has no matching semantic work left, start a revised task with the current source evidence.`),
|
|
863
|
+
],
|
|
864
|
+
runtimeIdentity: identity,
|
|
865
|
+
permissions: noPermission(),
|
|
866
|
+
});
|
|
670
867
|
const references = inspectFoundryReferences(context, inspected.artifacts);
|
|
671
868
|
const scopeComplete = workflow.rows &&
|
|
672
869
|
(workflow.rows.value.sets.length > 0 || references.scope) &&
|
|
@@ -868,9 +1065,14 @@ function taskProjection(operation, context, record, inspected, identity) {
|
|
|
868
1065
|
],
|
|
869
1066
|
nextActions: [
|
|
870
1067
|
...queueIssues.actions,
|
|
1068
|
+
...scoped.actions,
|
|
871
1069
|
...pending.flatMap((set) => [
|
|
872
|
-
|
|
873
|
-
|
|
1070
|
+
...(!scoped.types.includes(set.type)
|
|
1071
|
+
? [
|
|
1072
|
+
human("review_semantic_work", `Read the registered curation report ${set.curation_report} and authoring manifest ${set.authoring_manifest}. Use their bound source/context evidence; no write permission is implied.`),
|
|
1073
|
+
]
|
|
1074
|
+
: []),
|
|
1075
|
+
...(!scoped.types.includes(set.type) ? (set.decisions ?? []) : []).map((work) => human(`review_${work.kind}_decisions`, `Read registered ${work.kind} task ${work.task} (${work.status}). Complete its bound decision template and submit it with semantic-input kind=${work.kind}.`)),
|
|
874
1076
|
]),
|
|
875
1077
|
...(workflow.assessmentRemainingTypes.length ? [resumeCommand(context, record)] : []),
|
|
876
1078
|
],
|
|
@@ -1335,6 +1537,9 @@ export function createFoundryFacade(options) {
|
|
|
1335
1537
|
return taskProjection("task.resume", context, record, await runtime.inspectTask(), runtimeIdentity(context, qualified));
|
|
1336
1538
|
}
|
|
1337
1539
|
if (input.authorizationInputFile) {
|
|
1540
|
+
const interactionBlocker = currentFoundryInteractionWriteBlocker(context, before.artifacts);
|
|
1541
|
+
if (interactionBlocker)
|
|
1542
|
+
throw new FoundryContextError(interactionBlocker.code, interactionBlocker.message);
|
|
1338
1543
|
if (input.semanticInputFile || record.spec.preparation)
|
|
1339
1544
|
throw new FoundryContextError("task_authorization_input_invalid", "Submit approval separately from semantic input or explicit cleanup.");
|
|
1340
1545
|
if (!qualified)
|
|
@@ -1399,6 +1604,9 @@ export function createFoundryFacade(options) {
|
|
|
1399
1604
|
}
|
|
1400
1605
|
const preparation = record.spec.preparation;
|
|
1401
1606
|
const workflow = currentWorkflowState(context, before.artifacts);
|
|
1607
|
+
if ((workflow.authorization || workflow.preparedApproval) &&
|
|
1608
|
+
currentFoundryInteractionWriteBlocker(context, before.artifacts))
|
|
1609
|
+
return existing;
|
|
1402
1610
|
if (hasUnresolvedInteraction &&
|
|
1403
1611
|
(workflow.authorization ||
|
|
1404
1612
|
!independentLocalPreparationPending(record, workflow, before.artifacts)))
|
|
@@ -2,13 +2,14 @@ import { type FoundryInputFact, type FoundryRuntimeContext } from "./foundry-run
|
|
|
2
2
|
import type { ArtifactEntry } from "./foundry-task-types.ts";
|
|
3
3
|
import { type FoundryInteractionInput, type FoundryInteractionState } from "./foundry-interaction-types.ts";
|
|
4
4
|
export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, FOUNDRY_INTERACTION_COMMAND, FOUNDRY_INTERACTION_REPORT, } from "./foundry-interaction-types.ts";
|
|
5
|
-
export type { FoundryInteractionInput, FoundryInteractionState, } from "./foundry-interaction-types.ts";
|
|
5
|
+
export type { FoundryInteractionInput, FoundryInteractionObjectScope, FoundryInteractionState, } from "./foundry-interaction-types.ts";
|
|
6
|
+
export { foundryInteractionObjectKey, foundryInteractionObjectProofKey, } from "./foundry-interaction-scope.ts";
|
|
6
7
|
export interface SelectedFoundryInteractionInput {
|
|
7
8
|
readonly spec: FoundryInteractionInput;
|
|
8
9
|
readonly descriptor: FoundryInputFact;
|
|
9
10
|
}
|
|
10
11
|
export declare function parseFoundryInteractionInput(value: unknown): FoundryInteractionInput;
|
|
11
|
-
export declare function advanceFoundryInteractionState(previous: FoundryInteractionState | null, input: FoundryInteractionInput, currentSha256: string | null, availableEvidence: ReadonlySet<string>, allowedTypes: ReadonlySet<string>): FoundryInteractionState;
|
|
12
|
+
export declare function advanceFoundryInteractionState(previous: FoundryInteractionState | null, input: FoundryInteractionInput, currentSha256: string | null, availableEvidence: ReadonlySet<string>, allowedTypes: ReadonlySet<string>, verifiedObjectScopes?: ReadonlySet<string>): FoundryInteractionState;
|
|
12
13
|
export declare function readSelectedFoundryInteractionBytes(fact: FoundryInputFact): Buffer;
|
|
13
14
|
export declare function selectFoundryInteractionInput(context: FoundryRuntimeContext, file: string): SelectedFoundryInteractionInput;
|
|
14
15
|
export declare function assertSelectedFoundryInteractionInput(input: SelectedFoundryInteractionInput): void;
|
|
@@ -16,4 +17,4 @@ export declare function currentFoundryInteractionState(context: FoundryRuntimeCo
|
|
|
16
17
|
entry: ArtifactEntry;
|
|
17
18
|
state: FoundryInteractionState;
|
|
18
19
|
} | null;
|
|
19
|
-
export { applicableFoundryInteractionDigest, applicableFoundryInteractionProjection, currentFoundryAssumptions, currentFoundryAssumptionsForType, currentFoundryDecisions, currentFoundryDecisionsForType, currentFoundryInvestigations, currentFoundryQuestions, } from "./foundry-interaction-projection.ts";
|
|
20
|
+
export { applicableFoundryInteractionDigest, applicableFoundryInteractionDigestForObject, applicableFoundryInteractionProjection, applicableFoundryInteractionProjectionForObject, currentFoundryAssumptions, currentFoundryAssumptionsForObject, currentFoundryAssumptionsForType, currentFoundryDecisions, currentFoundryDecisionsForObject, currentFoundryDecisionsForType, currentFoundryInvestigations, currentFoundryInvestigationsForObject, currentFoundryQuestions, currentFoundryQuestionsForObject, foundryInteractionEventAppliesToObject, } from "./foundry-interaction-projection.ts";
|
|
@@ -5,7 +5,9 @@ import { captureFoundryInput, FoundryContextError, } from "./foundry-runtime-con
|
|
|
5
5
|
import { assertNotFoundrySessionFile, migrationCredentialPath } from "./foundry-private-path.js";
|
|
6
6
|
import { readWorkflowArtifact } from "./foundry-workflow-state.js";
|
|
7
7
|
import { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, FOUNDRY_INTERACTION_COMMAND, FOUNDRY_INTERACTION_REPORT, } from "./foundry-interaction-types.js";
|
|
8
|
+
import { foundryInteractionObjectProofKey, sameFoundryInteractionScope, } from "./foundry-interaction-scope.js";
|
|
8
9
|
export { FOUNDRY_INTERACTION_INPUT_SCHEMA, FOUNDRY_INTERACTION_STATE_SCHEMA, FOUNDRY_INTERACTION_COMMAND, FOUNDRY_INTERACTION_REPORT, } from "./foundry-interaction-types.js";
|
|
10
|
+
export { foundryInteractionObjectKey, foundryInteractionObjectProofKey, } from "./foundry-interaction-scope.js";
|
|
9
11
|
const idPattern = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]{0,255}$/u;
|
|
10
12
|
const taskPattern = /^task-[0-9a-f]{64}-r\d{4}$/u;
|
|
11
13
|
const shaPattern = /^[0-9a-f]{64}$/u;
|
|
@@ -61,6 +63,19 @@ function datasetType(value) {
|
|
|
61
63
|
invalid("Question or assumption dataset type is invalid.");
|
|
62
64
|
return value;
|
|
63
65
|
}
|
|
66
|
+
function objectScope(item, type) {
|
|
67
|
+
if (!Object.hasOwn(item, "object_scope"))
|
|
68
|
+
return undefined;
|
|
69
|
+
if (type === null || type === "support")
|
|
70
|
+
invalid("An object scope requires one concrete dataset type.");
|
|
71
|
+
const scope = record(item.object_scope);
|
|
72
|
+
exact(scope, ["entity_id", "version", "row_sha256"]);
|
|
73
|
+
const entityId = identifier(scope.entity_id, "Object entity id");
|
|
74
|
+
const version = identifier(scope.version, "Object version");
|
|
75
|
+
if (typeof scope.row_sha256 !== "string" || !shaPattern.test(scope.row_sha256))
|
|
76
|
+
invalid("Object row SHA-256 is invalid.");
|
|
77
|
+
return Object.freeze({ entity_id: entityId, version, row_sha256: scope.row_sha256 });
|
|
78
|
+
}
|
|
64
79
|
function event(value) {
|
|
65
80
|
const item = record(value);
|
|
66
81
|
if (item.kind === "question") {
|
|
@@ -75,16 +90,20 @@ function event(value) {
|
|
|
75
90
|
"choices",
|
|
76
91
|
"evidence_sha256",
|
|
77
92
|
"supersedes",
|
|
93
|
+
...(Object.hasOwn(item, "object_scope") ? ["object_scope"] : []),
|
|
78
94
|
]);
|
|
79
95
|
if (!Array.isArray(item.choices) || item.choices.length > 4)
|
|
80
96
|
invalid("A question may offer at most four short choices.");
|
|
81
97
|
const choices = item.choices.map((choice) => bounded(choice, "Choice", 240));
|
|
82
98
|
if (new Set(choices).size !== choices.length)
|
|
83
99
|
invalid("Question choices must be unique.");
|
|
100
|
+
const type = datasetType(item.dataset_type);
|
|
101
|
+
const scope = objectScope(item, type);
|
|
84
102
|
return Object.freeze({
|
|
85
103
|
kind: "question",
|
|
86
104
|
id: identifier(item.id, "Question id"),
|
|
87
|
-
dataset_type:
|
|
105
|
+
dataset_type: type,
|
|
106
|
+
...(scope ? { object_scope: scope } : {}),
|
|
88
107
|
missing: bounded(item.missing, "Missing information", 1_200),
|
|
89
108
|
impact: bounded(item.impact, "Impact", 1_200),
|
|
90
109
|
recommendation: bounded(item.recommendation, "Recommendation", 1_200),
|
|
@@ -132,11 +151,15 @@ function event(value) {
|
|
|
132
151
|
"impact",
|
|
133
152
|
"evidence_sha256",
|
|
134
153
|
"supersedes",
|
|
154
|
+
...(Object.hasOwn(item, "object_scope") ? ["object_scope"] : []),
|
|
135
155
|
]);
|
|
156
|
+
const type = datasetType(item.dataset_type);
|
|
157
|
+
const scope = objectScope(item, type);
|
|
136
158
|
return Object.freeze({
|
|
137
159
|
kind: "assumption",
|
|
138
160
|
id: identifier(item.id, "Assumption id"),
|
|
139
|
-
dataset_type:
|
|
161
|
+
dataset_type: type,
|
|
162
|
+
...(scope ? { object_scope: scope } : {}),
|
|
140
163
|
statement: bounded(item.statement, "Assumption"),
|
|
141
164
|
impact: bounded(item.impact, "Assumption impact"),
|
|
142
165
|
evidence_sha256: evidence(item.evidence_sha256),
|
|
@@ -168,7 +191,7 @@ export function parseFoundryInteractionInput(value) {
|
|
|
168
191
|
events: Object.freeze(item.events.map(event)),
|
|
169
192
|
});
|
|
170
193
|
}
|
|
171
|
-
export function advanceFoundryInteractionState(previous, input, currentSha256, availableEvidence, allowedTypes) {
|
|
194
|
+
export function advanceFoundryInteractionState(previous, input, currentSha256, availableEvidence, allowedTypes, verifiedObjectScopes = new Set()) {
|
|
172
195
|
if (input.expected_state_sha256 !== currentSha256)
|
|
173
196
|
invalid("Interaction state changed; reload the current question and submit against its digest.");
|
|
174
197
|
if (previous && (previous.task_id !== input.task_id || previous.actor_id !== input.actor_id))
|
|
@@ -202,6 +225,11 @@ export function advanceFoundryInteractionState(previous, input, currentSha256, a
|
|
|
202
225
|
const type = item.dataset_type;
|
|
203
226
|
if (typeof type === "string" && !allowedTypes.has(type))
|
|
204
227
|
invalid("Interaction scope is outside this task's target entity types.");
|
|
228
|
+
if (item.kind !== "answer" && Object.hasOwn(item, "object_scope")) {
|
|
229
|
+
const scope = item.object_scope;
|
|
230
|
+
if (!verifiedObjectScopes.has(foundryInteractionObjectProofKey(String(type), scope.entity_id, scope.version, scope.row_sha256)))
|
|
231
|
+
invalid("Interaction object scope is not bound to a registered row.");
|
|
232
|
+
}
|
|
205
233
|
for (const sha of item.evidence_sha256)
|
|
206
234
|
if (!availableEvidence.has(sha))
|
|
207
235
|
invalid("Interaction evidence is not a registered source or artifact.");
|
|
@@ -213,12 +241,12 @@ export function advanceFoundryInteractionState(previous, input, currentSha256, a
|
|
|
213
241
|
const prior = questions.get(String(item.supersedes));
|
|
214
242
|
if (!prior ||
|
|
215
243
|
supersededQuestions.has(String(item.supersedes)) ||
|
|
216
|
-
prior
|
|
244
|
+
!sameFoundryInteractionScope(prior, item))
|
|
217
245
|
invalid("A replacement question must name one current question in the same scope.");
|
|
218
246
|
supersededQuestions.add(String(item.supersedes));
|
|
219
247
|
}
|
|
220
248
|
if ([...questions.values()].some((prior) => !supersededQuestions.has(String(prior.id)) &&
|
|
221
|
-
prior
|
|
249
|
+
sameFoundryInteractionScope(prior, item) &&
|
|
222
250
|
prior.missing === item.missing &&
|
|
223
251
|
prior.ask === item.ask))
|
|
224
252
|
invalid("Duplicate current question; use its existing id and answer.");
|
|
@@ -243,11 +271,16 @@ export function advanceFoundryInteractionState(previous, input, currentSha256, a
|
|
|
243
271
|
if (item.supersedes) {
|
|
244
272
|
const prior = assumptions.get(String(item.supersedes));
|
|
245
273
|
if (!prior ||
|
|
246
|
-
prior
|
|
274
|
+
!sameFoundryInteractionScope(prior, item) ||
|
|
247
275
|
supersededAssumptions.has(String(item.supersedes)))
|
|
248
276
|
invalid("A replacement assumption must name one current assumption in the same scope.");
|
|
249
277
|
supersededAssumptions.add(String(item.supersedes));
|
|
250
278
|
}
|
|
279
|
+
if (Object.hasOwn(item, "object_scope") &&
|
|
280
|
+
[...assumptions.values()].some((prior) => !supersededAssumptions.has(String(prior.id)) &&
|
|
281
|
+
sameFoundryInteractionScope(prior, item) &&
|
|
282
|
+
prior.statement === item.statement))
|
|
283
|
+
invalid("Duplicate current assumption for this object scope.");
|
|
251
284
|
assumptions.set(String(item.id), item);
|
|
252
285
|
}
|
|
253
286
|
events.push(item);
|
|
@@ -324,4 +357,4 @@ export function currentFoundryInteractionState(context, entries) {
|
|
|
324
357
|
}
|
|
325
358
|
return null;
|
|
326
359
|
}
|
|
327
|
-
export { applicableFoundryInteractionDigest, applicableFoundryInteractionProjection, currentFoundryAssumptions, currentFoundryAssumptionsForType, currentFoundryDecisions, currentFoundryDecisionsForType, currentFoundryInvestigations, currentFoundryQuestions, } from "./foundry-interaction-projection.js";
|
|
360
|
+
export { applicableFoundryInteractionDigest, applicableFoundryInteractionDigestForObject, applicableFoundryInteractionProjection, applicableFoundryInteractionProjectionForObject, currentFoundryAssumptions, currentFoundryAssumptionsForObject, currentFoundryAssumptionsForType, currentFoundryDecisions, currentFoundryDecisionsForObject, currentFoundryDecisionsForType, currentFoundryInvestigations, currentFoundryInvestigationsForObject, currentFoundryQuestions, currentFoundryQuestionsForObject, foundryInteractionEventAppliesToObject, } from "./foundry-interaction-projection.js";
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { FoundryInteractionState } from "./foundry-interaction-types.ts";
|
|
2
|
+
export { foundryInteractionEventAppliesToObject, foundryInteractionScopeApplies, } from "./foundry-interaction-scope.ts";
|
|
2
3
|
type Item = Readonly<Record<string, unknown>>;
|
|
3
|
-
export declare function foundryInteractionScopeApplies(scope: unknown, type: string): boolean;
|
|
4
4
|
export declare function currentFoundryQuestions(state: FoundryInteractionState): Item[];
|
|
5
5
|
export declare function currentFoundryInvestigations(state: FoundryInteractionState): Item[];
|
|
6
6
|
export declare function currentFoundryDecisions(state: FoundryInteractionState): Item[];
|
|
7
7
|
export declare function currentFoundryDecisionsForType(state: FoundryInteractionState, type: string): Item[];
|
|
8
|
+
export declare function currentFoundryQuestionsForObject(state: FoundryInteractionState, type: string, entityId: string, version: string): Item[];
|
|
9
|
+
export declare function currentFoundryInvestigationsForObject(state: FoundryInteractionState, type: string, entityId: string, version: string): Item[];
|
|
10
|
+
export declare function currentFoundryDecisionsForObject(state: FoundryInteractionState, type: string, entityId: string, version: string): Item[];
|
|
8
11
|
export declare function currentFoundryAssumptions(state: FoundryInteractionState): Item[];
|
|
9
12
|
export declare function currentFoundryAssumptionsForType(state: FoundryInteractionState, type: string): Item[];
|
|
13
|
+
export declare function currentFoundryAssumptionsForObject(state: FoundryInteractionState, type: string, entityId: string, version: string): Item[];
|
|
10
14
|
export declare function applicableFoundryInteractionProjection(state: FoundryInteractionState, type: string): {
|
|
11
15
|
schema: string;
|
|
12
16
|
dataset_type: string;
|
|
@@ -18,5 +22,20 @@ export declare function applicableFoundryInteractionProjection(state: FoundryInt
|
|
|
18
22
|
}[];
|
|
19
23
|
ai_assumptions: Readonly<Record<string, unknown>>[];
|
|
20
24
|
};
|
|
25
|
+
export declare function applicableFoundryInteractionProjectionForObject(state: FoundryInteractionState, type: string, entityId: string, version: string): {
|
|
26
|
+
schema: string;
|
|
27
|
+
dataset_type: string;
|
|
28
|
+
object_scope: {
|
|
29
|
+
entity_id: string;
|
|
30
|
+
version: string;
|
|
31
|
+
};
|
|
32
|
+
pending_questions: Readonly<Record<string, unknown>>[];
|
|
33
|
+
investigations: Readonly<Record<string, unknown>>[];
|
|
34
|
+
decisions: {
|
|
35
|
+
question: Readonly<Record<string, unknown>> | undefined;
|
|
36
|
+
answer: Readonly<Record<string, unknown>>;
|
|
37
|
+
}[];
|
|
38
|
+
ai_assumptions: Readonly<Record<string, unknown>>[];
|
|
39
|
+
};
|
|
21
40
|
export declare function applicableFoundryInteractionDigest(state: FoundryInteractionState | null, type: string): string | null;
|
|
22
|
-
export
|
|
41
|
+
export declare function applicableFoundryInteractionDigestForObject(state: FoundryInteractionState | null, type: string, entityId: string, version: string): string | null;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { sha256Json } from "./identity-preflight-proof.js";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
}
|
|
2
|
+
import { foundryInteractionEventAppliesToObject, foundryInteractionScopeApplies, } from "./foundry-interaction-scope.js";
|
|
3
|
+
export { foundryInteractionEventAppliesToObject, foundryInteractionScopeApplies, } from "./foundry-interaction-scope.js";
|
|
4
|
+
const broad = (item) => !Object.hasOwn(item, "object_scope");
|
|
6
5
|
function current(state) {
|
|
7
6
|
const questions = new Map();
|
|
8
7
|
const answers = new Map();
|
|
@@ -42,8 +41,21 @@ export function currentFoundryDecisions(state) {
|
|
|
42
41
|
export function currentFoundryDecisionsForType(state, type) {
|
|
43
42
|
const { questions } = current(state);
|
|
44
43
|
return currentFoundryDecisions(state).filter((answer) => {
|
|
45
|
-
const
|
|
46
|
-
return foundryInteractionScopeApplies(
|
|
44
|
+
const question = questions.get(String(answer.question_id));
|
|
45
|
+
return (question && broad(question) && foundryInteractionScopeApplies(question.dataset_type, type));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
export function currentFoundryQuestionsForObject(state, type, entityId, version) {
|
|
49
|
+
return currentFoundryQuestions(state).filter((question) => foundryInteractionEventAppliesToObject(question, type, entityId, version));
|
|
50
|
+
}
|
|
51
|
+
export function currentFoundryInvestigationsForObject(state, type, entityId, version) {
|
|
52
|
+
return currentFoundryInvestigations(state).filter((question) => foundryInteractionEventAppliesToObject(question, type, entityId, version));
|
|
53
|
+
}
|
|
54
|
+
export function currentFoundryDecisionsForObject(state, type, entityId, version) {
|
|
55
|
+
const { questions } = current(state);
|
|
56
|
+
return currentFoundryDecisions(state).filter((answer) => {
|
|
57
|
+
const question = questions.get(String(answer.question_id));
|
|
58
|
+
return question && foundryInteractionEventAppliesToObject(question, type, entityId, version);
|
|
47
59
|
});
|
|
48
60
|
}
|
|
49
61
|
export function currentFoundryAssumptions(state) {
|
|
@@ -51,11 +63,14 @@ export function currentFoundryAssumptions(state) {
|
|
|
51
63
|
return [...assumptions.values()].filter((assumption) => !supersededAssumptions.has(String(assumption.id)));
|
|
52
64
|
}
|
|
53
65
|
export function currentFoundryAssumptionsForType(state, type) {
|
|
54
|
-
return currentFoundryAssumptions(state).filter((assumption) => foundryInteractionScopeApplies(assumption.dataset_type, type));
|
|
66
|
+
return currentFoundryAssumptions(state).filter((assumption) => broad(assumption) && foundryInteractionScopeApplies(assumption.dataset_type, type));
|
|
67
|
+
}
|
|
68
|
+
export function currentFoundryAssumptionsForObject(state, type, entityId, version) {
|
|
69
|
+
return currentFoundryAssumptions(state).filter((assumption) => foundryInteractionEventAppliesToObject(assumption, type, entityId, version));
|
|
55
70
|
}
|
|
56
71
|
export function applicableFoundryInteractionProjection(state, type) {
|
|
57
72
|
const { questions } = current(state);
|
|
58
|
-
const applies = (item) => foundryInteractionScopeApplies(item.dataset_type, type);
|
|
73
|
+
const applies = (item) => broad(item) && foundryInteractionScopeApplies(item.dataset_type, type);
|
|
59
74
|
return {
|
|
60
75
|
schema: "tiangong-foundry.interaction-context.v1",
|
|
61
76
|
dataset_type: type,
|
|
@@ -68,6 +83,21 @@ export function applicableFoundryInteractionProjection(state, type) {
|
|
|
68
83
|
ai_assumptions: currentFoundryAssumptionsForType(state, type),
|
|
69
84
|
};
|
|
70
85
|
}
|
|
86
|
+
export function applicableFoundryInteractionProjectionForObject(state, type, entityId, version) {
|
|
87
|
+
const { questions } = current(state);
|
|
88
|
+
return {
|
|
89
|
+
schema: "tiangong-foundry.interaction-context.v1",
|
|
90
|
+
dataset_type: type,
|
|
91
|
+
object_scope: { entity_id: entityId, version },
|
|
92
|
+
pending_questions: currentFoundryQuestionsForObject(state, type, entityId, version),
|
|
93
|
+
investigations: currentFoundryInvestigationsForObject(state, type, entityId, version),
|
|
94
|
+
decisions: currentFoundryDecisionsForObject(state, type, entityId, version).map((answer) => ({
|
|
95
|
+
question: questions.get(String(answer.question_id)),
|
|
96
|
+
answer,
|
|
97
|
+
})),
|
|
98
|
+
ai_assumptions: currentFoundryAssumptionsForObject(state, type, entityId, version),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
71
101
|
export function applicableFoundryInteractionDigest(state, type) {
|
|
72
102
|
if (!state)
|
|
73
103
|
return null;
|
|
@@ -79,3 +109,14 @@ export function applicableFoundryInteractionDigest(state, type) {
|
|
|
79
109
|
return null;
|
|
80
110
|
return sha256Json(projected);
|
|
81
111
|
}
|
|
112
|
+
export function applicableFoundryInteractionDigestForObject(state, type, entityId, version) {
|
|
113
|
+
if (!state)
|
|
114
|
+
return null;
|
|
115
|
+
const projected = applicableFoundryInteractionProjectionForObject(state, type, entityId, version);
|
|
116
|
+
if (!projected.pending_questions.length &&
|
|
117
|
+
!projected.investigations.length &&
|
|
118
|
+
!projected.decisions.length &&
|
|
119
|
+
!projected.ai_assumptions.length)
|
|
120
|
+
return null;
|
|
121
|
+
return sha256Json(projected);
|
|
122
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
type Item = Readonly<Record<string, unknown>>;
|
|
2
|
+
export declare function foundryInteractionObjectKey(datasetType: string, entityId: string, version: string): string;
|
|
3
|
+
export declare function foundryInteractionObjectProofKey(datasetType: string, entityId: string, version: string, rowSha256: string): string;
|
|
4
|
+
export declare function foundryInteractionScopeApplies(scope: unknown, type: string): boolean;
|
|
5
|
+
export declare function foundryInteractionEventAppliesToObject(item: Item, type: string, entityId: string, version: string): boolean;
|
|
6
|
+
export declare function sameFoundryInteractionScope(left: Item, right: Item): boolean;
|
|
7
|
+
export {};
|