omnius 1.0.813 → 1.0.816
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/dist/api/py-embed.js +4277 -2406
- package/dist/index.js +2 -2
- package/dist/library.js +1964 -1792
- package/dist/memory-maintenance-worker.js +1799 -68
- package/dist/update-worker.js +4302 -2431
- package/docs/DISCOVERY.json +36 -0
- package/docs/DISCOVERY.md +1 -0
- package/docs/engineering/kolibri-placement-and-empty-response-20261007.md +113 -0
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -1
|
@@ -626,6 +626,1737 @@ var DEFAULT_CAPACITIES = {
|
|
|
626
626
|
L5: Number.POSITIVE_INFINITY
|
|
627
627
|
};
|
|
628
628
|
|
|
629
|
+
// packages/schemas/dist/feature-workflow.js
|
|
630
|
+
import { z } from "zod";
|
|
631
|
+
var FEATURE_WORKFLOW_PLAN_SCHEMA = "omnius.feature-workflow-plan.v1";
|
|
632
|
+
var FEATURE_WORKFLOW_PHASES = [
|
|
633
|
+
"research",
|
|
634
|
+
"specification",
|
|
635
|
+
"implementation",
|
|
636
|
+
"integration",
|
|
637
|
+
"acceptance",
|
|
638
|
+
"handoff"
|
|
639
|
+
];
|
|
640
|
+
var FeatureWorkflowPhaseSchema = z.enum(FEATURE_WORKFLOW_PHASES);
|
|
641
|
+
var id = z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.:-]{0,119}$/);
|
|
642
|
+
var text = z.string().trim().min(1).max(4e3);
|
|
643
|
+
var FeatureWorkflowArtifactReferenceSchema = z.string().regex(/^omnius-artifact:\/\/sha256\/[a-f0-9]{64}$/);
|
|
644
|
+
var path = z.string().trim().min(1).max(1e3);
|
|
645
|
+
var FeatureWorkflowCardSchema = z.object({
|
|
646
|
+
id,
|
|
647
|
+
title: text,
|
|
648
|
+
phase: FeatureWorkflowPhaseSchema,
|
|
649
|
+
role: z.enum([
|
|
650
|
+
"researcher",
|
|
651
|
+
"author",
|
|
652
|
+
"reviewer",
|
|
653
|
+
"implementer",
|
|
654
|
+
"integrator",
|
|
655
|
+
"verifier",
|
|
656
|
+
"synthesizer"
|
|
657
|
+
]),
|
|
658
|
+
dependsOn: z.array(id).max(128).default([]),
|
|
659
|
+
sourceIds: z.array(id).max(256).default([]),
|
|
660
|
+
inputSlots: z.array(id).max(256).default([]),
|
|
661
|
+
reviewSlots: z.array(id).max(32).default([]),
|
|
662
|
+
ownedFiles: z.array(path).max(128).default([]),
|
|
663
|
+
acceptanceIds: z.array(id).max(256).default([]),
|
|
664
|
+
verifier: z.object({
|
|
665
|
+
command: z.string().trim().min(1).max(4e3),
|
|
666
|
+
cwd: path.optional(),
|
|
667
|
+
targetPaths: z.array(path).min(1).max(128)
|
|
668
|
+
}).strict().optional()
|
|
669
|
+
}).strict();
|
|
670
|
+
var FeatureWorkflowPlanSchema = z.object({
|
|
671
|
+
schema: z.literal(FEATURE_WORKFLOW_PLAN_SCHEMA),
|
|
672
|
+
id,
|
|
673
|
+
revision: z.number().int().min(1).max(Number.MAX_SAFE_INTEGER),
|
|
674
|
+
objective: text,
|
|
675
|
+
requirements: z.array(z.object({ id, description: text }).strict()).min(1).max(256),
|
|
676
|
+
sources: z.array(z.object({ id, reference: FeatureWorkflowArtifactReferenceSchema }).strict()).max(256).default([]),
|
|
677
|
+
slots: z.array(z.object({
|
|
678
|
+
id,
|
|
679
|
+
kind: z.enum([
|
|
680
|
+
"research",
|
|
681
|
+
"specification",
|
|
682
|
+
"implementation",
|
|
683
|
+
"integration",
|
|
684
|
+
"review",
|
|
685
|
+
"handoff"
|
|
686
|
+
]),
|
|
687
|
+
cardId: id,
|
|
688
|
+
requiresReview: z.boolean().default(false)
|
|
689
|
+
}).strict()).min(4).max(256),
|
|
690
|
+
cards: z.array(FeatureWorkflowCardSchema).min(6).max(128)
|
|
691
|
+
}).strict().superRefine((plan, ctx) => {
|
|
692
|
+
const fail = (message) => ctx.addIssue({ code: "custom", message });
|
|
693
|
+
const unique = (values, label) => {
|
|
694
|
+
if (new Set(values).size !== values.length)
|
|
695
|
+
fail(`duplicate ${label}`);
|
|
696
|
+
};
|
|
697
|
+
unique(plan.cards.map((c) => c.id), "card id");
|
|
698
|
+
unique(plan.slots.map((s) => s.id), "slot id");
|
|
699
|
+
unique(plan.sources.map((s) => s.id), "source id");
|
|
700
|
+
unique(plan.requirements.map((r) => r.id), "requirement id");
|
|
701
|
+
const cards = new Map(plan.cards.map((c) => [c.id, c]));
|
|
702
|
+
const slots = new Map(plan.slots.map((s) => [s.id, s]));
|
|
703
|
+
const sources = new Set(plan.sources.map((s) => s.id));
|
|
704
|
+
const assertions = new Map(plan.requirements.map((r) => [r.id, 0]));
|
|
705
|
+
for (const phase of FEATURE_WORKFLOW_PHASES)
|
|
706
|
+
if (!plan.cards.some((c) => c.phase === phase))
|
|
707
|
+
fail(`missing phase ${phase}`);
|
|
708
|
+
for (const slot of plan.slots) {
|
|
709
|
+
if (slot.id.startsWith("source:"))
|
|
710
|
+
fail(`reserved source namespace ${slot.id}`);
|
|
711
|
+
const producer = cards.get(slot.cardId);
|
|
712
|
+
if (!producer)
|
|
713
|
+
fail(`unknown producer ${slot.cardId}`);
|
|
714
|
+
if (slot.requiresReview && !plan.cards.some((c) => c.role === "reviewer" && c.reviewSlots.includes(slot.id)))
|
|
715
|
+
fail(`missing independent review for ${slot.id}`);
|
|
716
|
+
if (slot.requiresReview && producer && plan.cards.some((c) => c.reviewSlots.includes(slot.id) && c.phase !== producer.phase))
|
|
717
|
+
fail(`review must occur in producer phase ${slot.id}`);
|
|
718
|
+
}
|
|
719
|
+
for (const kind of [
|
|
720
|
+
"research",
|
|
721
|
+
"specification",
|
|
722
|
+
"integration",
|
|
723
|
+
"handoff"
|
|
724
|
+
]) {
|
|
725
|
+
if (!plan.slots.some((s) => s.kind === kind && cards.get(s.cardId)?.phase === kind))
|
|
726
|
+
fail(`missing ${kind} artifact`);
|
|
727
|
+
}
|
|
728
|
+
if (!plan.slots.some((s) => s.kind === "specification" && s.requiresReview))
|
|
729
|
+
fail("specification requires independent review");
|
|
730
|
+
for (const card of plan.cards) {
|
|
731
|
+
if (card.role !== "reviewer" && card.role !== "verifier" && !plan.slots.some((slot) => slot.cardId === card.id))
|
|
732
|
+
fail(`work card requires an artifact slot ${card.id}`);
|
|
733
|
+
for (const [label, values] of Object.entries({
|
|
734
|
+
dependency: card.dependsOn,
|
|
735
|
+
source: card.sourceIds,
|
|
736
|
+
input: card.inputSlots,
|
|
737
|
+
review: card.reviewSlots,
|
|
738
|
+
acceptance: card.acceptanceIds
|
|
739
|
+
}))
|
|
740
|
+
unique(values, `${label} in ${card.id}`);
|
|
741
|
+
for (const dep of card.dependsOn)
|
|
742
|
+
if (!cards.has(dep))
|
|
743
|
+
fail(`unknown dependency ${dep}`);
|
|
744
|
+
for (const source of card.sourceIds)
|
|
745
|
+
if (!sources.has(source))
|
|
746
|
+
fail(`unknown source ${source}`);
|
|
747
|
+
for (const slotId of [...card.inputSlots, ...card.reviewSlots]) {
|
|
748
|
+
const slot = slots.get(slotId);
|
|
749
|
+
if (!slot) {
|
|
750
|
+
fail(`unknown slot ${slotId}`);
|
|
751
|
+
continue;
|
|
752
|
+
}
|
|
753
|
+
const producer = cards.get(slot.cardId);
|
|
754
|
+
if (slot.cardId === card.id)
|
|
755
|
+
fail(`self-dependent slot ${slotId}`);
|
|
756
|
+
if (producer && FEATURE_WORKFLOW_PHASES.indexOf(producer.phase) > FEATURE_WORKFLOW_PHASES.indexOf(card.phase))
|
|
757
|
+
fail(`future slot ${slotId}`);
|
|
758
|
+
}
|
|
759
|
+
for (const dep of card.dependsOn) {
|
|
760
|
+
const source = cards.get(dep);
|
|
761
|
+
if (source && FEATURE_WORKFLOW_PHASES.indexOf(source.phase) > FEATURE_WORKFLOW_PHASES.indexOf(card.phase))
|
|
762
|
+
fail(`future dependency ${dep}`);
|
|
763
|
+
}
|
|
764
|
+
if (card.role === "reviewer" !== card.reviewSlots.length > 0)
|
|
765
|
+
fail(`review role/slots mismatch ${card.id}`);
|
|
766
|
+
if (card.phase === "acceptance" && (card.role !== "verifier" || !card.verifier || card.acceptanceIds.length === 0))
|
|
767
|
+
fail(`acceptance needs explicit verifier ${card.id}`);
|
|
768
|
+
if (card.phase !== "acceptance" && (card.verifier || card.acceptanceIds.length))
|
|
769
|
+
fail(`acceptance authority outside acceptance phase ${card.id}`);
|
|
770
|
+
if (card.phase === "implementation" && card.role !== "reviewer" && (card.role !== "implementer" || card.ownedFiles.length === 0))
|
|
771
|
+
fail(`implementation needs owned files ${card.id}`);
|
|
772
|
+
for (const assertion of card.acceptanceIds) {
|
|
773
|
+
if (!assertions.has(assertion))
|
|
774
|
+
fail(`unknown acceptance ${assertion}`);
|
|
775
|
+
else
|
|
776
|
+
assertions.set(assertion, assertions.get(assertion) + 1);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
for (const [assertion, count] of assertions)
|
|
780
|
+
if (count !== 1)
|
|
781
|
+
fail(`acceptance ${assertion} must have exactly one owner`);
|
|
782
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
783
|
+
const visited = /* @__PURE__ */ new Set();
|
|
784
|
+
const visit = (cardId) => {
|
|
785
|
+
if (visiting.has(cardId)) {
|
|
786
|
+
fail(`dependency cycle ${cardId}`);
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
if (visited.has(cardId))
|
|
790
|
+
return;
|
|
791
|
+
const card = cards.get(cardId);
|
|
792
|
+
if (!card)
|
|
793
|
+
return;
|
|
794
|
+
visiting.add(cardId);
|
|
795
|
+
for (const dependency of [
|
|
796
|
+
...card.dependsOn,
|
|
797
|
+
...[...card.inputSlots, ...card.reviewSlots].map((s) => slots.get(s)?.cardId).filter((s) => !!s)
|
|
798
|
+
])
|
|
799
|
+
visit(dependency);
|
|
800
|
+
visiting.delete(cardId);
|
|
801
|
+
visited.add(cardId);
|
|
802
|
+
};
|
|
803
|
+
for (const card of plan.cards)
|
|
804
|
+
visit(card.id);
|
|
805
|
+
});
|
|
806
|
+
var FeatureWorkflowChildReportSchema = z.object({
|
|
807
|
+
schema: z.literal("omnius.feature-workflow-child-report.v1"),
|
|
808
|
+
cardId: id,
|
|
809
|
+
status: z.enum(["completed", "partial", "blocked", "failed"]),
|
|
810
|
+
inputSlots: z.record(z.string().min(1).max(256), FeatureWorkflowArtifactReferenceSchema),
|
|
811
|
+
artifacts: z.array(z.object({ slotId: id, content: z.string().min(1).max(1e5) }).strict()).max(32).default([]),
|
|
812
|
+
review: z.object({
|
|
813
|
+
disposition: z.enum(["approved", "changes_requested"]),
|
|
814
|
+
reviewedSlots: z.record(id, FeatureWorkflowArtifactReferenceSchema),
|
|
815
|
+
findings: z.array(z.object({
|
|
816
|
+
id,
|
|
817
|
+
severity: z.enum(["info", "blocking"]),
|
|
818
|
+
detail: text
|
|
819
|
+
}).strict()).max(64)
|
|
820
|
+
}).strict().optional(),
|
|
821
|
+
blockers: z.array(text).max(32),
|
|
822
|
+
unresolvedQuestions: z.array(text).max(32)
|
|
823
|
+
}).strict();
|
|
824
|
+
var FeatureWorkflowToolInputSchema = z.discriminatedUnion("action", [
|
|
825
|
+
z.object({
|
|
826
|
+
action: z.enum(["create", "revise"]),
|
|
827
|
+
plan: FeatureWorkflowPlanSchema
|
|
828
|
+
}).strict(),
|
|
829
|
+
z.object({ action: z.literal("status") }).strict(),
|
|
830
|
+
z.object({ action: z.literal("discover") }).strict(),
|
|
831
|
+
z.object({
|
|
832
|
+
action: z.literal("resume"),
|
|
833
|
+
runId: id,
|
|
834
|
+
planReference: FeatureWorkflowArtifactReferenceSchema,
|
|
835
|
+
objectiveId: id
|
|
836
|
+
}).strict(),
|
|
837
|
+
z.object({
|
|
838
|
+
action: z.literal("repair"),
|
|
839
|
+
cardId: id,
|
|
840
|
+
failedCardId: id,
|
|
841
|
+
reason: text
|
|
842
|
+
}).strict(),
|
|
843
|
+
z.object({
|
|
844
|
+
action: z.literal("record_artifact"),
|
|
845
|
+
cardId: id,
|
|
846
|
+
slotId: id,
|
|
847
|
+
path
|
|
848
|
+
}).strict()
|
|
849
|
+
]);
|
|
850
|
+
var FeatureWorkflowToolJsonSchema = z.toJSONSchema(FeatureWorkflowToolInputSchema, { reused: "ref", unrepresentable: "any" });
|
|
851
|
+
|
|
852
|
+
// packages/schemas/dist/messages.js
|
|
853
|
+
import { z as z2 } from "zod";
|
|
854
|
+
var AgentMessageSchema = z2.object({
|
|
855
|
+
id: z2.string().uuid(),
|
|
856
|
+
sessionId: z2.string().uuid(),
|
|
857
|
+
role: z2.enum(["user", "assistant", "system", "tool"]),
|
|
858
|
+
content: z2.string(),
|
|
859
|
+
timestamp: z2.string().datetime(),
|
|
860
|
+
metadata: z2.record(z2.string(), z2.unknown()).optional()
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
// packages/schemas/dist/tools.js
|
|
864
|
+
import { z as z3 } from "zod";
|
|
865
|
+
var ToolCallSchema = z3.object({
|
|
866
|
+
id: z3.string().uuid(),
|
|
867
|
+
name: z3.string(),
|
|
868
|
+
arguments: z3.record(z3.string(), z3.unknown()),
|
|
869
|
+
result: z3.unknown().optional(),
|
|
870
|
+
status: z3.enum(["pending", "running", "completed", "failed"]),
|
|
871
|
+
startedAt: z3.string().datetime().optional(),
|
|
872
|
+
completedAt: z3.string().datetime().optional()
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
// packages/schemas/dist/session.js
|
|
876
|
+
import { z as z4 } from "zod";
|
|
877
|
+
var SessionSchema = z4.object({
|
|
878
|
+
id: z4.string().uuid(),
|
|
879
|
+
projectRoot: z4.string(),
|
|
880
|
+
model: z4.string(),
|
|
881
|
+
createdAt: z4.string().datetime(),
|
|
882
|
+
updatedAt: z4.string().datetime(),
|
|
883
|
+
status: z4.enum(["active", "paused", "completed", "error"]),
|
|
884
|
+
config: z4.record(z4.string(), z4.unknown()).optional()
|
|
885
|
+
});
|
|
886
|
+
|
|
887
|
+
// packages/schemas/dist/task.js
|
|
888
|
+
import { z as z5 } from "zod";
|
|
889
|
+
var TaskClassSchema = z5.enum([
|
|
890
|
+
"bugfix",
|
|
891
|
+
"feature",
|
|
892
|
+
"refactor",
|
|
893
|
+
"migration",
|
|
894
|
+
"dependency-upgrade",
|
|
895
|
+
"test",
|
|
896
|
+
"docs",
|
|
897
|
+
"infra"
|
|
898
|
+
]);
|
|
899
|
+
var UrgencySchema = z5.enum(["low", "medium", "high", "critical"]);
|
|
900
|
+
var NormalizedTaskSchema = z5.object({
|
|
901
|
+
/** Stable unique identifier for this task instance */
|
|
902
|
+
id: z5.string(),
|
|
903
|
+
/** Human-readable goal description */
|
|
904
|
+
goal: z5.string().min(1),
|
|
905
|
+
/** Constraints the solution must satisfy */
|
|
906
|
+
constraints: z5.array(z5.string()),
|
|
907
|
+
/** Criteria that must pass for the task to be considered done */
|
|
908
|
+
successCriteria: z5.array(z5.string()),
|
|
909
|
+
/** Absolute path to the repo root */
|
|
910
|
+
repoRoot: z5.string(),
|
|
911
|
+
urgency: UrgencySchema,
|
|
912
|
+
taskClass: TaskClassSchema,
|
|
913
|
+
/** Original raw user request before normalization */
|
|
914
|
+
rawRequest: z5.string().optional(),
|
|
915
|
+
/** Timestamp when the task was created (ISO-8601) */
|
|
916
|
+
createdAt: z5.string().datetime()
|
|
917
|
+
});
|
|
918
|
+
var TaskStatusSchema = z5.enum([
|
|
919
|
+
"pending",
|
|
920
|
+
"dispatched",
|
|
921
|
+
"in_progress",
|
|
922
|
+
"success",
|
|
923
|
+
"partial_success",
|
|
924
|
+
"needs_human_decision",
|
|
925
|
+
"blocked_missing_context",
|
|
926
|
+
"rollback_required",
|
|
927
|
+
"failed"
|
|
928
|
+
]);
|
|
929
|
+
|
|
930
|
+
// packages/schemas/dist/plan.js
|
|
931
|
+
import { z as z6 } from "zod";
|
|
932
|
+
var SubtaskKindSchema = z6.enum([
|
|
933
|
+
"inspect",
|
|
934
|
+
"patch",
|
|
935
|
+
"test",
|
|
936
|
+
"migrate",
|
|
937
|
+
"verify",
|
|
938
|
+
"merge"
|
|
939
|
+
]);
|
|
940
|
+
var SubtaskSchema = z6.object({
|
|
941
|
+
/** Stable identifier used for dependency references */
|
|
942
|
+
id: z6.string().min(1),
|
|
943
|
+
kind: SubtaskKindSchema,
|
|
944
|
+
/** File paths or symbol names that this subtask targets */
|
|
945
|
+
targets: z6.array(z6.string()),
|
|
946
|
+
/** IDs of subtasks that must complete before this one starts */
|
|
947
|
+
dependsOn: z6.array(z6.string()).optional(),
|
|
948
|
+
/** Why this subtask is necessary */
|
|
949
|
+
reason: z6.string().min(1),
|
|
950
|
+
/** Shell commands or assertions that confirm success */
|
|
951
|
+
validation: z6.array(z6.string())
|
|
952
|
+
});
|
|
953
|
+
var PlanSchema = z6.object({
|
|
954
|
+
goal: z6.string().min(1),
|
|
955
|
+
subtasks: z6.array(SubtaskSchema),
|
|
956
|
+
/** Files/modules at elevated risk of breakage */
|
|
957
|
+
riskAreas: z6.array(z6.string()),
|
|
958
|
+
/** Aspects of the codebase that are unclear or ambiguous */
|
|
959
|
+
unknowns: z6.array(z6.string())
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
// packages/schemas/dist/patch.js
|
|
963
|
+
import { z as z7 } from "zod";
|
|
964
|
+
var EditOperationSchema = z7.enum([
|
|
965
|
+
"diff",
|
|
966
|
+
"rewrite",
|
|
967
|
+
"append",
|
|
968
|
+
"create"
|
|
969
|
+
]);
|
|
970
|
+
var FileEditSchema = z7.object({
|
|
971
|
+
/** Repo-relative or absolute path to the file being edited */
|
|
972
|
+
file: z7.string().min(1),
|
|
973
|
+
operation: EditOperationSchema,
|
|
974
|
+
/** Unified diff, full file content, appended text, or new file content */
|
|
975
|
+
content: z7.string()
|
|
976
|
+
});
|
|
977
|
+
var NeedsMoreContextSchema = z7.object({
|
|
978
|
+
reason: z7.string().min(1),
|
|
979
|
+
requestedPaths: z7.array(z7.string()).optional(),
|
|
980
|
+
requestedSymbols: z7.array(z7.string()).optional()
|
|
981
|
+
});
|
|
982
|
+
var PatchProposalSchema = z7.object({
|
|
983
|
+
/** One-paragraph description of what changed and why */
|
|
984
|
+
summary: z7.string().min(1),
|
|
985
|
+
edits: z7.array(FileEditSchema),
|
|
986
|
+
/** Test commands or test file paths that should be executed to validate */
|
|
987
|
+
testsToRun: z7.array(z7.string()),
|
|
988
|
+
/** Assumptions the editor made that the verifier should check */
|
|
989
|
+
assumptions: z7.array(z7.string()),
|
|
990
|
+
/** Known risks introduced by this patch */
|
|
991
|
+
risks: z7.array(z7.string()),
|
|
992
|
+
/**
|
|
993
|
+
* When the editor cannot safely produce a patch without more information.
|
|
994
|
+
* The presence of this field indicates the patch is incomplete.
|
|
995
|
+
*/
|
|
996
|
+
needsMoreContext: NeedsMoreContextSchema.optional()
|
|
997
|
+
});
|
|
998
|
+
|
|
999
|
+
// packages/schemas/dist/verification.js
|
|
1000
|
+
import { z as z8 } from "zod";
|
|
1001
|
+
var VerificationStatusSchema = z8.enum(["pass", "fail", "partial"]);
|
|
1002
|
+
var VerificationNextActionSchema = z8.enum([
|
|
1003
|
+
"finish",
|
|
1004
|
+
"retry",
|
|
1005
|
+
"rollback",
|
|
1006
|
+
"inspect_more"
|
|
1007
|
+
]);
|
|
1008
|
+
var VerificationDecisionSchema = z8.object({
|
|
1009
|
+
status: VerificationStatusSchema,
|
|
1010
|
+
/** Concrete evidence lines from logs, test output, or type-checker output */
|
|
1011
|
+
evidence: z8.array(z8.string()),
|
|
1012
|
+
nextAction: VerificationNextActionSchema,
|
|
1013
|
+
/** Files that should be prioritised in the next retrieval/editing round */
|
|
1014
|
+
focusFiles: z8.array(z8.string()),
|
|
1015
|
+
/**
|
|
1016
|
+
* Short fingerprint string identifying the failure category.
|
|
1017
|
+
* Used to detect repeat failure loops. Only present when status !== "pass".
|
|
1018
|
+
*/
|
|
1019
|
+
failureFingerprint: z8.string().optional()
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
// packages/schemas/dist/repoProfile.js
|
|
1023
|
+
import { z as z9 } from "zod";
|
|
1024
|
+
var LanguageSchema = z9.enum([
|
|
1025
|
+
"typescript",
|
|
1026
|
+
"javascript",
|
|
1027
|
+
"python",
|
|
1028
|
+
"go",
|
|
1029
|
+
"rust",
|
|
1030
|
+
"java",
|
|
1031
|
+
"csharp",
|
|
1032
|
+
"sql",
|
|
1033
|
+
"other"
|
|
1034
|
+
]);
|
|
1035
|
+
var PackageManagerSchema = z9.enum([
|
|
1036
|
+
"npm",
|
|
1037
|
+
"pnpm",
|
|
1038
|
+
"yarn",
|
|
1039
|
+
"bun",
|
|
1040
|
+
"pip",
|
|
1041
|
+
"poetry",
|
|
1042
|
+
"cargo",
|
|
1043
|
+
"go-modules",
|
|
1044
|
+
"maven",
|
|
1045
|
+
"gradle",
|
|
1046
|
+
"other"
|
|
1047
|
+
]);
|
|
1048
|
+
var BuildSystemSchema = z9.enum([
|
|
1049
|
+
"tsc",
|
|
1050
|
+
"vite",
|
|
1051
|
+
"webpack",
|
|
1052
|
+
"esbuild",
|
|
1053
|
+
"turbo",
|
|
1054
|
+
"nx",
|
|
1055
|
+
"make",
|
|
1056
|
+
"cmake",
|
|
1057
|
+
"cargo",
|
|
1058
|
+
"gradle",
|
|
1059
|
+
"maven",
|
|
1060
|
+
"other"
|
|
1061
|
+
]);
|
|
1062
|
+
var MigrationSystemSchema = z9.enum([
|
|
1063
|
+
"prisma",
|
|
1064
|
+
"drizzle",
|
|
1065
|
+
"knex",
|
|
1066
|
+
"alembic",
|
|
1067
|
+
"flyway",
|
|
1068
|
+
"liquibase",
|
|
1069
|
+
"typeorm",
|
|
1070
|
+
"sequelize",
|
|
1071
|
+
"other",
|
|
1072
|
+
"none"
|
|
1073
|
+
]);
|
|
1074
|
+
var RepoProfileSchema = z9.object({
|
|
1075
|
+
/** Languages present in the repo, ordered by prevalence */
|
|
1076
|
+
languages: z9.array(LanguageSchema),
|
|
1077
|
+
/** Frameworks detected (e.g. "nextjs", "fastapi", "express") */
|
|
1078
|
+
frameworks: z9.array(z9.string()),
|
|
1079
|
+
packageManager: PackageManagerSchema.optional(),
|
|
1080
|
+
buildSystem: BuildSystemSchema.optional(),
|
|
1081
|
+
/** Shell commands known to run the test suite */
|
|
1082
|
+
testCommands: z9.array(z9.string()),
|
|
1083
|
+
/** Shell commands known to run the linter */
|
|
1084
|
+
lintCommands: z9.array(z9.string()),
|
|
1085
|
+
migrationSystem: MigrationSystemSchema.optional(),
|
|
1086
|
+
/** Runtime assumptions such as Node version, Python version, etc. */
|
|
1087
|
+
runtimeAssumptions: z9.array(z9.string()),
|
|
1088
|
+
/** Names of environment variables the repo consumes */
|
|
1089
|
+
envVarNames: z9.array(z9.string()),
|
|
1090
|
+
/** Deployment-related notes (e.g. Docker, Kubernetes, serverless) */
|
|
1091
|
+
deploymentNotes: z9.array(z9.string()),
|
|
1092
|
+
/** Absolute path to the repo root on the agent's filesystem */
|
|
1093
|
+
repoRoot: z9.string(),
|
|
1094
|
+
/** ISO-8601 timestamp of the last profile update */
|
|
1095
|
+
lastIndexed: z9.string().datetime()
|
|
1096
|
+
});
|
|
1097
|
+
|
|
1098
|
+
// packages/schemas/dist/retrieval.js
|
|
1099
|
+
import { z as z10 } from "zod";
|
|
1100
|
+
var RetrievalRequestSchema = z10.object({
|
|
1101
|
+
/** Natural language description of what information is needed */
|
|
1102
|
+
query: z10.string().min(1),
|
|
1103
|
+
/** File path hints that the retrieval system should prioritise */
|
|
1104
|
+
pathsHint: z10.array(z10.string()),
|
|
1105
|
+
/** Symbol names (functions, classes, types) to look up */
|
|
1106
|
+
symbolHint: z10.array(z10.string()),
|
|
1107
|
+
/** Error message fragments to search for in logs and source */
|
|
1108
|
+
errorHint: z10.array(z10.string()),
|
|
1109
|
+
/** Maximum number of files to include in the retrieval packet */
|
|
1110
|
+
maxFiles: z10.number().int().positive(),
|
|
1111
|
+
/** Maximum number of code snippets to include */
|
|
1112
|
+
maxSnippets: z10.number().int().positive(),
|
|
1113
|
+
/** Whether test files should be included in results */
|
|
1114
|
+
includeTests: z10.boolean(),
|
|
1115
|
+
/** Whether config files (tsconfig, package.json, .env.example …) should be included */
|
|
1116
|
+
includeConfigs: z10.boolean()
|
|
1117
|
+
});
|
|
1118
|
+
var SnippetSchema = z10.object({
|
|
1119
|
+
/** Repo-relative path of the source file */
|
|
1120
|
+
file: z10.string(),
|
|
1121
|
+
/** 1-based start line */
|
|
1122
|
+
startLine: z10.number().int().positive(),
|
|
1123
|
+
/** 1-based end line (inclusive) */
|
|
1124
|
+
endLine: z10.number().int().positive(),
|
|
1125
|
+
/** The actual source text */
|
|
1126
|
+
content: z10.string(),
|
|
1127
|
+
/** Why this snippet was selected */
|
|
1128
|
+
relevanceNote: z10.string().optional()
|
|
1129
|
+
});
|
|
1130
|
+
var RetrievalPacketSchema = z10.object({
|
|
1131
|
+
/** Echo of the original request that produced this packet */
|
|
1132
|
+
request: RetrievalRequestSchema,
|
|
1133
|
+
/** Full file contents or extracts, keyed by repo-relative path */
|
|
1134
|
+
files: z10.record(z10.string(), z10.string()),
|
|
1135
|
+
snippets: z10.array(SnippetSchema),
|
|
1136
|
+
/** One-line architecture note for orientation */
|
|
1137
|
+
architectureNote: z10.string().optional(),
|
|
1138
|
+
/** Note summarising relevant prior attempts at related tasks */
|
|
1139
|
+
priorAttemptNote: z10.string().optional(),
|
|
1140
|
+
/** ISO-8601 timestamp when the packet was assembled */
|
|
1141
|
+
assembledAt: z10.string().datetime()
|
|
1142
|
+
});
|
|
1143
|
+
|
|
1144
|
+
// packages/schemas/dist/dispatch.js
|
|
1145
|
+
import { z as z11 } from "zod";
|
|
1146
|
+
var DispatchModeSchema = z11.enum([
|
|
1147
|
+
"single_pass",
|
|
1148
|
+
"multi_agent",
|
|
1149
|
+
"hybrid"
|
|
1150
|
+
]);
|
|
1151
|
+
var TaskComplexitySchema = z11.enum(["low", "medium", "high"]);
|
|
1152
|
+
var AgentRoleSchema = z11.enum([
|
|
1153
|
+
"planner",
|
|
1154
|
+
"scout",
|
|
1155
|
+
"editor",
|
|
1156
|
+
"verifier",
|
|
1157
|
+
"researcher"
|
|
1158
|
+
]);
|
|
1159
|
+
var BudgetsSchema = z11.object({
|
|
1160
|
+
/** Maximum prompt tokens across all model calls for this task */
|
|
1161
|
+
promptTokens: z11.number().int().positive(),
|
|
1162
|
+
/** Maximum number of retry cycles allowed per subtask */
|
|
1163
|
+
retries: z11.number().int().nonnegative(),
|
|
1164
|
+
/** Maximum wall-clock seconds before the task is considered timed out */
|
|
1165
|
+
wallClockSec: z11.number().positive()
|
|
1166
|
+
});
|
|
1167
|
+
var DispatchDecisionSchema = z11.object({
|
|
1168
|
+
mode: DispatchModeSchema,
|
|
1169
|
+
taskComplexity: TaskComplexitySchema,
|
|
1170
|
+
splitRecommended: z11.boolean(),
|
|
1171
|
+
/** Agent roles that should be spun up for the first wave of execution */
|
|
1172
|
+
initialAgents: z11.array(AgentRoleSchema),
|
|
1173
|
+
budgets: BudgetsSchema
|
|
1174
|
+
});
|
|
1175
|
+
|
|
1176
|
+
// packages/schemas/dist/memory.js
|
|
1177
|
+
import { z as z12 } from "zod";
|
|
1178
|
+
var RiskLevelSchema = z12.enum(["low", "medium", "high", "critical"]);
|
|
1179
|
+
var FileSummarySchema = z12.object({
|
|
1180
|
+
/** Repo-relative path of the file */
|
|
1181
|
+
path: z12.string().min(1),
|
|
1182
|
+
/** One-sentence description of the file's role */
|
|
1183
|
+
purpose: z12.string(),
|
|
1184
|
+
/** Primary exported symbols (functions, classes, constants) */
|
|
1185
|
+
mainExports: z12.array(z12.string()),
|
|
1186
|
+
/** Key import paths this file depends on */
|
|
1187
|
+
keyImports: z12.array(z12.string()),
|
|
1188
|
+
/** Logical ownership area (e.g. "auth", "api", "db", "frontend") */
|
|
1189
|
+
ownershipDomain: z12.string(),
|
|
1190
|
+
riskLevel: RiskLevelSchema,
|
|
1191
|
+
/** Paths of test files that cover this file */
|
|
1192
|
+
relatedTests: z12.array(z12.string()),
|
|
1193
|
+
/** SHA-256 or similar hash of the file content at last index time */
|
|
1194
|
+
summaryHash: z12.string(),
|
|
1195
|
+
/** ISO-8601 timestamp of the last indexing pass */
|
|
1196
|
+
lastIndexed: z12.string().datetime()
|
|
1197
|
+
});
|
|
1198
|
+
var FailureCategorySchema = z12.enum([
|
|
1199
|
+
"ts_type_drift",
|
|
1200
|
+
"import_path_mismatch",
|
|
1201
|
+
"route_not_registered",
|
|
1202
|
+
"env_var_absent",
|
|
1203
|
+
"schema_runtime_mismatch",
|
|
1204
|
+
"migration_missing",
|
|
1205
|
+
"circular_dependency",
|
|
1206
|
+
"stale_snapshot",
|
|
1207
|
+
"build_error",
|
|
1208
|
+
"test_error",
|
|
1209
|
+
"other"
|
|
1210
|
+
]);
|
|
1211
|
+
var FailureFingerprintSchema = z12.object({
|
|
1212
|
+
/** Short stable identifier (e.g. "ts_type_drift:UserSchema") */
|
|
1213
|
+
fingerprint: z12.string().min(1),
|
|
1214
|
+
category: FailureCategorySchema,
|
|
1215
|
+
/** Human-readable summary of what went wrong */
|
|
1216
|
+
description: z12.string(),
|
|
1217
|
+
/** Files involved in or triggering the failure */
|
|
1218
|
+
affectedFiles: z12.array(z12.string()),
|
|
1219
|
+
/** How many times this fingerprint has been seen */
|
|
1220
|
+
occurrenceCount: z12.number().int().nonnegative(),
|
|
1221
|
+
/** ISO-8601 timestamp of first occurrence */
|
|
1222
|
+
firstSeen: z12.string().datetime(),
|
|
1223
|
+
/** ISO-8601 timestamp of most recent occurrence */
|
|
1224
|
+
lastSeen: z12.string().datetime()
|
|
1225
|
+
});
|
|
1226
|
+
var TaskMemorySchema = z12.object({
|
|
1227
|
+
taskId: z12.string().min(1),
|
|
1228
|
+
goal: z12.string(),
|
|
1229
|
+
/** Normalised constraints carried into the task */
|
|
1230
|
+
normalizedConstraints: z12.array(z12.string()),
|
|
1231
|
+
/** Files that were read or modified during the task */
|
|
1232
|
+
filesTouched: z12.array(z12.string()),
|
|
1233
|
+
/** Summary of patches applied (not the full diff) */
|
|
1234
|
+
patchesApplied: z12.array(z12.string()),
|
|
1235
|
+
/** Final validation outcome ("pass" | "fail" | "partial") */
|
|
1236
|
+
validationOutcome: z12.enum(["pass", "fail", "partial"]),
|
|
1237
|
+
/** Human-readable reasons for any failures */
|
|
1238
|
+
failureReasons: z12.array(z12.string()),
|
|
1239
|
+
/** Follow-up tasks or open questions left behind */
|
|
1240
|
+
followUpTodos: z12.array(z12.string()),
|
|
1241
|
+
/**
|
|
1242
|
+
* Subjective quality score 0–100 assigned by the verifier
|
|
1243
|
+
* (100 = perfect, 0 = complete failure)
|
|
1244
|
+
*/
|
|
1245
|
+
qualityScore: z12.number().int().min(0).max(100),
|
|
1246
|
+
/** ISO-8601 timestamp when the task completed */
|
|
1247
|
+
completedAt: z12.string().datetime()
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
// packages/schemas/dist/backend.js
|
|
1251
|
+
import { z as z13 } from "zod";
|
|
1252
|
+
var MessageRoleSchema = z13.enum([
|
|
1253
|
+
"system",
|
|
1254
|
+
"user",
|
|
1255
|
+
"assistant",
|
|
1256
|
+
"tool"
|
|
1257
|
+
]);
|
|
1258
|
+
var ChatMessageSchema = z13.object({
|
|
1259
|
+
role: MessageRoleSchema,
|
|
1260
|
+
content: z13.string(),
|
|
1261
|
+
/** Tool call ID, required when role === "tool" */
|
|
1262
|
+
toolCallId: z13.string().optional(),
|
|
1263
|
+
/** Tool name, required when role === "tool" */
|
|
1264
|
+
name: z13.string().optional()
|
|
1265
|
+
});
|
|
1266
|
+
var CompletionRequestSchema = z13.object({
|
|
1267
|
+
messages: z13.array(ChatMessageSchema),
|
|
1268
|
+
/** Override the model used by the backend for this request */
|
|
1269
|
+
model: z13.string().optional(),
|
|
1270
|
+
maxTokens: z13.number().int().positive().optional(),
|
|
1271
|
+
temperature: z13.number().min(0).max(2).optional(),
|
|
1272
|
+
/** Request class for queue routing */
|
|
1273
|
+
queueClass: z13.string().optional(),
|
|
1274
|
+
/** Prefix hash for cache-aware routing */
|
|
1275
|
+
prefixHash: z13.string().optional(),
|
|
1276
|
+
stopSequences: z13.array(z13.string()).optional()
|
|
1277
|
+
});
|
|
1278
|
+
var TokenUsageSchema = z13.object({
|
|
1279
|
+
promptTokens: z13.number().int().nonnegative(),
|
|
1280
|
+
completionTokens: z13.number().int().nonnegative(),
|
|
1281
|
+
totalTokens: z13.number().int().nonnegative(),
|
|
1282
|
+
cacheCreationInputTokens: z13.number().int().nonnegative().optional(),
|
|
1283
|
+
cacheReadInputTokens: z13.number().int().nonnegative().optional(),
|
|
1284
|
+
promptEvalCount: z13.number().int().nonnegative().optional()
|
|
1285
|
+
});
|
|
1286
|
+
var CompletionResponseSchema = z13.object({
|
|
1287
|
+
content: z13.string(),
|
|
1288
|
+
usage: TokenUsageSchema.optional(),
|
|
1289
|
+
/** Which model actually served the request */
|
|
1290
|
+
model: z13.string().optional(),
|
|
1291
|
+
finishReason: z13.enum(["stop", "length", "tool_calls", "content_filter", "error"]).optional()
|
|
1292
|
+
});
|
|
1293
|
+
var StructuredCompletionRequestSchema = CompletionRequestSchema.extend({
|
|
1294
|
+
/**
|
|
1295
|
+
* The Zod schema used to constrain and validate the output.
|
|
1296
|
+
* Stored as unknown here because Zod schemas are not themselves
|
|
1297
|
+
* serialisable — callers pass the live schema object.
|
|
1298
|
+
*/
|
|
1299
|
+
outputSchema: z13.unknown(),
|
|
1300
|
+
/** Human-readable label used in prompt injection for the schema */
|
|
1301
|
+
schemaLabel: z13.string().optional()
|
|
1302
|
+
});
|
|
1303
|
+
var BackendHealthSchema = z13.object({
|
|
1304
|
+
status: z13.enum(["ok", "degraded", "down"]),
|
|
1305
|
+
latencyMs: z13.number().nonnegative().optional(),
|
|
1306
|
+
/** Fraction of GPU memory currently in use (0–1) */
|
|
1307
|
+
gpuMemoryUsed: z13.number().min(0).max(1).optional(),
|
|
1308
|
+
/** Fraction of KV cache currently in use (0–1) */
|
|
1309
|
+
kvCacheUsed: z13.number().min(0).max(1).optional(),
|
|
1310
|
+
/** Number of requests currently waiting in the queue */
|
|
1311
|
+
queueDepth: z13.number().int().nonnegative().optional(),
|
|
1312
|
+
/** Human-readable note about any degraded state */
|
|
1313
|
+
note: z13.string().optional()
|
|
1314
|
+
});
|
|
1315
|
+
var BackendMetricsSchema = z13.object({
|
|
1316
|
+
/** Total requests handled since startup */
|
|
1317
|
+
totalRequests: z13.number().int().nonnegative(),
|
|
1318
|
+
/** Requests that completed successfully */
|
|
1319
|
+
successfulRequests: z13.number().int().nonnegative(),
|
|
1320
|
+
/** Requests that failed */
|
|
1321
|
+
failedRequests: z13.number().int().nonnegative(),
|
|
1322
|
+
/** Average time-to-first-token across recent requests (ms) */
|
|
1323
|
+
avgTtftMs: z13.number().nonnegative().optional(),
|
|
1324
|
+
/** Average end-to-end latency across recent requests (ms) */
|
|
1325
|
+
avgLatencyMs: z13.number().nonnegative().optional(),
|
|
1326
|
+
/** Approximate prefix cache hit rate (0–1) */
|
|
1327
|
+
prefixCacheHitRate: z13.number().min(0).max(1).optional(),
|
|
1328
|
+
/** Number of sleep/wake cycles since startup */
|
|
1329
|
+
sleepWakeCycles: z13.number().int().nonnegative().optional(),
|
|
1330
|
+
/** Number of OOM / preemption / offload events */
|
|
1331
|
+
oomEvents: z13.number().int().nonnegative().optional(),
|
|
1332
|
+
/** ISO-8601 timestamp of when the backend service started */
|
|
1333
|
+
uptimeSince: z13.string().datetime().optional()
|
|
1334
|
+
});
|
|
1335
|
+
|
|
1336
|
+
// packages/schemas/dist/config.js
|
|
1337
|
+
import { z as z14 } from "zod";
|
|
1338
|
+
var AgentConfigSchema = z14.object({
|
|
1339
|
+
// -----------------------------------------------------------------------
|
|
1340
|
+
// Model / backend
|
|
1341
|
+
// -----------------------------------------------------------------------
|
|
1342
|
+
/** HuggingFace model ID, e.g. "Qwen/Qwen3.5-122B-A10B" */
|
|
1343
|
+
MODEL_ID: z14.string().min(1),
|
|
1344
|
+
/** Base URL of the primary vLLM OpenAI-compatible endpoint */
|
|
1345
|
+
VLLM_BASE_URL: z14.string().url(),
|
|
1346
|
+
/** API key sent to the vLLM service (often the literal string "EMPTY") */
|
|
1347
|
+
VLLM_API_KEY: z14.string().default("EMPTY"),
|
|
1348
|
+
// -----------------------------------------------------------------------
|
|
1349
|
+
// Context / memory tuning
|
|
1350
|
+
// -----------------------------------------------------------------------
|
|
1351
|
+
/**
|
|
1352
|
+
* Maximum context length for the model.
|
|
1353
|
+
* Should be discovered by startup probing rather than hard-coded.
|
|
1354
|
+
*/
|
|
1355
|
+
AGENT_MAX_MODEL_LEN: z14.string().transform((v) => parseInt(v, 10)).pipe(z14.number().int().positive()).default(65536),
|
|
1356
|
+
/** Enable vLLM automatic prefix caching (1 = enabled) */
|
|
1357
|
+
AGENT_ENABLE_PREFIX_CACHING: z14.string().transform((v) => v === "1" || v.toLowerCase() === "true").pipe(z14.boolean()).default(true),
|
|
1358
|
+
/** Enable vLLM sleep mode when idle (1 = enabled) */
|
|
1359
|
+
AGENT_ENABLE_SLEEP_MODE: z14.string().transform((v) => v === "1" || v.toLowerCase() === "true").pipe(z14.boolean()).default(true),
|
|
1360
|
+
// -----------------------------------------------------------------------
|
|
1361
|
+
// Agent behaviour
|
|
1362
|
+
// -----------------------------------------------------------------------
|
|
1363
|
+
/** Maximum retry cycles per subtask */
|
|
1364
|
+
AGENT_MAX_RETRIES: z14.string().transform((v) => parseInt(v, 10)).pipe(z14.number().int().nonnegative()).default(3),
|
|
1365
|
+
/** Maximum number of parallel subagents that may run simultaneously */
|
|
1366
|
+
AGENT_MAX_PARALLEL_SUBAGENTS: z14.string().transform((v) => parseInt(v, 10)).pipe(z14.number().int().positive()).default(4),
|
|
1367
|
+
// -----------------------------------------------------------------------
|
|
1368
|
+
// Retrieval limits
|
|
1369
|
+
// -----------------------------------------------------------------------
|
|
1370
|
+
/** Maximum files included in a single retrieval packet */
|
|
1371
|
+
AGENT_RETRIEVAL_MAX_FILES: z14.string().transform((v) => parseInt(v, 10)).pipe(z14.number().int().positive()).default(8),
|
|
1372
|
+
/** Maximum snippets included in a single retrieval packet */
|
|
1373
|
+
AGENT_RETRIEVAL_MAX_SNIPPETS: z14.string().transform((v) => parseInt(v, 10)).pipe(z14.number().int().positive()).default(16),
|
|
1374
|
+
// -----------------------------------------------------------------------
|
|
1375
|
+
// File paths
|
|
1376
|
+
// -----------------------------------------------------------------------
|
|
1377
|
+
/** Directory where agent working trees and artefacts are written */
|
|
1378
|
+
AGENT_WORK_ROOT: z14.string().min(1),
|
|
1379
|
+
/** Directory where the indexer stores its indexes and embeddings */
|
|
1380
|
+
AGENT_INDEX_ROOT: z14.string().min(1),
|
|
1381
|
+
// -----------------------------------------------------------------------
|
|
1382
|
+
// Optional models
|
|
1383
|
+
// -----------------------------------------------------------------------
|
|
1384
|
+
/** Model ID or endpoint for the embedding model (optional) */
|
|
1385
|
+
AGENT_EMBEDDING_MODEL: z14.string().optional(),
|
|
1386
|
+
/**
|
|
1387
|
+
* Optional smaller local model for triage/summarisation tasks.
|
|
1388
|
+
* When set, used in Profile C (hybrid mode).
|
|
1389
|
+
*/
|
|
1390
|
+
AGENT_SMALL_MODEL: z14.string().optional()
|
|
1391
|
+
});
|
|
1392
|
+
|
|
1393
|
+
// packages/schemas/dist/queue.js
|
|
1394
|
+
import { z as z15 } from "zod";
|
|
1395
|
+
var QueueClassSchema = z15.enum([
|
|
1396
|
+
/** CLI and direct user-facing requests; lowest latency target */
|
|
1397
|
+
"interactive-high",
|
|
1398
|
+
/** Planner role requests; moderate priority */
|
|
1399
|
+
"planner-medium",
|
|
1400
|
+
/** Editor role patch generation; high priority, may be long-running */
|
|
1401
|
+
"editor-high",
|
|
1402
|
+
/** Verifier role review; high priority, usually short */
|
|
1403
|
+
"verifier-high",
|
|
1404
|
+
/** Memory write-back and summarisation; background, low priority */
|
|
1405
|
+
"memory-low",
|
|
1406
|
+
/** Bulk indexing and embedding; lowest priority, best-effort */
|
|
1407
|
+
"batch-indexing-low"
|
|
1408
|
+
]);
|
|
1409
|
+
|
|
1410
|
+
// packages/schemas/dist/operational-world.js
|
|
1411
|
+
import { z as z16 } from "zod";
|
|
1412
|
+
var OPERATIONAL_WORLD_SCHEMA_VERSION = "omnius.operational-world.v1";
|
|
1413
|
+
var OperationalWorldSchemaVersionSchema = z16.literal(OPERATIONAL_WORLD_SCHEMA_VERSION);
|
|
1414
|
+
var OperationalWorldIdSchema = z16.string().trim().min(1).max(256);
|
|
1415
|
+
var OperationalWorldRevisionSchema = z16.string().trim().min(1).max(256);
|
|
1416
|
+
var ConfidenceSchema = z16.number().finite().min(0).max(1);
|
|
1417
|
+
var OperationalFactScopeSchema = z16.object({
|
|
1418
|
+
kind: z16.enum([
|
|
1419
|
+
"global",
|
|
1420
|
+
"run",
|
|
1421
|
+
"task",
|
|
1422
|
+
"session",
|
|
1423
|
+
"chat",
|
|
1424
|
+
"thread",
|
|
1425
|
+
"conversation",
|
|
1426
|
+
"legacy_unscoped"
|
|
1427
|
+
]),
|
|
1428
|
+
scopeId: OperationalWorldIdSchema,
|
|
1429
|
+
taskEpoch: z16.number().int().nonnegative().optional()
|
|
1430
|
+
}).strict();
|
|
1431
|
+
var OperationalMetadataDerivedFieldSchema = z16.enum([
|
|
1432
|
+
"source_evidence",
|
|
1433
|
+
"confidence",
|
|
1434
|
+
"revision",
|
|
1435
|
+
"temporal_validity",
|
|
1436
|
+
"scope",
|
|
1437
|
+
"metadata_provenance"
|
|
1438
|
+
]);
|
|
1439
|
+
var OperationalMetadataProvenanceSchema = z16.discriminatedUnion("kind", [
|
|
1440
|
+
z16.object({ kind: z16.literal("native") }).strict(),
|
|
1441
|
+
z16.object({
|
|
1442
|
+
kind: z16.literal("legacy_derived"),
|
|
1443
|
+
marker: z16.literal("metadata-only-no-semantic-assertion"),
|
|
1444
|
+
sourceRecordId: OperationalWorldIdSchema,
|
|
1445
|
+
derivedFields: z16.array(OperationalMetadataDerivedFieldSchema).min(1).max(6)
|
|
1446
|
+
}).strict()
|
|
1447
|
+
]);
|
|
1448
|
+
var JsonValueSchema = z16.lazy(() => z16.union([
|
|
1449
|
+
z16.string(),
|
|
1450
|
+
z16.number().finite(),
|
|
1451
|
+
z16.boolean(),
|
|
1452
|
+
z16.null(),
|
|
1453
|
+
z16.array(JsonValueSchema),
|
|
1454
|
+
z16.record(z16.string(), JsonValueSchema)
|
|
1455
|
+
]));
|
|
1456
|
+
var LineRangeLocatorSchema = z16.object({
|
|
1457
|
+
type: z16.literal("line_range"),
|
|
1458
|
+
startLine: z16.number().int().positive(),
|
|
1459
|
+
endLine: z16.number().int().positive()
|
|
1460
|
+
}).strict();
|
|
1461
|
+
var CharacterRangeLocatorSchema = z16.object({
|
|
1462
|
+
type: z16.literal("character_range"),
|
|
1463
|
+
startOffset: z16.number().int().nonnegative(),
|
|
1464
|
+
/** Exclusive end offset. */
|
|
1465
|
+
endOffset: z16.number().int().positive()
|
|
1466
|
+
}).strict();
|
|
1467
|
+
var PageRangeLocatorSchema = z16.object({
|
|
1468
|
+
type: z16.literal("page_range"),
|
|
1469
|
+
startPage: z16.number().int().positive(),
|
|
1470
|
+
endPage: z16.number().int().positive()
|
|
1471
|
+
}).strict();
|
|
1472
|
+
var SheetRangeLocatorSchema = z16.object({
|
|
1473
|
+
type: z16.literal("sheet_range"),
|
|
1474
|
+
sheetName: z16.string().trim().min(1).max(256),
|
|
1475
|
+
startRow: z16.number().int().positive().optional(),
|
|
1476
|
+
endRow: z16.number().int().positive().optional(),
|
|
1477
|
+
startColumn: z16.number().int().positive().optional(),
|
|
1478
|
+
endColumn: z16.number().int().positive().optional()
|
|
1479
|
+
}).strict();
|
|
1480
|
+
var TableRangeLocatorSchema = z16.object({
|
|
1481
|
+
type: z16.literal("table_range"),
|
|
1482
|
+
table: z16.string().trim().min(1).max(256),
|
|
1483
|
+
startRow: z16.number().int().nonnegative(),
|
|
1484
|
+
endRow: z16.number().int().nonnegative(),
|
|
1485
|
+
columns: z16.array(z16.string().trim().min(1).max(256)).max(128).optional()
|
|
1486
|
+
}).strict();
|
|
1487
|
+
var JsonPathLocatorSchema = z16.object({
|
|
1488
|
+
type: z16.literal("json_path"),
|
|
1489
|
+
path: z16.string().trim().min(1).max(2048)
|
|
1490
|
+
}).strict();
|
|
1491
|
+
var HeadingLocatorSchema = z16.object({
|
|
1492
|
+
type: z16.literal("heading"),
|
|
1493
|
+
heading: z16.string().trim().min(1).max(1024),
|
|
1494
|
+
occurrence: z16.number().int().positive().optional()
|
|
1495
|
+
}).strict();
|
|
1496
|
+
var FieldLocatorSchema = z16.object({
|
|
1497
|
+
type: z16.literal("field"),
|
|
1498
|
+
path: z16.array(z16.string().trim().min(1).max(256)).min(1).max(64),
|
|
1499
|
+
recordKey: z16.string().trim().min(1).max(512).optional()
|
|
1500
|
+
}).strict();
|
|
1501
|
+
var UriFragmentLocatorSchema = z16.object({
|
|
1502
|
+
type: z16.literal("uri_fragment"),
|
|
1503
|
+
fragment: z16.string().trim().min(1).max(2048)
|
|
1504
|
+
}).strict();
|
|
1505
|
+
var EvidenceLocatorSchema = z16.discriminatedUnion("type", [
|
|
1506
|
+
LineRangeLocatorSchema,
|
|
1507
|
+
CharacterRangeLocatorSchema,
|
|
1508
|
+
PageRangeLocatorSchema,
|
|
1509
|
+
SheetRangeLocatorSchema,
|
|
1510
|
+
TableRangeLocatorSchema,
|
|
1511
|
+
JsonPathLocatorSchema,
|
|
1512
|
+
HeadingLocatorSchema,
|
|
1513
|
+
FieldLocatorSchema,
|
|
1514
|
+
UriFragmentLocatorSchema
|
|
1515
|
+
]).superRefine((locator, ctx) => {
|
|
1516
|
+
if (locator.type === "line_range" && locator.endLine < locator.startLine) {
|
|
1517
|
+
ctx.addIssue({
|
|
1518
|
+
code: "custom",
|
|
1519
|
+
path: ["endLine"],
|
|
1520
|
+
message: "endLine must be greater than or equal to startLine"
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
if (locator.type === "character_range" && locator.endOffset <= locator.startOffset) {
|
|
1524
|
+
ctx.addIssue({
|
|
1525
|
+
code: "custom",
|
|
1526
|
+
path: ["endOffset"],
|
|
1527
|
+
message: "endOffset must be greater than startOffset"
|
|
1528
|
+
});
|
|
1529
|
+
}
|
|
1530
|
+
if (locator.type === "page_range" && locator.endPage < locator.startPage) {
|
|
1531
|
+
ctx.addIssue({
|
|
1532
|
+
code: "custom",
|
|
1533
|
+
path: ["endPage"],
|
|
1534
|
+
message: "endPage must be greater than or equal to startPage"
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
if (locator.type === "sheet_range") {
|
|
1538
|
+
if (locator.endRow !== void 0 && locator.startRow === void 0) {
|
|
1539
|
+
ctx.addIssue({
|
|
1540
|
+
code: "custom",
|
|
1541
|
+
path: ["startRow"],
|
|
1542
|
+
message: "startRow is required when endRow is present"
|
|
1543
|
+
});
|
|
1544
|
+
} else if (locator.startRow !== void 0 && locator.endRow !== void 0 && locator.endRow < locator.startRow) {
|
|
1545
|
+
ctx.addIssue({
|
|
1546
|
+
code: "custom",
|
|
1547
|
+
path: ["endRow"],
|
|
1548
|
+
message: "endRow must be greater than or equal to startRow"
|
|
1549
|
+
});
|
|
1550
|
+
}
|
|
1551
|
+
if (locator.endColumn !== void 0 && locator.startColumn === void 0) {
|
|
1552
|
+
ctx.addIssue({
|
|
1553
|
+
code: "custom",
|
|
1554
|
+
path: ["startColumn"],
|
|
1555
|
+
message: "startColumn is required when endColumn is present"
|
|
1556
|
+
});
|
|
1557
|
+
} else if (locator.startColumn !== void 0 && locator.endColumn !== void 0 && locator.endColumn < locator.startColumn) {
|
|
1558
|
+
ctx.addIssue({
|
|
1559
|
+
code: "custom",
|
|
1560
|
+
path: ["endColumn"],
|
|
1561
|
+
message: "endColumn must be greater than or equal to startColumn"
|
|
1562
|
+
});
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
if (locator.type === "table_range" && locator.endRow < locator.startRow) {
|
|
1566
|
+
ctx.addIssue({
|
|
1567
|
+
code: "custom",
|
|
1568
|
+
path: ["endRow"],
|
|
1569
|
+
message: "endRow must be greater than or equal to startRow"
|
|
1570
|
+
});
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
var SourceAuthoritySchema = z16.enum([
|
|
1574
|
+
"authoritative",
|
|
1575
|
+
"primary",
|
|
1576
|
+
"secondary",
|
|
1577
|
+
"derived",
|
|
1578
|
+
"unknown"
|
|
1579
|
+
]);
|
|
1580
|
+
var SourceFreshnessSchema = z16.enum(["fresh", "stale", "unknown"]);
|
|
1581
|
+
var SourceReadPolicySchema = z16.enum([
|
|
1582
|
+
"immutable",
|
|
1583
|
+
"snapshot",
|
|
1584
|
+
"refresh_before_use",
|
|
1585
|
+
"live"
|
|
1586
|
+
]);
|
|
1587
|
+
var SourceBindingSchema = z16.object({
|
|
1588
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
1589
|
+
bindingId: OperationalWorldIdSchema,
|
|
1590
|
+
sourceId: OperationalWorldIdSchema,
|
|
1591
|
+
/** URI, repo-relative path, or external source identifier. */
|
|
1592
|
+
sourceUri: z16.string().trim().min(1).max(4096),
|
|
1593
|
+
sourceRevision: OperationalWorldRevisionSchema,
|
|
1594
|
+
sourceHash: z16.string().trim().min(1).max(512).optional(),
|
|
1595
|
+
locator: EvidenceLocatorSchema,
|
|
1596
|
+
authority: SourceAuthoritySchema,
|
|
1597
|
+
freshness: SourceFreshnessSchema,
|
|
1598
|
+
readPolicy: SourceReadPolicySchema,
|
|
1599
|
+
observedAt: z16.string().datetime(),
|
|
1600
|
+
confidence: ConfidenceSchema,
|
|
1601
|
+
notes: z16.string().trim().max(2e3).optional()
|
|
1602
|
+
}).strict();
|
|
1603
|
+
var EvidenceRoleSchema = z16.enum([
|
|
1604
|
+
"supports",
|
|
1605
|
+
"refutes",
|
|
1606
|
+
"context",
|
|
1607
|
+
"verification",
|
|
1608
|
+
"blocker"
|
|
1609
|
+
]);
|
|
1610
|
+
var EvidenceRefSchema = z16.object({
|
|
1611
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
1612
|
+
evidenceId: OperationalWorldIdSchema,
|
|
1613
|
+
bindingId: OperationalWorldIdSchema,
|
|
1614
|
+
role: EvidenceRoleSchema,
|
|
1615
|
+
excerpt: z16.string().max(4e3).optional(),
|
|
1616
|
+
excerptHash: z16.string().trim().min(1).max(512).optional(),
|
|
1617
|
+
observedAt: z16.string().datetime(),
|
|
1618
|
+
confidence: ConfidenceSchema,
|
|
1619
|
+
tags: z16.array(z16.string().trim().min(1).max(128)).max(64)
|
|
1620
|
+
}).strict();
|
|
1621
|
+
var ClaimKindSchema = z16.enum([
|
|
1622
|
+
"fact",
|
|
1623
|
+
"inference",
|
|
1624
|
+
"requirement",
|
|
1625
|
+
"constraint",
|
|
1626
|
+
"outcome"
|
|
1627
|
+
]);
|
|
1628
|
+
var ClaimPolaritySchema = z16.enum(["positive", "negative"]);
|
|
1629
|
+
var ClaimStatusSchema = z16.enum([
|
|
1630
|
+
"proposed",
|
|
1631
|
+
"supported",
|
|
1632
|
+
"refuted",
|
|
1633
|
+
"contested",
|
|
1634
|
+
"unverified",
|
|
1635
|
+
"blocked"
|
|
1636
|
+
]);
|
|
1637
|
+
var WorkGraphNodeAuthoritySchema = z16.enum([
|
|
1638
|
+
"explicit",
|
|
1639
|
+
"inferred",
|
|
1640
|
+
"adopted"
|
|
1641
|
+
]);
|
|
1642
|
+
var ClaimSchema = z16.object({
|
|
1643
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
1644
|
+
claimId: OperationalWorldIdSchema,
|
|
1645
|
+
statement: z16.string().trim().min(1).max(4e3),
|
|
1646
|
+
kind: ClaimKindSchema,
|
|
1647
|
+
polarity: ClaimPolaritySchema,
|
|
1648
|
+
status: ClaimStatusSchema,
|
|
1649
|
+
confidence: ConfidenceSchema,
|
|
1650
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).max(256),
|
|
1651
|
+
dependsOnClaimIds: z16.array(OperationalWorldIdSchema).max(256),
|
|
1652
|
+
tags: z16.array(z16.string().trim().min(1).max(128)).max(64),
|
|
1653
|
+
/** Structured proposition fields used to group competing claims. */
|
|
1654
|
+
subjectNodeId: OperationalWorldIdSchema.optional(),
|
|
1655
|
+
predicate: z16.string().trim().min(1).max(512).optional(),
|
|
1656
|
+
objectValue: JsonValueSchema.optional(),
|
|
1657
|
+
validFrom: z16.string().datetime().optional(),
|
|
1658
|
+
validTo: z16.string().datetime().optional(),
|
|
1659
|
+
authority: WorkGraphNodeAuthoritySchema.optional()
|
|
1660
|
+
}).strict().superRefine((claim, ctx) => {
|
|
1661
|
+
if (claim.validFrom !== void 0 && claim.validTo !== void 0 && Date.parse(claim.validTo) < Date.parse(claim.validFrom)) {
|
|
1662
|
+
ctx.addIssue({
|
|
1663
|
+
code: "custom",
|
|
1664
|
+
path: ["validTo"],
|
|
1665
|
+
message: "validTo must not precede validFrom"
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1669
|
+
var ConflictKindSchema = z16.enum([
|
|
1670
|
+
"contradiction",
|
|
1671
|
+
"source_disagreement",
|
|
1672
|
+
"temporal",
|
|
1673
|
+
"schema",
|
|
1674
|
+
"authority"
|
|
1675
|
+
]);
|
|
1676
|
+
var ConflictStatusSchema = z16.enum([
|
|
1677
|
+
"open",
|
|
1678
|
+
"resolved",
|
|
1679
|
+
"accepted_uncertainty"
|
|
1680
|
+
]);
|
|
1681
|
+
var ConflictResolutionSchema = z16.object({
|
|
1682
|
+
decision: z16.string().trim().min(1).max(2e3),
|
|
1683
|
+
rationale: z16.string().trim().min(1).max(4e3),
|
|
1684
|
+
resolvedBy: z16.string().trim().min(1).max(256),
|
|
1685
|
+
resolvedAt: z16.string().datetime(),
|
|
1686
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).max(256)
|
|
1687
|
+
}).strict();
|
|
1688
|
+
var ConflictSchema = z16.object({
|
|
1689
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
1690
|
+
conflictId: OperationalWorldIdSchema,
|
|
1691
|
+
kind: ConflictKindSchema,
|
|
1692
|
+
summary: z16.string().trim().min(1).max(4e3),
|
|
1693
|
+
claimIds: z16.array(OperationalWorldIdSchema).min(2).max(64),
|
|
1694
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).max(256),
|
|
1695
|
+
status: ConflictStatusSchema,
|
|
1696
|
+
resolution: ConflictResolutionSchema.optional()
|
|
1697
|
+
}).strict().superRefine((conflict, ctx) => {
|
|
1698
|
+
if (new Set(conflict.claimIds).size !== conflict.claimIds.length) {
|
|
1699
|
+
ctx.addIssue({
|
|
1700
|
+
code: "custom",
|
|
1701
|
+
path: ["claimIds"],
|
|
1702
|
+
message: "claimIds must contain at least two distinct claims"
|
|
1703
|
+
});
|
|
1704
|
+
}
|
|
1705
|
+
if (conflict.status !== "open" && !conflict.resolution) {
|
|
1706
|
+
ctx.addIssue({
|
|
1707
|
+
code: "custom",
|
|
1708
|
+
path: ["resolution"],
|
|
1709
|
+
message: "a non-open conflict requires a resolution record"
|
|
1710
|
+
});
|
|
1711
|
+
}
|
|
1712
|
+
});
|
|
1713
|
+
var WorkGraphNodeKindSchema = z16.enum([
|
|
1714
|
+
"objective",
|
|
1715
|
+
"requirement",
|
|
1716
|
+
"document",
|
|
1717
|
+
"section",
|
|
1718
|
+
"task",
|
|
1719
|
+
"feature",
|
|
1720
|
+
"component",
|
|
1721
|
+
"module",
|
|
1722
|
+
"acceptance",
|
|
1723
|
+
"symbol",
|
|
1724
|
+
"entity",
|
|
1725
|
+
"event",
|
|
1726
|
+
"action",
|
|
1727
|
+
"mutation",
|
|
1728
|
+
"verification",
|
|
1729
|
+
"blocker",
|
|
1730
|
+
"policy",
|
|
1731
|
+
"artifact",
|
|
1732
|
+
"decision",
|
|
1733
|
+
"claim",
|
|
1734
|
+
"evidence",
|
|
1735
|
+
"conflict",
|
|
1736
|
+
"validation",
|
|
1737
|
+
"actor",
|
|
1738
|
+
"conversation",
|
|
1739
|
+
"relationship"
|
|
1740
|
+
]);
|
|
1741
|
+
var WorkGraphNodeStatusSchema = z16.enum([
|
|
1742
|
+
"proposed",
|
|
1743
|
+
"active",
|
|
1744
|
+
"blocked",
|
|
1745
|
+
"complete",
|
|
1746
|
+
"invalid",
|
|
1747
|
+
"superseded"
|
|
1748
|
+
]);
|
|
1749
|
+
var WorkGraphTargetRefSchema = z16.discriminatedUnion("type", [
|
|
1750
|
+
z16.object({ type: z16.literal("node"), nodeId: OperationalWorldIdSchema }).strict(),
|
|
1751
|
+
z16.object({ type: z16.literal("claim"), claimId: OperationalWorldIdSchema }).strict(),
|
|
1752
|
+
z16.object({
|
|
1753
|
+
type: z16.literal("conflict"),
|
|
1754
|
+
conflictId: OperationalWorldIdSchema
|
|
1755
|
+
}).strict(),
|
|
1756
|
+
z16.object({
|
|
1757
|
+
type: z16.literal("evidence"),
|
|
1758
|
+
evidenceId: OperationalWorldIdSchema
|
|
1759
|
+
}).strict(),
|
|
1760
|
+
z16.object({ type: z16.literal("source"), bindingId: OperationalWorldIdSchema }).strict(),
|
|
1761
|
+
z16.object({
|
|
1762
|
+
type: z16.literal("artifact"),
|
|
1763
|
+
uri: z16.string().trim().min(1).max(4096),
|
|
1764
|
+
revision: OperationalWorldRevisionSchema.optional()
|
|
1765
|
+
}).strict()
|
|
1766
|
+
]);
|
|
1767
|
+
var WorkActionPreconditionSchema = z16.object({
|
|
1768
|
+
preconditionId: OperationalWorldIdSchema,
|
|
1769
|
+
description: z16.string().trim().min(1).max(2e3),
|
|
1770
|
+
status: z16.enum(["unknown", "satisfied", "unsatisfied", "waived"]),
|
|
1771
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).max(256)
|
|
1772
|
+
}).strict();
|
|
1773
|
+
var WorkActionMutationSchema = z16.object({
|
|
1774
|
+
mutationId: OperationalWorldIdSchema,
|
|
1775
|
+
kind: z16.enum(["create", "update", "delete", "execute", "deliver"]),
|
|
1776
|
+
target: WorkGraphTargetRefSchema,
|
|
1777
|
+
description: z16.string().trim().min(1).max(2e3),
|
|
1778
|
+
reversible: z16.boolean()
|
|
1779
|
+
}).strict();
|
|
1780
|
+
var WorkActionApprovalSchema = z16.object({
|
|
1781
|
+
required: z16.boolean(),
|
|
1782
|
+
status: z16.enum(["not_required", "pending", "approved", "rejected"]),
|
|
1783
|
+
approvedBy: z16.string().trim().min(1).max(256).optional(),
|
|
1784
|
+
approvedAt: z16.string().datetime().optional()
|
|
1785
|
+
}).strict().superRefine((approval, ctx) => {
|
|
1786
|
+
if (!approval.required && approval.status !== "not_required") {
|
|
1787
|
+
ctx.addIssue({
|
|
1788
|
+
code: "custom",
|
|
1789
|
+
path: ["status"],
|
|
1790
|
+
message: "approval status must be not_required when approval is not required"
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
if (approval.required && approval.status === "not_required") {
|
|
1794
|
+
ctx.addIssue({
|
|
1795
|
+
code: "custom",
|
|
1796
|
+
path: ["status"],
|
|
1797
|
+
message: "required approval cannot have not_required status"
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
if (approval.status === "approved" && (!approval.approvedBy || !approval.approvedAt)) {
|
|
1801
|
+
ctx.addIssue({
|
|
1802
|
+
code: "custom",
|
|
1803
|
+
path: ["approvedBy"],
|
|
1804
|
+
message: "approved actions require approvedBy and approvedAt"
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
});
|
|
1808
|
+
var WorkActionContractSchema = z16.object({
|
|
1809
|
+
preconditions: z16.array(WorkActionPreconditionSchema).max(256),
|
|
1810
|
+
mutations: z16.array(WorkActionMutationSchema).max(256),
|
|
1811
|
+
sideEffects: z16.array(z16.string().trim().min(1).max(2e3)).max(256),
|
|
1812
|
+
approval: WorkActionApprovalSchema,
|
|
1813
|
+
authority: z16.enum([
|
|
1814
|
+
"operator_explicit",
|
|
1815
|
+
"delegated_scope",
|
|
1816
|
+
"policy",
|
|
1817
|
+
"none"
|
|
1818
|
+
]),
|
|
1819
|
+
risk: z16.enum(["none", "low", "medium", "high", "critical"])
|
|
1820
|
+
}).strict();
|
|
1821
|
+
var WorkGraphNodeReferenceSchema = z16.discriminatedUnion("type", [
|
|
1822
|
+
z16.object({ type: z16.literal("claim"), claimId: OperationalWorldIdSchema }).strict(),
|
|
1823
|
+
z16.object({
|
|
1824
|
+
type: z16.literal("conflict"),
|
|
1825
|
+
conflictId: OperationalWorldIdSchema
|
|
1826
|
+
}).strict(),
|
|
1827
|
+
z16.object({
|
|
1828
|
+
type: z16.literal("evidence"),
|
|
1829
|
+
evidenceId: OperationalWorldIdSchema
|
|
1830
|
+
}).strict(),
|
|
1831
|
+
z16.object({ type: z16.literal("source"), bindingId: OperationalWorldIdSchema }).strict()
|
|
1832
|
+
]);
|
|
1833
|
+
var WorkGraphNodeSchema = z16.object({
|
|
1834
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
1835
|
+
nodeId: OperationalWorldIdSchema,
|
|
1836
|
+
kind: WorkGraphNodeKindSchema,
|
|
1837
|
+
label: z16.string().trim().min(1).max(1e3),
|
|
1838
|
+
description: z16.string().trim().max(4e3).optional(),
|
|
1839
|
+
status: WorkGraphNodeStatusSchema,
|
|
1840
|
+
authority: WorkGraphNodeAuthoritySchema,
|
|
1841
|
+
parentNodeId: OperationalWorldIdSchema.optional(),
|
|
1842
|
+
bindingIds: z16.array(OperationalWorldIdSchema).min(1).max(256),
|
|
1843
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).min(1).max(256),
|
|
1844
|
+
confidence: ConfidenceSchema,
|
|
1845
|
+
revision: OperationalWorldRevisionSchema,
|
|
1846
|
+
validFrom: z16.string().datetime(),
|
|
1847
|
+
validTo: z16.string().datetime().optional(),
|
|
1848
|
+
scope: OperationalFactScopeSchema,
|
|
1849
|
+
taskEpoch: z16.number().int().nonnegative().optional(),
|
|
1850
|
+
metadataProvenance: OperationalMetadataProvenanceSchema,
|
|
1851
|
+
reference: WorkGraphNodeReferenceSchema.optional(),
|
|
1852
|
+
actionContract: WorkActionContractSchema.optional(),
|
|
1853
|
+
attributes: z16.record(z16.string(), JsonValueSchema)
|
|
1854
|
+
}).strict().superRefine((node, ctx) => {
|
|
1855
|
+
const expectedReference = node.kind === "claim" ? "claim" : node.kind === "conflict" ? "conflict" : node.kind === "evidence" ? "evidence" : null;
|
|
1856
|
+
if (expectedReference && node.reference?.type !== expectedReference) {
|
|
1857
|
+
ctx.addIssue({
|
|
1858
|
+
code: "custom",
|
|
1859
|
+
path: ["reference"],
|
|
1860
|
+
message: `${node.kind} nodes require a matching ${expectedReference} reference`
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
if (node.parentNodeId === node.nodeId) {
|
|
1864
|
+
ctx.addIssue({
|
|
1865
|
+
code: "custom",
|
|
1866
|
+
path: ["parentNodeId"],
|
|
1867
|
+
message: "a node cannot be its own parent"
|
|
1868
|
+
});
|
|
1869
|
+
}
|
|
1870
|
+
if ((node.kind === "action" || node.kind === "mutation") && !node.actionContract) {
|
|
1871
|
+
ctx.addIssue({
|
|
1872
|
+
code: "custom",
|
|
1873
|
+
path: ["actionContract"],
|
|
1874
|
+
message: `${node.kind} nodes require an action contract`
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
if (node.validFrom && node.validTo && Date.parse(node.validTo) < Date.parse(node.validFrom)) {
|
|
1878
|
+
ctx.addIssue({
|
|
1879
|
+
code: "custom",
|
|
1880
|
+
path: ["validTo"],
|
|
1881
|
+
message: "validTo must not precede validFrom"
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
if (node.scope?.taskEpoch !== void 0 && node.taskEpoch !== void 0 && node.scope.taskEpoch !== node.taskEpoch) {
|
|
1885
|
+
ctx.addIssue({
|
|
1886
|
+
code: "custom",
|
|
1887
|
+
path: ["taskEpoch"],
|
|
1888
|
+
message: "taskEpoch must match scope.taskEpoch"
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
});
|
|
1892
|
+
var WorkGraphEdgeKindSchema = z16.enum([
|
|
1893
|
+
"contains",
|
|
1894
|
+
"part_of",
|
|
1895
|
+
"decomposes_to",
|
|
1896
|
+
"depends_on",
|
|
1897
|
+
"satisfies",
|
|
1898
|
+
"produces",
|
|
1899
|
+
"supports",
|
|
1900
|
+
"refutes",
|
|
1901
|
+
"evidences",
|
|
1902
|
+
"verified_by",
|
|
1903
|
+
"evidenced_by",
|
|
1904
|
+
"contradicted_by",
|
|
1905
|
+
"blocked_by",
|
|
1906
|
+
"derived_from",
|
|
1907
|
+
"implements",
|
|
1908
|
+
"modifies",
|
|
1909
|
+
"validates",
|
|
1910
|
+
"conflicts_with",
|
|
1911
|
+
"supersedes",
|
|
1912
|
+
"mentions",
|
|
1913
|
+
"governs",
|
|
1914
|
+
"blocks",
|
|
1915
|
+
"assigned_to",
|
|
1916
|
+
"attempts",
|
|
1917
|
+
"invalidates",
|
|
1918
|
+
"resolves",
|
|
1919
|
+
"synthesizes",
|
|
1920
|
+
"replied_to",
|
|
1921
|
+
"reacted_to",
|
|
1922
|
+
"delivered_to",
|
|
1923
|
+
"owned_by",
|
|
1924
|
+
"relates_to"
|
|
1925
|
+
]);
|
|
1926
|
+
var WorkGraphEdgeSchema = z16.object({
|
|
1927
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
1928
|
+
edgeId: OperationalWorldIdSchema,
|
|
1929
|
+
sourceNodeId: OperationalWorldIdSchema,
|
|
1930
|
+
targetNodeId: OperationalWorldIdSchema,
|
|
1931
|
+
kind: WorkGraphEdgeKindSchema,
|
|
1932
|
+
directed: z16.boolean(),
|
|
1933
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).min(1).max(256),
|
|
1934
|
+
confidence: ConfidenceSchema,
|
|
1935
|
+
revision: OperationalWorldRevisionSchema,
|
|
1936
|
+
validFrom: z16.string().datetime(),
|
|
1937
|
+
validTo: z16.string().datetime().optional(),
|
|
1938
|
+
scope: OperationalFactScopeSchema,
|
|
1939
|
+
taskEpoch: z16.number().int().nonnegative().optional(),
|
|
1940
|
+
metadataProvenance: OperationalMetadataProvenanceSchema,
|
|
1941
|
+
attributes: z16.record(z16.string(), JsonValueSchema)
|
|
1942
|
+
}).strict().superRefine((edge, ctx) => {
|
|
1943
|
+
if (edge.sourceNodeId === edge.targetNodeId) {
|
|
1944
|
+
ctx.addIssue({
|
|
1945
|
+
code: "custom",
|
|
1946
|
+
path: ["targetNodeId"],
|
|
1947
|
+
message: "self-referential edges are not permitted"
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
if (edge.validFrom && edge.validTo && Date.parse(edge.validTo) < Date.parse(edge.validFrom)) {
|
|
1951
|
+
ctx.addIssue({
|
|
1952
|
+
code: "custom",
|
|
1953
|
+
path: ["validTo"],
|
|
1954
|
+
message: "validTo must not precede validFrom"
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
if (edge.scope?.taskEpoch !== void 0 && edge.taskEpoch !== void 0 && edge.scope.taskEpoch !== edge.taskEpoch) {
|
|
1958
|
+
ctx.addIssue({
|
|
1959
|
+
code: "custom",
|
|
1960
|
+
path: ["taskEpoch"],
|
|
1961
|
+
message: "taskEpoch must match scope.taskEpoch"
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
});
|
|
1965
|
+
function addDuplicateIdIssues(values, path2, ctx) {
|
|
1966
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1967
|
+
for (let index = 0; index < values.length; index++) {
|
|
1968
|
+
const value = values[index];
|
|
1969
|
+
if (seen.has(value)) {
|
|
1970
|
+
ctx.addIssue({
|
|
1971
|
+
code: "custom",
|
|
1972
|
+
path: [path2, index],
|
|
1973
|
+
message: `duplicate identifier: ${value}`
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
seen.add(value);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
function validateGraphCollections(value, ctx) {
|
|
1980
|
+
addDuplicateIdIssues(value.nodes.map((item) => item.nodeId), "nodes", ctx);
|
|
1981
|
+
addDuplicateIdIssues(value.edges.map((item) => item.edgeId), "edges", ctx);
|
|
1982
|
+
addDuplicateIdIssues(value.sourceBindings.map((item) => item.bindingId), "sourceBindings", ctx);
|
|
1983
|
+
addDuplicateIdIssues(value.evidenceRefs.map((item) => item.evidenceId), "evidenceRefs", ctx);
|
|
1984
|
+
addDuplicateIdIssues(value.claims.map((item) => item.claimId), "claims", ctx);
|
|
1985
|
+
addDuplicateIdIssues(value.conflicts.map((item) => item.conflictId), "conflicts", ctx);
|
|
1986
|
+
const nodeIds = new Set(value.nodes.map((item) => item.nodeId));
|
|
1987
|
+
const bindingIds = new Set(value.sourceBindings.map((item) => item.bindingId));
|
|
1988
|
+
const evidenceIds = new Set(value.evidenceRefs.map((item) => item.evidenceId));
|
|
1989
|
+
const claimIds = new Set(value.claims.map((item) => item.claimId));
|
|
1990
|
+
const conflictIds = new Set(value.conflicts.map((item) => item.conflictId));
|
|
1991
|
+
value.nodes.forEach((node, index) => {
|
|
1992
|
+
if (node.parentNodeId && !nodeIds.has(node.parentNodeId)) {
|
|
1993
|
+
ctx.addIssue({
|
|
1994
|
+
code: "custom",
|
|
1995
|
+
path: ["nodes", index, "parentNodeId"],
|
|
1996
|
+
message: `unknown parent node: ${node.parentNodeId}`
|
|
1997
|
+
});
|
|
1998
|
+
}
|
|
1999
|
+
node.bindingIds.forEach((id2) => {
|
|
2000
|
+
if (!bindingIds.has(id2)) {
|
|
2001
|
+
ctx.addIssue({
|
|
2002
|
+
code: "custom",
|
|
2003
|
+
path: ["nodes", index, "bindingIds"],
|
|
2004
|
+
message: `unknown source binding: ${id2}`
|
|
2005
|
+
});
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
node.evidenceRefIds.forEach((id2) => {
|
|
2009
|
+
if (!evidenceIds.has(id2)) {
|
|
2010
|
+
ctx.addIssue({
|
|
2011
|
+
code: "custom",
|
|
2012
|
+
path: ["nodes", index, "evidenceRefIds"],
|
|
2013
|
+
message: `unknown evidence reference: ${id2}`
|
|
2014
|
+
});
|
|
2015
|
+
}
|
|
2016
|
+
});
|
|
2017
|
+
if (node.reference?.type === "claim" && !claimIds.has(node.reference.claimId)) {
|
|
2018
|
+
ctx.addIssue({
|
|
2019
|
+
code: "custom",
|
|
2020
|
+
path: ["nodes", index, "reference", "claimId"],
|
|
2021
|
+
message: `unknown claim: ${node.reference.claimId}`
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
if (node.reference?.type === "conflict" && !conflictIds.has(node.reference.conflictId)) {
|
|
2025
|
+
ctx.addIssue({
|
|
2026
|
+
code: "custom",
|
|
2027
|
+
path: ["nodes", index, "reference", "conflictId"],
|
|
2028
|
+
message: `unknown conflict: ${node.reference.conflictId}`
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
if (node.reference?.type === "evidence" && !evidenceIds.has(node.reference.evidenceId)) {
|
|
2032
|
+
ctx.addIssue({
|
|
2033
|
+
code: "custom",
|
|
2034
|
+
path: ["nodes", index, "reference", "evidenceId"],
|
|
2035
|
+
message: `unknown evidence reference: ${node.reference.evidenceId}`
|
|
2036
|
+
});
|
|
2037
|
+
}
|
|
2038
|
+
if (node.reference?.type === "source" && !bindingIds.has(node.reference.bindingId)) {
|
|
2039
|
+
ctx.addIssue({
|
|
2040
|
+
code: "custom",
|
|
2041
|
+
path: ["nodes", index, "reference", "bindingId"],
|
|
2042
|
+
message: `unknown source binding: ${node.reference.bindingId}`
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
node.actionContract?.preconditions.forEach((precondition) => {
|
|
2046
|
+
precondition.evidenceRefIds.forEach((id2) => {
|
|
2047
|
+
if (!evidenceIds.has(id2)) {
|
|
2048
|
+
ctx.addIssue({
|
|
2049
|
+
code: "custom",
|
|
2050
|
+
path: ["nodes", index, "actionContract", "preconditions"],
|
|
2051
|
+
message: `unknown precondition evidence reference: ${id2}`
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
2054
|
+
});
|
|
2055
|
+
});
|
|
2056
|
+
node.actionContract?.mutations.forEach((mutation, mutationIndex) => {
|
|
2057
|
+
const target = mutation.target;
|
|
2058
|
+
const targetExists = target.type === "artifact" || target.type === "node" && nodeIds.has(target.nodeId) || target.type === "claim" && claimIds.has(target.claimId) || target.type === "conflict" && conflictIds.has(target.conflictId) || target.type === "evidence" && evidenceIds.has(target.evidenceId) || target.type === "source" && bindingIds.has(target.bindingId);
|
|
2059
|
+
if (!targetExists) {
|
|
2060
|
+
ctx.addIssue({
|
|
2061
|
+
code: "custom",
|
|
2062
|
+
path: [
|
|
2063
|
+
"nodes",
|
|
2064
|
+
index,
|
|
2065
|
+
"actionContract",
|
|
2066
|
+
"mutations",
|
|
2067
|
+
mutationIndex,
|
|
2068
|
+
"target"
|
|
2069
|
+
],
|
|
2070
|
+
message: "action mutation target is absent from the graph"
|
|
2071
|
+
});
|
|
2072
|
+
}
|
|
2073
|
+
});
|
|
2074
|
+
});
|
|
2075
|
+
value.edges.forEach((edge, index) => {
|
|
2076
|
+
if (!nodeIds.has(edge.sourceNodeId)) {
|
|
2077
|
+
ctx.addIssue({
|
|
2078
|
+
code: "custom",
|
|
2079
|
+
path: ["edges", index, "sourceNodeId"],
|
|
2080
|
+
message: `unknown source node: ${edge.sourceNodeId}`
|
|
2081
|
+
});
|
|
2082
|
+
}
|
|
2083
|
+
if (!nodeIds.has(edge.targetNodeId)) {
|
|
2084
|
+
ctx.addIssue({
|
|
2085
|
+
code: "custom",
|
|
2086
|
+
path: ["edges", index, "targetNodeId"],
|
|
2087
|
+
message: `unknown target node: ${edge.targetNodeId}`
|
|
2088
|
+
});
|
|
2089
|
+
}
|
|
2090
|
+
edge.evidenceRefIds.forEach((id2) => {
|
|
2091
|
+
if (!evidenceIds.has(id2)) {
|
|
2092
|
+
ctx.addIssue({
|
|
2093
|
+
code: "custom",
|
|
2094
|
+
path: ["edges", index, "evidenceRefIds"],
|
|
2095
|
+
message: `unknown evidence reference: ${id2}`
|
|
2096
|
+
});
|
|
2097
|
+
}
|
|
2098
|
+
});
|
|
2099
|
+
});
|
|
2100
|
+
value.evidenceRefs.forEach((evidence, index) => {
|
|
2101
|
+
if (!bindingIds.has(evidence.bindingId)) {
|
|
2102
|
+
ctx.addIssue({
|
|
2103
|
+
code: "custom",
|
|
2104
|
+
path: ["evidenceRefs", index, "bindingId"],
|
|
2105
|
+
message: `unknown source binding: ${evidence.bindingId}`
|
|
2106
|
+
});
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
value.claims.forEach((claim, index) => {
|
|
2110
|
+
if (claim.subjectNodeId && !nodeIds.has(claim.subjectNodeId)) {
|
|
2111
|
+
ctx.addIssue({
|
|
2112
|
+
code: "custom",
|
|
2113
|
+
path: ["claims", index, "subjectNodeId"],
|
|
2114
|
+
message: `unknown claim subject node: ${claim.subjectNodeId}`
|
|
2115
|
+
});
|
|
2116
|
+
}
|
|
2117
|
+
claim.evidenceRefIds.forEach((id2) => {
|
|
2118
|
+
if (!evidenceIds.has(id2)) {
|
|
2119
|
+
ctx.addIssue({
|
|
2120
|
+
code: "custom",
|
|
2121
|
+
path: ["claims", index, "evidenceRefIds"],
|
|
2122
|
+
message: `unknown evidence reference: ${id2}`
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
claim.dependsOnClaimIds.forEach((id2) => {
|
|
2127
|
+
if (!claimIds.has(id2)) {
|
|
2128
|
+
ctx.addIssue({
|
|
2129
|
+
code: "custom",
|
|
2130
|
+
path: ["claims", index, "dependsOnClaimIds"],
|
|
2131
|
+
message: `unknown claim dependency: ${id2}`
|
|
2132
|
+
});
|
|
2133
|
+
}
|
|
2134
|
+
});
|
|
2135
|
+
});
|
|
2136
|
+
value.conflicts.forEach((conflict, index) => {
|
|
2137
|
+
conflict.claimIds.forEach((id2) => {
|
|
2138
|
+
if (!claimIds.has(id2)) {
|
|
2139
|
+
ctx.addIssue({
|
|
2140
|
+
code: "custom",
|
|
2141
|
+
path: ["conflicts", index, "claimIds"],
|
|
2142
|
+
message: `unknown conflict claim: ${id2}`
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
});
|
|
2146
|
+
conflict.evidenceRefIds.forEach((id2) => {
|
|
2147
|
+
if (!evidenceIds.has(id2)) {
|
|
2148
|
+
ctx.addIssue({
|
|
2149
|
+
code: "custom",
|
|
2150
|
+
path: ["conflicts", index, "evidenceRefIds"],
|
|
2151
|
+
message: `unknown evidence reference: ${id2}`
|
|
2152
|
+
});
|
|
2153
|
+
}
|
|
2154
|
+
});
|
|
2155
|
+
conflict.resolution?.evidenceRefIds.forEach((id2) => {
|
|
2156
|
+
if (!evidenceIds.has(id2)) {
|
|
2157
|
+
ctx.addIssue({
|
|
2158
|
+
code: "custom",
|
|
2159
|
+
path: ["conflicts", index, "resolution", "evidenceRefIds"],
|
|
2160
|
+
message: `unknown resolution evidence reference: ${id2}`
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
});
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
var WorkGraphSchema = z16.object({
|
|
2167
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
2168
|
+
graphId: OperationalWorldIdSchema,
|
|
2169
|
+
revision: OperationalWorldRevisionSchema,
|
|
2170
|
+
previousRevision: OperationalWorldRevisionSchema.optional(),
|
|
2171
|
+
title: z16.string().trim().min(1).max(1e3),
|
|
2172
|
+
nodes: z16.array(WorkGraphNodeSchema).max(1e5),
|
|
2173
|
+
edges: z16.array(WorkGraphEdgeSchema).max(25e4),
|
|
2174
|
+
sourceBindings: z16.array(SourceBindingSchema).max(1e5),
|
|
2175
|
+
evidenceRefs: z16.array(EvidenceRefSchema).max(25e4),
|
|
2176
|
+
claims: z16.array(ClaimSchema).max(1e5),
|
|
2177
|
+
conflicts: z16.array(ConflictSchema).max(1e5),
|
|
2178
|
+
createdAt: z16.string().datetime(),
|
|
2179
|
+
updatedAt: z16.string().datetime()
|
|
2180
|
+
}).strict().superRefine(validateGraphCollections);
|
|
2181
|
+
var WorldPatchOperationSchema = z16.discriminatedUnion("op", [
|
|
2182
|
+
z16.object({ op: z16.literal("upsert_node"), node: WorkGraphNodeSchema }).strict(),
|
|
2183
|
+
z16.object({
|
|
2184
|
+
op: z16.literal("remove_node"),
|
|
2185
|
+
nodeId: OperationalWorldIdSchema,
|
|
2186
|
+
cascade: z16.boolean()
|
|
2187
|
+
}).strict(),
|
|
2188
|
+
z16.object({ op: z16.literal("upsert_edge"), edge: WorkGraphEdgeSchema }).strict(),
|
|
2189
|
+
z16.object({ op: z16.literal("remove_edge"), edgeId: OperationalWorldIdSchema }).strict(),
|
|
2190
|
+
z16.object({
|
|
2191
|
+
op: z16.literal("upsert_source_binding"),
|
|
2192
|
+
sourceBinding: SourceBindingSchema
|
|
2193
|
+
}).strict(),
|
|
2194
|
+
z16.object({
|
|
2195
|
+
op: z16.literal("remove_source_binding"),
|
|
2196
|
+
bindingId: OperationalWorldIdSchema
|
|
2197
|
+
}).strict(),
|
|
2198
|
+
z16.object({
|
|
2199
|
+
op: z16.literal("upsert_evidence_ref"),
|
|
2200
|
+
evidenceRef: EvidenceRefSchema
|
|
2201
|
+
}).strict(),
|
|
2202
|
+
z16.object({
|
|
2203
|
+
op: z16.literal("remove_evidence_ref"),
|
|
2204
|
+
evidenceId: OperationalWorldIdSchema
|
|
2205
|
+
}).strict(),
|
|
2206
|
+
z16.object({ op: z16.literal("upsert_claim"), claim: ClaimSchema }).strict(),
|
|
2207
|
+
z16.object({
|
|
2208
|
+
op: z16.literal("remove_claim"),
|
|
2209
|
+
claimId: OperationalWorldIdSchema
|
|
2210
|
+
}).strict(),
|
|
2211
|
+
z16.object({ op: z16.literal("upsert_conflict"), conflict: ConflictSchema }).strict(),
|
|
2212
|
+
z16.object({
|
|
2213
|
+
op: z16.literal("remove_conflict"),
|
|
2214
|
+
conflictId: OperationalWorldIdSchema
|
|
2215
|
+
}).strict()
|
|
2216
|
+
]);
|
|
2217
|
+
var WorldPatchSchema = z16.object({
|
|
2218
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
2219
|
+
patchId: OperationalWorldIdSchema,
|
|
2220
|
+
graphId: OperationalWorldIdSchema,
|
|
2221
|
+
/** Optimistic-concurrency precondition. */
|
|
2222
|
+
baseRevision: OperationalWorldRevisionSchema,
|
|
2223
|
+
targetRevision: OperationalWorldRevisionSchema,
|
|
2224
|
+
operations: z16.array(WorldPatchOperationSchema).min(1).max(1e4),
|
|
2225
|
+
rationale: z16.string().trim().min(1).max(4e3),
|
|
2226
|
+
createdBy: z16.string().trim().min(1).max(256),
|
|
2227
|
+
createdAt: z16.string().datetime()
|
|
2228
|
+
}).strict().superRefine((patch, ctx) => {
|
|
2229
|
+
if (patch.baseRevision === patch.targetRevision) {
|
|
2230
|
+
ctx.addIssue({
|
|
2231
|
+
code: "custom",
|
|
2232
|
+
path: ["targetRevision"],
|
|
2233
|
+
message: "targetRevision must differ from baseRevision"
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2237
|
+
var ValidationIssueSeveritySchema = z16.enum([
|
|
2238
|
+
"info",
|
|
2239
|
+
"warning",
|
|
2240
|
+
"error"
|
|
2241
|
+
]);
|
|
2242
|
+
var OperationalValidationIssueSchema = z16.object({
|
|
2243
|
+
code: z16.string().trim().min(1).max(128),
|
|
2244
|
+
severity: ValidationIssueSeveritySchema,
|
|
2245
|
+
message: z16.string().trim().min(1).max(4e3),
|
|
2246
|
+
path: z16.array(z16.union([z16.string(), z16.number().int().nonnegative()])).max(64),
|
|
2247
|
+
nodeId: OperationalWorldIdSchema.optional(),
|
|
2248
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).max(256)
|
|
2249
|
+
}).strict();
|
|
2250
|
+
var OperationalValidationStatusSchema = z16.enum([
|
|
2251
|
+
"pass",
|
|
2252
|
+
"fail",
|
|
2253
|
+
"partial"
|
|
2254
|
+
]);
|
|
2255
|
+
var OperationalValidationResultSchema = z16.object({
|
|
2256
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
2257
|
+
valid: z16.boolean(),
|
|
2258
|
+
status: OperationalValidationStatusSchema,
|
|
2259
|
+
checkedRevision: OperationalWorldRevisionSchema,
|
|
2260
|
+
issues: z16.array(OperationalValidationIssueSchema).max(1e4),
|
|
2261
|
+
checkedAt: z16.string().datetime()
|
|
2262
|
+
}).strict().superRefine((result, ctx) => {
|
|
2263
|
+
const hasErrors = result.issues.some((issue) => issue.severity === "error");
|
|
2264
|
+
if (result.valid !== (result.status === "pass")) {
|
|
2265
|
+
ctx.addIssue({
|
|
2266
|
+
code: "custom",
|
|
2267
|
+
path: ["valid"],
|
|
2268
|
+
message: "valid must be true exactly when status is pass"
|
|
2269
|
+
});
|
|
2270
|
+
}
|
|
2271
|
+
if (result.status === "pass" && hasErrors) {
|
|
2272
|
+
ctx.addIssue({
|
|
2273
|
+
code: "custom",
|
|
2274
|
+
path: ["issues"],
|
|
2275
|
+
message: "a passing result cannot contain error issues"
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
if (result.status === "fail" && !hasErrors) {
|
|
2279
|
+
ctx.addIssue({
|
|
2280
|
+
code: "custom",
|
|
2281
|
+
path: ["issues"],
|
|
2282
|
+
message: "a failing result must contain at least one error issue"
|
|
2283
|
+
});
|
|
2284
|
+
}
|
|
2285
|
+
});
|
|
2286
|
+
var ValidationArtifactHashSchema = z16.object({
|
|
2287
|
+
uri: z16.string().trim().min(1).max(4096),
|
|
2288
|
+
algorithm: z16.enum(["sha256", "sha512", "blake3"]),
|
|
2289
|
+
digest: z16.string().trim().min(1).max(512)
|
|
2290
|
+
}).strict();
|
|
2291
|
+
var OperationalValidationReceiptSchema = z16.object({
|
|
2292
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
2293
|
+
receiptId: OperationalWorldIdSchema,
|
|
2294
|
+
graphId: OperationalWorldIdSchema,
|
|
2295
|
+
patchId: OperationalWorldIdSchema.optional(),
|
|
2296
|
+
baseRevision: OperationalWorldRevisionSchema,
|
|
2297
|
+
resultRevision: OperationalWorldRevisionSchema,
|
|
2298
|
+
validator: z16.object({
|
|
2299
|
+
name: z16.string().trim().min(1).max(256),
|
|
2300
|
+
version: z16.string().trim().min(1).max(128)
|
|
2301
|
+
}).strict(),
|
|
2302
|
+
startedAt: z16.string().datetime(),
|
|
2303
|
+
finishedAt: z16.string().datetime(),
|
|
2304
|
+
result: OperationalValidationResultSchema,
|
|
2305
|
+
evidenceRefIds: z16.array(OperationalWorldIdSchema).max(1e4),
|
|
2306
|
+
artifactHashes: z16.array(ValidationArtifactHashSchema).max(1e4)
|
|
2307
|
+
}).strict().superRefine((receipt, ctx) => {
|
|
2308
|
+
if (receipt.result.checkedRevision !== receipt.resultRevision) {
|
|
2309
|
+
ctx.addIssue({
|
|
2310
|
+
code: "custom",
|
|
2311
|
+
path: ["result", "checkedRevision"],
|
|
2312
|
+
message: "checkedRevision must equal resultRevision"
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
if (Date.parse(receipt.finishedAt) < Date.parse(receipt.startedAt)) {
|
|
2316
|
+
ctx.addIssue({
|
|
2317
|
+
code: "custom",
|
|
2318
|
+
path: ["finishedAt"],
|
|
2319
|
+
message: "finishedAt must not precede startedAt"
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
});
|
|
2323
|
+
var ReasoningSliceSelectionSchema = z16.object({
|
|
2324
|
+
strategy: z16.enum(["exact", "lexical", "semantic", "graph", "hybrid"]),
|
|
2325
|
+
graphHops: z16.number().int().nonnegative().max(32),
|
|
2326
|
+
maxCharacters: z16.number().int().positive(),
|
|
2327
|
+
truncated: z16.boolean(),
|
|
2328
|
+
omissions: z16.array(z16.string().trim().min(1).max(1e3)).max(256),
|
|
2329
|
+
evidenceRoles: z16.array(EvidenceRoleSchema).max(5)
|
|
2330
|
+
}).strict();
|
|
2331
|
+
var ReasoningSliceSchema = z16.object({
|
|
2332
|
+
schemaVersion: OperationalWorldSchemaVersionSchema,
|
|
2333
|
+
sliceId: OperationalWorldIdSchema,
|
|
2334
|
+
graphId: OperationalWorldIdSchema,
|
|
2335
|
+
revision: OperationalWorldRevisionSchema,
|
|
2336
|
+
objective: z16.string().trim().min(1).max(4e3),
|
|
2337
|
+
focusNodeIds: z16.array(OperationalWorldIdSchema).min(1).max(256),
|
|
2338
|
+
nodes: z16.array(WorkGraphNodeSchema).max(1e4),
|
|
2339
|
+
edges: z16.array(WorkGraphEdgeSchema).max(25e3),
|
|
2340
|
+
sourceBindings: z16.array(SourceBindingSchema).max(1e4),
|
|
2341
|
+
evidenceRefs: z16.array(EvidenceRefSchema).max(25e3),
|
|
2342
|
+
claims: z16.array(ClaimSchema).max(1e4),
|
|
2343
|
+
conflicts: z16.array(ConflictSchema).max(1e4),
|
|
2344
|
+
selection: ReasoningSliceSelectionSchema,
|
|
2345
|
+
generatedAt: z16.string().datetime()
|
|
2346
|
+
}).strict().superRefine((slice, ctx) => {
|
|
2347
|
+
validateGraphCollections(slice, ctx);
|
|
2348
|
+
const nodeIds = new Set(slice.nodes.map((node) => node.nodeId));
|
|
2349
|
+
slice.focusNodeIds.forEach((nodeId, index) => {
|
|
2350
|
+
if (!nodeIds.has(nodeId)) {
|
|
2351
|
+
ctx.addIssue({
|
|
2352
|
+
code: "custom",
|
|
2353
|
+
path: ["focusNodeIds", index],
|
|
2354
|
+
message: `focus node is absent from the reasoning slice: ${nodeId}`
|
|
2355
|
+
});
|
|
2356
|
+
}
|
|
2357
|
+
});
|
|
2358
|
+
});
|
|
2359
|
+
|
|
629
2360
|
// packages/memory/dist/episodeStore.js
|
|
630
2361
|
import { join } from "node:path";
|
|
631
2362
|
import { mkdirSync, existsSync } from "node:fs";
|
|
@@ -928,12 +2659,12 @@ var DEFAULT_CONFIG2 = {
|
|
|
928
2659
|
function extractQueryEntities(query) {
|
|
929
2660
|
const entities = [];
|
|
930
2661
|
const seen = /* @__PURE__ */ new Set();
|
|
931
|
-
const add = (
|
|
932
|
-
const normalized =
|
|
2662
|
+
const add = (text2) => {
|
|
2663
|
+
const normalized = text2.trim().toLowerCase();
|
|
933
2664
|
if (normalized.length < 2 || seen.has(normalized))
|
|
934
2665
|
return;
|
|
935
2666
|
seen.add(normalized);
|
|
936
|
-
entities.push(
|
|
2667
|
+
entities.push(text2.trim());
|
|
937
2668
|
};
|
|
938
2669
|
const filePattern = /(?:[\w./-]+\/[\w./-]+|[\w-]+\.\w{1,5})\b/g;
|
|
939
2670
|
for (const match of query.matchAll(filePattern)) {
|
|
@@ -1046,8 +2777,8 @@ function personalizedPageRank(graph, seedNodeIds, config) {
|
|
|
1046
2777
|
if (delta > maxDelta)
|
|
1047
2778
|
maxDelta = delta;
|
|
1048
2779
|
}
|
|
1049
|
-
for (const [
|
|
1050
|
-
scores.set(
|
|
2780
|
+
for (const [id2, score] of newScores)
|
|
2781
|
+
scores.set(id2, score);
|
|
1051
2782
|
if (maxDelta < cfg.convergenceThreshold) {
|
|
1052
2783
|
return scores;
|
|
1053
2784
|
}
|
|
@@ -1300,13 +3031,13 @@ var EpisodeStore = class {
|
|
|
1300
3031
|
* orchestrator when an episode that was retrieved is detected to have
|
|
1301
3032
|
* been mentioned in a subsequent assistant turn. Idempotent on missing
|
|
1302
3033
|
* ids (no row → no-op). Returns the new count, or null if not found. */
|
|
1303
|
-
bumpReuseCount(
|
|
3034
|
+
bumpReuseCount(id2, delta = 1) {
|
|
1304
3035
|
const safeDelta = Number.isFinite(delta) ? delta : 1;
|
|
1305
3036
|
try {
|
|
1306
|
-
const result = this.db.prepare(`UPDATE episodes SET reuse_count = COALESCE(reuse_count, 0) + ? WHERE id = ?`).run(safeDelta,
|
|
3037
|
+
const result = this.db.prepare(`UPDATE episodes SET reuse_count = COALESCE(reuse_count, 0) + ? WHERE id = ?`).run(safeDelta, id2);
|
|
1307
3038
|
if (result.changes === 0)
|
|
1308
3039
|
return null;
|
|
1309
|
-
const row = this.db.prepare(`SELECT reuse_count FROM episodes WHERE id = ?`).get(
|
|
3040
|
+
const row = this.db.prepare(`SELECT reuse_count FROM episodes WHERE id = ?`).get(id2);
|
|
1310
3041
|
return row?.reuse_count ?? null;
|
|
1311
3042
|
} catch {
|
|
1312
3043
|
return null;
|
|
@@ -1372,7 +3103,7 @@ var EpisodeStore = class {
|
|
|
1372
3103
|
}
|
|
1373
3104
|
/** Insert a new episode. Returns the episode ID. */
|
|
1374
3105
|
insert(ep) {
|
|
1375
|
-
const
|
|
3106
|
+
const id2 = randomUUID();
|
|
1376
3107
|
const now = Date.now();
|
|
1377
3108
|
const contentHash = episodeIdentityHash(ep);
|
|
1378
3109
|
const modality = ep.modality ?? "text";
|
|
@@ -1393,17 +3124,17 @@ var EpisodeStore = class {
|
|
|
1393
3124
|
this.db.prepare(`
|
|
1394
3125
|
INSERT INTO episodes (id, timestamp, session_id, task_id, turn_number, modality, tool_name, content, content_hash, metadata, importance, decay_class, strength)
|
|
1395
3126
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1.0)
|
|
1396
|
-
`).run(
|
|
3127
|
+
`).run(id2, now, ep.sessionId ?? null, ep.taskId ?? null, ep.turnNumber ?? null, modality, ep.toolName ?? null, ep.content, contentHash, ep.metadata ? JSON.stringify(ep.metadata) : null, importance, decayClass);
|
|
1397
3128
|
if (this.graph) {
|
|
1398
3129
|
try {
|
|
1399
|
-
const episode = this.get(
|
|
3130
|
+
const episode = this.get(id2);
|
|
1400
3131
|
if (episode) {
|
|
1401
3132
|
linkEpisode(episode, this, this.graph, this.zettelConfig);
|
|
1402
3133
|
}
|
|
1403
3134
|
} catch {
|
|
1404
3135
|
}
|
|
1405
3136
|
}
|
|
1406
|
-
return
|
|
3137
|
+
return id2;
|
|
1407
3138
|
}
|
|
1408
3139
|
/** Retrieve episodes matching a query, scored by recency + importance + (lexical + embedding). */
|
|
1409
3140
|
search(query, opts = {}) {
|
|
@@ -1637,8 +3368,8 @@ var EpisodeStore = class {
|
|
|
1637
3368
|
updateAll();
|
|
1638
3369
|
}
|
|
1639
3370
|
/** Get a single episode by ID. */
|
|
1640
|
-
get(
|
|
1641
|
-
const row = this.db.prepare("SELECT * FROM episodes WHERE id = ?").get(
|
|
3371
|
+
get(id2) {
|
|
3372
|
+
const row = this.db.prepare("SELECT * FROM episodes WHERE id = ?").get(id2);
|
|
1642
3373
|
return row ? this.rowToEpisode(row) : null;
|
|
1643
3374
|
}
|
|
1644
3375
|
/** Get recent episodes (for context assembly). */
|
|
@@ -1667,18 +3398,18 @@ var EpisodeStore = class {
|
|
|
1667
3398
|
return result.changes;
|
|
1668
3399
|
}
|
|
1669
3400
|
/** Update embedding for an episode (async fill from WO-AM-10). */
|
|
1670
|
-
setEmbedding(
|
|
3401
|
+
setEmbedding(id2, embedding) {
|
|
1671
3402
|
const buf = Buffer.from(embedding.buffer);
|
|
1672
|
-
this.db.prepare("UPDATE episodes SET embedding = ? WHERE id = ?").run(buf,
|
|
3403
|
+
this.db.prepare("UPDATE episodes SET embedding = ? WHERE id = ?").run(buf, id2);
|
|
1673
3404
|
}
|
|
1674
3405
|
/** WO-AM-GAP-03: Set CLIP embedding for cross-modal retrieval (512d). */
|
|
1675
|
-
setClipEmbedding(
|
|
3406
|
+
setClipEmbedding(id2, clipEmbedding) {
|
|
1676
3407
|
const buf = Buffer.from(clipEmbedding.buffer);
|
|
1677
|
-
this.db.prepare("UPDATE episodes SET clip_embedding = ? WHERE id = ?").run(buf,
|
|
3408
|
+
this.db.prepare("UPDATE episodes SET clip_embedding = ? WHERE id = ?").run(buf, id2);
|
|
1678
3409
|
}
|
|
1679
3410
|
/** Update gist for an episode (from WO-AM-07 gist compression). */
|
|
1680
|
-
setGist(
|
|
1681
|
-
this.db.prepare("UPDATE episodes SET gist = ? WHERE id = ?").run(gist,
|
|
3411
|
+
setGist(id2, gist) {
|
|
3412
|
+
this.db.prepare("UPDATE episodes SET gist = ? WHERE id = ?").run(gist, id2);
|
|
1682
3413
|
}
|
|
1683
3414
|
/** Close the database connection. */
|
|
1684
3415
|
close() {
|
|
@@ -2003,12 +3734,12 @@ var CRLParser = class {
|
|
|
2003
3734
|
return props;
|
|
2004
3735
|
}
|
|
2005
3736
|
parseIdentifier() {
|
|
2006
|
-
let
|
|
3737
|
+
let id2 = "";
|
|
2007
3738
|
while (this.pos < this.input.length && /[a-zA-Z0-9_]/.test(this.peek())) {
|
|
2008
|
-
|
|
3739
|
+
id2 += this.peek();
|
|
2009
3740
|
this.pos++;
|
|
2010
3741
|
}
|
|
2011
|
-
return
|
|
3742
|
+
return id2;
|
|
2012
3743
|
}
|
|
2013
3744
|
parseTemplate() {
|
|
2014
3745
|
const start = this.pos;
|
|
@@ -2180,8 +3911,8 @@ var CRLEncoder = class {
|
|
|
2180
3911
|
/**
|
|
2181
3912
|
* Encode natural language text to CRL
|
|
2182
3913
|
*/
|
|
2183
|
-
encode(
|
|
2184
|
-
let result = this.compress(
|
|
3914
|
+
encode(text2) {
|
|
3915
|
+
let result = this.compress(text2);
|
|
2185
3916
|
const concepts = this.extractConcepts(result);
|
|
2186
3917
|
const relations = this.extractRelations(result, concepts);
|
|
2187
3918
|
if (relations.length > 0) {
|
|
@@ -2192,11 +3923,11 @@ var CRLEncoder = class {
|
|
|
2192
3923
|
/**
|
|
2193
3924
|
* Extract key concepts from text
|
|
2194
3925
|
*/
|
|
2195
|
-
extractConcepts(
|
|
3926
|
+
extractConcepts(text2) {
|
|
2196
3927
|
const concepts = [];
|
|
2197
3928
|
const conceptPattern = /\[([^\]]+)\]/g;
|
|
2198
3929
|
let match;
|
|
2199
|
-
while ((match = conceptPattern.exec(
|
|
3930
|
+
while ((match = conceptPattern.exec(text2)) !== null) {
|
|
2200
3931
|
concepts.push({
|
|
2201
3932
|
type: "concept",
|
|
2202
3933
|
name: match[1],
|
|
@@ -2205,7 +3936,7 @@ var CRLEncoder = class {
|
|
|
2205
3936
|
});
|
|
2206
3937
|
}
|
|
2207
3938
|
const implicitPattern = /\b([A-Z][a-z]+(?:_[A-Z][a-z]+)*)\b/g;
|
|
2208
|
-
while ((match = implicitPattern.exec(
|
|
3939
|
+
while ((match = implicitPattern.exec(text2)) !== null) {
|
|
2209
3940
|
if (!concepts.find((c) => c.name === match[1])) {
|
|
2210
3941
|
concepts.push({
|
|
2211
3942
|
type: "concept",
|
|
@@ -2220,11 +3951,11 @@ var CRLEncoder = class {
|
|
|
2220
3951
|
/**
|
|
2221
3952
|
* Extract relations between concepts
|
|
2222
3953
|
*/
|
|
2223
|
-
extractRelations(
|
|
3954
|
+
extractRelations(text2, concepts) {
|
|
2224
3955
|
const relations = [];
|
|
2225
3956
|
const relationPattern = /\[([^\]]+)\]\s*(→|↔|∴|∵|⇒|⇐)(?::(\w+))?\s*(?:→)?\s*\[([^\]]+)\]/g;
|
|
2226
3957
|
let match;
|
|
2227
|
-
while ((match = relationPattern.exec(
|
|
3958
|
+
while ((match = relationPattern.exec(text2)) !== null) {
|
|
2228
3959
|
const from = concepts.find((c) => c.name === match[1]);
|
|
2229
3960
|
const to = concepts.find((c) => c.name === match[4]);
|
|
2230
3961
|
if (from && to) {
|
|
@@ -2268,7 +3999,7 @@ var CRLEncoder = class {
|
|
|
2268
3999
|
/**
|
|
2269
4000
|
* Compress text using CRL patterns
|
|
2270
4001
|
*/
|
|
2271
|
-
compress(
|
|
4002
|
+
compress(text2) {
|
|
2272
4003
|
const replacements = [
|
|
2273
4004
|
[/therefore/gi, "∴"],
|
|
2274
4005
|
[/because/gi, "∵"],
|
|
@@ -2285,7 +4016,7 @@ var CRLEncoder = class {
|
|
|
2285
4016
|
[/fixes/gi, "→:fixes"],
|
|
2286
4017
|
[/relates to/gi, "∩"]
|
|
2287
4018
|
];
|
|
2288
|
-
let result =
|
|
4019
|
+
let result = text2;
|
|
2289
4020
|
for (const [pattern, replacement] of replacements) {
|
|
2290
4021
|
result = result.replace(pattern, replacement);
|
|
2291
4022
|
}
|
|
@@ -2438,7 +4169,7 @@ var CRLDecoder = class {
|
|
|
2438
4169
|
/**
|
|
2439
4170
|
* Expand CRL symbols to natural language
|
|
2440
4171
|
*/
|
|
2441
|
-
expand(
|
|
4172
|
+
expand(text2) {
|
|
2442
4173
|
const expansions = {
|
|
2443
4174
|
"∴": "therefore",
|
|
2444
4175
|
"∵": "because",
|
|
@@ -2464,7 +4195,7 @@ var CRLDecoder = class {
|
|
|
2464
4195
|
"∃": "there exists",
|
|
2465
4196
|
"∄": "there does not exist"
|
|
2466
4197
|
};
|
|
2467
|
-
let result =
|
|
4198
|
+
let result = text2;
|
|
2468
4199
|
for (const [symbol, expansion] of Object.entries(expansions)) {
|
|
2469
4200
|
result = result.replace(new RegExp(`(^|[.!?]\\s*)${symbol}`, "g"), (match, prefix) => {
|
|
2470
4201
|
const capitalized = expansion.charAt(0).toUpperCase() + expansion.slice(1);
|
|
@@ -2518,8 +4249,8 @@ var CRL = {
|
|
|
2518
4249
|
/**
|
|
2519
4250
|
* Quick encode: natural language → CRL
|
|
2520
4251
|
*/
|
|
2521
|
-
encode(
|
|
2522
|
-
return this.encoder.encode(
|
|
4252
|
+
encode(text2) {
|
|
4253
|
+
return this.encoder.encode(text2);
|
|
2523
4254
|
},
|
|
2524
4255
|
/**
|
|
2525
4256
|
* Quick decode: CRL → natural language
|
|
@@ -2530,14 +4261,14 @@ var CRL = {
|
|
|
2530
4261
|
/**
|
|
2531
4262
|
* Quick compress: replace common patterns with symbols
|
|
2532
4263
|
*/
|
|
2533
|
-
compress(
|
|
2534
|
-
return this.encoder.compress(
|
|
4264
|
+
compress(text2) {
|
|
4265
|
+
return this.encoder.compress(text2);
|
|
2535
4266
|
},
|
|
2536
4267
|
/**
|
|
2537
4268
|
* Quick expand: replace symbols with natural language
|
|
2538
4269
|
*/
|
|
2539
|
-
expand(
|
|
2540
|
-
return this.decoder.expand(
|
|
4270
|
+
expand(text2) {
|
|
4271
|
+
return this.decoder.expand(text2);
|
|
2541
4272
|
},
|
|
2542
4273
|
/**
|
|
2543
4274
|
* Resolve templates with context
|
|
@@ -2582,11 +4313,11 @@ function slowWaveReplay(db, options = {}) {
|
|
|
2582
4313
|
}
|
|
2583
4314
|
const integratedNodes = [];
|
|
2584
4315
|
if (options.graph) {
|
|
2585
|
-
for (const
|
|
4316
|
+
for (const id2 of ids) {
|
|
2586
4317
|
try {
|
|
2587
|
-
const referenced = db.prepare(`SELECT 1 FROM kg_edges WHERE source_episode_id = ? LIMIT 1`).get(
|
|
4318
|
+
const referenced = db.prepare(`SELECT 1 FROM kg_edges WHERE source_episode_id = ? LIMIT 1`).get(id2);
|
|
2588
4319
|
if (!referenced) {
|
|
2589
|
-
const nodeText = `episode:${
|
|
4320
|
+
const nodeText = `episode:${id2}`;
|
|
2590
4321
|
const newNodeId = options.graph.upsertNode({ text: nodeText, nodeType: "event" });
|
|
2591
4322
|
if (newNodeId)
|
|
2592
4323
|
integratedNodes.push(newNodeId);
|
|
@@ -2977,8 +4708,8 @@ function runMemoryMaintenance(options) {
|
|
|
2977
4708
|
return result;
|
|
2978
4709
|
}
|
|
2979
4710
|
function emptyResult(options, started) {
|
|
2980
|
-
const missing = (
|
|
2981
|
-
path,
|
|
4711
|
+
const missing = (path2) => ({
|
|
4712
|
+
path: path2,
|
|
2982
4713
|
exists: false,
|
|
2983
4714
|
sizeBeforeBytes: 0,
|
|
2984
4715
|
sizeAfterBytes: 0,
|
|
@@ -3029,17 +4760,17 @@ function emptyResult(options, started) {
|
|
|
3029
4760
|
stoppedEarly: false
|
|
3030
4761
|
};
|
|
3031
4762
|
}
|
|
3032
|
-
function storeStats(
|
|
3033
|
-
const walPath = `${
|
|
3034
|
-
const shmPath = `${
|
|
3035
|
-
const archivePath =
|
|
3036
|
-
const sizeBeforeBytes = fileSize(
|
|
4763
|
+
function storeStats(path2) {
|
|
4764
|
+
const walPath = `${path2}-wal`;
|
|
4765
|
+
const shmPath = `${path2}-shm`;
|
|
4766
|
+
const archivePath = path2.endsWith("knowledge.db") ? join2(dirname(path2), "knowledge.archive.db") : "";
|
|
4767
|
+
const sizeBeforeBytes = fileSize(path2);
|
|
3037
4768
|
const walBeforeBytes = fileSize(walPath);
|
|
3038
4769
|
const shmBeforeBytes = fileSize(shmPath);
|
|
3039
4770
|
const archiveBeforeBytes = archivePath ? fileSize(archivePath) : 0;
|
|
3040
4771
|
return {
|
|
3041
|
-
path,
|
|
3042
|
-
exists: existsSync2(
|
|
4772
|
+
path: path2,
|
|
4773
|
+
exists: existsSync2(path2),
|
|
3043
4774
|
sizeBeforeBytes,
|
|
3044
4775
|
sizeAfterBytes: sizeBeforeBytes,
|
|
3045
4776
|
walBeforeBytes,
|
|
@@ -3062,9 +4793,9 @@ function refreshStoreStatsAfter(stats) {
|
|
|
3062
4793
|
stats.archiveAfterBytes = archivePath ? fileSize(archivePath) : 0;
|
|
3063
4794
|
stats.physicalAfterBytes = stats.sizeAfterBytes + stats.walAfterBytes + stats.shmAfterBytes + stats.archiveAfterBytes;
|
|
3064
4795
|
}
|
|
3065
|
-
function fileSize(
|
|
4796
|
+
function fileSize(path2) {
|
|
3066
4797
|
try {
|
|
3067
|
-
return existsSync2(
|
|
4798
|
+
return existsSync2(path2) ? statSync(path2).size : 0;
|
|
3068
4799
|
} catch {
|
|
3069
4800
|
return 0;
|
|
3070
4801
|
}
|
|
@@ -3340,8 +5071,8 @@ function deleteEpisodes(db, ids, dryRun) {
|
|
|
3340
5071
|
let deleted = 0;
|
|
3341
5072
|
const stmt = db.prepare(`DELETE FROM episodes WHERE id = ?`);
|
|
3342
5073
|
const tx = db.transaction((rows) => {
|
|
3343
|
-
for (const
|
|
3344
|
-
const result = stmt.run(
|
|
5074
|
+
for (const id2 of rows) {
|
|
5075
|
+
const result = stmt.run(id2);
|
|
3345
5076
|
deleted += Number(result.changes ?? 0);
|
|
3346
5077
|
}
|
|
3347
5078
|
});
|
|
@@ -3637,8 +5368,8 @@ function reinforceGraphNodes(dbPath, ids) {
|
|
|
3637
5368
|
const stmt = db.prepare("UPDATE kg_nodes SET last_seen = ?, mention_count = COALESCE(mention_count, 1) + 1 WHERE id = ?");
|
|
3638
5369
|
let updated = 0;
|
|
3639
5370
|
const tx = db.transaction((rows) => {
|
|
3640
|
-
for (const
|
|
3641
|
-
updated += Number(stmt.run(now,
|
|
5371
|
+
for (const id2 of rows)
|
|
5372
|
+
updated += Number(stmt.run(now, id2).changes ?? 0);
|
|
3642
5373
|
});
|
|
3643
5374
|
tx(ids);
|
|
3644
5375
|
return updated;
|
|
@@ -3703,8 +5434,8 @@ function deleteById(db, table, ids) {
|
|
|
3703
5434
|
let deleted = 0;
|
|
3704
5435
|
const stmt = db.prepare(`DELETE FROM ${table} WHERE id = ?`);
|
|
3705
5436
|
const tx = db.transaction((rows) => {
|
|
3706
|
-
for (const
|
|
3707
|
-
const result = stmt.run(
|
|
5437
|
+
for (const id2 of rows) {
|
|
5438
|
+
const result = stmt.run(id2);
|
|
3708
5439
|
deleted += Number(result.changes ?? 0);
|
|
3709
5440
|
}
|
|
3710
5441
|
});
|
|
@@ -3752,9 +5483,9 @@ function graphNodeScore(row) {
|
|
|
3752
5483
|
const recency = Math.exp(-age / (30 * DAY));
|
|
3753
5484
|
return Math.log1p(Math.max(0, row.mentionCount)) * 0.7 + recency * 0.3;
|
|
3754
5485
|
}
|
|
3755
|
-
function vectorFor(rawEmbedding,
|
|
5486
|
+
function vectorFor(rawEmbedding, text2) {
|
|
3756
5487
|
const decoded = decodeEmbedding(rawEmbedding);
|
|
3757
|
-
return decoded ?? hashEmbedding(
|
|
5488
|
+
return decoded ?? hashEmbedding(text2);
|
|
3758
5489
|
}
|
|
3759
5490
|
function decodeEmbedding(raw) {
|
|
3760
5491
|
if (!raw)
|
|
@@ -3775,10 +5506,10 @@ function decodeEmbedding(raw) {
|
|
|
3775
5506
|
}
|
|
3776
5507
|
return null;
|
|
3777
5508
|
}
|
|
3778
|
-
function hashEmbedding(
|
|
5509
|
+
function hashEmbedding(text2, dimensions = 256) {
|
|
3779
5510
|
const dim = Math.max(16, dimensions);
|
|
3780
5511
|
const vector = new Array(dim).fill(0);
|
|
3781
|
-
const tokens =
|
|
5512
|
+
const tokens = text2.toLowerCase().split(/[^\p{L}\p{N}_./-]+/u).map((token) => token.trim()).filter(Boolean);
|
|
3782
5513
|
const features = [...tokens];
|
|
3783
5514
|
for (let i = 0; i < tokens.length - 1; i++) {
|
|
3784
5515
|
features.push(`${tokens[i]} ${tokens[i + 1]}`);
|
|
@@ -3847,8 +5578,8 @@ function vacuum(db) {
|
|
|
3847
5578
|
import { join as join3 } from "node:path";
|
|
3848
5579
|
|
|
3849
5580
|
// packages/cli/src/tui/commands/kg-prune-inference.ts
|
|
3850
|
-
function truncate(
|
|
3851
|
-
const clean =
|
|
5581
|
+
function truncate(text2, max) {
|
|
5582
|
+
const clean = text2.replace(/\s+/g, " ").trim();
|
|
3852
5583
|
return clean.length > max ? clean.slice(0, max - 1) + "…" : clean;
|
|
3853
5584
|
}
|
|
3854
5585
|
async function classifySignalNodes(candidates, cfg) {
|
|
@@ -3917,8 +5648,8 @@ function parseIdArray(content, valid) {
|
|
|
3917
5648
|
if (!Array.isArray(parsed)) return [];
|
|
3918
5649
|
const out = [];
|
|
3919
5650
|
for (const item of parsed) {
|
|
3920
|
-
const
|
|
3921
|
-
if (
|
|
5651
|
+
const id2 = typeof item === "string" ? item : String(item ?? "");
|
|
5652
|
+
if (id2 && valid.has(id2) && !out.includes(id2)) out.push(id2);
|
|
3922
5653
|
}
|
|
3923
5654
|
return out;
|
|
3924
5655
|
}
|