@principal-ai/subsystems-react 0.56.36 → 0.56.37
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/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/subsystem/nodes.d.ts +5 -5
- package/dist/subsystem/nodes.d.ts.map +1 -1
- package/dist/subsystem/nodes.js +196 -177
- package/dist/subsystem/nodes.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/src/stories/Canvases/Subsystem/AgentDrivenWalkthrough.stories.tsx +1543 -52
- package/src/subsystem/nodes.tsx +291 -220
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState,
|
|
7
|
+
} from "react";
|
|
2
8
|
import "@xyflow/react/dist/style.css";
|
|
3
9
|
import type { Meta, StoryObj } from "@storybook/react";
|
|
4
10
|
import {
|
|
@@ -12,6 +18,7 @@ import {
|
|
|
12
18
|
} from "../../../subsystem/SubsystemComponentGraph";
|
|
13
19
|
import {
|
|
14
20
|
HOST_PROPOSAL_COLOR,
|
|
21
|
+
trailStepGraphEdgeId,
|
|
15
22
|
type SubsystemComponent,
|
|
16
23
|
type SubsystemTrail,
|
|
17
24
|
type SubsystemTrailStep,
|
|
@@ -65,7 +72,9 @@ export default meta;
|
|
|
65
72
|
type Story = StoryObj<typeof meta>;
|
|
66
73
|
|
|
67
74
|
const PURL = "pkg:github/acme/booking-web";
|
|
75
|
+
const PAY_PURL = "pkg:github/acme/payments";
|
|
68
76
|
const stepPurl = (file: string) => `${PURL}#${file}`;
|
|
77
|
+
const payStepPurl = (file: string) => `${PAY_PURL}#${file}`;
|
|
69
78
|
|
|
70
79
|
const seedComponents: SubsystemComponent[] = [
|
|
71
80
|
{
|
|
@@ -703,9 +712,694 @@ const componentDeclinedEvents = withFinalDecision(
|
|
|
703
712
|
"RefundService would duplicate the mailer's responsibility, so I am keeping the model as is.",
|
|
704
713
|
);
|
|
705
714
|
|
|
715
|
+
/**
|
|
716
|
+
* Multi-proposal prototype: a proposal is context (trail-step refs that may
|
|
717
|
+
* span models) plus a delta on node-captured entities. Several proposals can
|
|
718
|
+
* share one decision boundary — a `HostChange`. The graph the user sees is a
|
|
719
|
+
* host-local synthetic model projected from the affected source trails.
|
|
720
|
+
*/
|
|
721
|
+
type SourceModelId = "booking" | "payments";
|
|
722
|
+
type ProposalStatus = "staged" | "accepted" | "rejected";
|
|
723
|
+
|
|
724
|
+
type ContextRef = {
|
|
725
|
+
modelId: SourceModelId;
|
|
726
|
+
trailId: string;
|
|
727
|
+
/** Stable claim fingerprint; survives reordering of the source trail. */
|
|
728
|
+
stepKey: string;
|
|
729
|
+
label: string;
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
type HostProposalDelta =
|
|
733
|
+
| {
|
|
734
|
+
kind: "trail-replace";
|
|
735
|
+
beforeTrailId: string;
|
|
736
|
+
afterTrail: SubsystemTrail;
|
|
737
|
+
}
|
|
738
|
+
| {
|
|
739
|
+
kind: "component-add";
|
|
740
|
+
component: SubsystemComponent;
|
|
741
|
+
trail: SubsystemTrail;
|
|
742
|
+
}
|
|
743
|
+
| { kind: "component-remove"; componentAlias: string };
|
|
744
|
+
|
|
745
|
+
type HostProposal = {
|
|
746
|
+
id: string;
|
|
747
|
+
name: string;
|
|
748
|
+
context: ContextRef[];
|
|
749
|
+
delta: HostProposalDelta;
|
|
750
|
+
rationale: string;
|
|
751
|
+
status: ProposalStatus;
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
type HostChange = {
|
|
755
|
+
id: string;
|
|
756
|
+
name: string;
|
|
757
|
+
rationale: string;
|
|
758
|
+
proposals: HostProposal[];
|
|
759
|
+
status: ProposalStatus;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
type SourceModel = {
|
|
763
|
+
id: SourceModelId;
|
|
764
|
+
name: string;
|
|
765
|
+
purl: string;
|
|
766
|
+
components: SubsystemComponent[];
|
|
767
|
+
trails: SubsystemTrail[];
|
|
768
|
+
};
|
|
769
|
+
|
|
770
|
+
type MultiDriveEvent =
|
|
771
|
+
| Extract<
|
|
772
|
+
DriveEvent,
|
|
773
|
+
{
|
|
774
|
+
kind:
|
|
775
|
+
| "prompt"
|
|
776
|
+
| "open-model"
|
|
777
|
+
| "agent"
|
|
778
|
+
| "agent-working"
|
|
779
|
+
| "agent-decision";
|
|
780
|
+
}
|
|
781
|
+
>
|
|
782
|
+
| {
|
|
783
|
+
kind: "open-proposal-context";
|
|
784
|
+
id: string;
|
|
785
|
+
tool: string;
|
|
786
|
+
text: string;
|
|
787
|
+
change: HostChange;
|
|
788
|
+
}
|
|
789
|
+
| {
|
|
790
|
+
kind: "activate-proposal";
|
|
791
|
+
id: string;
|
|
792
|
+
tool: string;
|
|
793
|
+
text: string;
|
|
794
|
+
proposalId: string;
|
|
795
|
+
}
|
|
796
|
+
| {
|
|
797
|
+
kind: "open-source-model";
|
|
798
|
+
id: string;
|
|
799
|
+
tool: string;
|
|
800
|
+
text: string;
|
|
801
|
+
sourceModelId: SourceModelId;
|
|
802
|
+
sourceTrailId: string;
|
|
803
|
+
}
|
|
804
|
+
| {
|
|
805
|
+
kind: "return-to-proposal";
|
|
806
|
+
id: string;
|
|
807
|
+
tool: string;
|
|
808
|
+
text: string;
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const sourceModels: Record<SourceModelId, SourceModel> = {
|
|
812
|
+
booking: {
|
|
813
|
+
id: "booking",
|
|
814
|
+
name: "Booking web",
|
|
815
|
+
purl: PURL,
|
|
816
|
+
components: seedComponents,
|
|
817
|
+
trails: seedTrails,
|
|
818
|
+
},
|
|
819
|
+
payments: {
|
|
820
|
+
id: "payments",
|
|
821
|
+
name: "Payments service",
|
|
822
|
+
purl: PAY_PURL,
|
|
823
|
+
components: [
|
|
824
|
+
{
|
|
825
|
+
alias: "pay-api",
|
|
826
|
+
name: "RefundApi",
|
|
827
|
+
construct: "function",
|
|
828
|
+
file: "src/refund/refundApi.ts",
|
|
829
|
+
purl: PAY_PURL,
|
|
830
|
+
symbol: "RefundApi",
|
|
831
|
+
purpose: "starts a refund",
|
|
832
|
+
process: "payments/service",
|
|
833
|
+
},
|
|
834
|
+
{
|
|
835
|
+
alias: "pay-gateway",
|
|
836
|
+
name: "PaymentGateway",
|
|
837
|
+
construct: "external",
|
|
838
|
+
file: "src/gateway/paymentGateway.ts",
|
|
839
|
+
purl: PAY_PURL,
|
|
840
|
+
symbol: "PaymentGateway",
|
|
841
|
+
purpose: "reverses a charge",
|
|
842
|
+
role: "service",
|
|
843
|
+
},
|
|
844
|
+
{
|
|
845
|
+
alias: "pay-ledger",
|
|
846
|
+
name: "RefundLedger",
|
|
847
|
+
construct: "class",
|
|
848
|
+
file: "src/ledger/refundLedger.ts",
|
|
849
|
+
purl: PAY_PURL,
|
|
850
|
+
symbol: "RefundLedger",
|
|
851
|
+
purpose: "records reversals",
|
|
852
|
+
process: "payments/service",
|
|
853
|
+
},
|
|
854
|
+
],
|
|
855
|
+
trails: [
|
|
856
|
+
{
|
|
857
|
+
id: "pt-refund",
|
|
858
|
+
title: "Issue refund",
|
|
859
|
+
steps: [
|
|
860
|
+
{
|
|
861
|
+
from: "pay-api",
|
|
862
|
+
to: "pay-gateway",
|
|
863
|
+
mechanism: "calls",
|
|
864
|
+
file: "src/refund/refundApi.ts",
|
|
865
|
+
span: { startLine: 18, endLine: 18, contentHash: "fixture" },
|
|
866
|
+
purl: payStepPurl("src/refund/refundApi.ts"),
|
|
867
|
+
symbol: "RefundApi.refund",
|
|
868
|
+
annotation:
|
|
869
|
+
"The refund API asks the gateway to reverse the charge.",
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
from: "pay-gateway",
|
|
873
|
+
to: "pay-ledger",
|
|
874
|
+
mechanism: "writes",
|
|
875
|
+
file: "src/gateway/paymentGateway.ts",
|
|
876
|
+
span: { startLine: 24, endLine: 24, contentHash: "fixture" },
|
|
877
|
+
purl: payStepPurl("src/gateway/paymentGateway.ts"),
|
|
878
|
+
symbol: "PaymentGateway.reverse",
|
|
879
|
+
annotation:
|
|
880
|
+
"The gateway records the reversal in the refund ledger.",
|
|
881
|
+
},
|
|
882
|
+
],
|
|
883
|
+
},
|
|
884
|
+
{
|
|
885
|
+
id: "pt-settlement",
|
|
886
|
+
title: "Settle a reversal",
|
|
887
|
+
steps: [
|
|
888
|
+
{
|
|
889
|
+
from: "pay-ledger",
|
|
890
|
+
to: "pay-api",
|
|
891
|
+
mechanism: "produces",
|
|
892
|
+
file: "src/ledger/refundLedger.ts",
|
|
893
|
+
span: { startLine: 31, endLine: 31, contentHash: "fixture" },
|
|
894
|
+
purl: payStepPurl("src/ledger/refundLedger.ts"),
|
|
895
|
+
symbol: "RefundLedger.settled",
|
|
896
|
+
annotation: "The ledger reports settlement back to the refund API.",
|
|
897
|
+
},
|
|
898
|
+
],
|
|
899
|
+
},
|
|
900
|
+
],
|
|
901
|
+
},
|
|
902
|
+
};
|
|
903
|
+
|
|
904
|
+
const allSourceComponents = Object.values(sourceModels).flatMap(
|
|
905
|
+
(model) => model.components,
|
|
906
|
+
);
|
|
907
|
+
|
|
908
|
+
function findComponentByAlias(alias: string): SubsystemComponent | undefined {
|
|
909
|
+
return allSourceComponents.find((component) => component.alias === alias);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function contextRefFromSource(
|
|
913
|
+
modelId: SourceModelId,
|
|
914
|
+
trailId: string,
|
|
915
|
+
stepIndex: number,
|
|
916
|
+
label: string,
|
|
917
|
+
): ContextRef {
|
|
918
|
+
const step = sourceModels[modelId].trails.find(
|
|
919
|
+
(trail) => trail.id === trailId,
|
|
920
|
+
)?.steps[stepIndex];
|
|
921
|
+
if (!step) {
|
|
922
|
+
throw new Error(`Missing source step: ${modelId}/${trailId}/${stepIndex}`);
|
|
923
|
+
}
|
|
924
|
+
return { modelId, trailId, stepKey: stepClaimKey(step), label };
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
const proposedCancelRefundTrail: SubsystemTrail = {
|
|
928
|
+
id: "wt-cancel-refund",
|
|
929
|
+
title: "Cancel with a refund intent",
|
|
930
|
+
steps: [
|
|
931
|
+
{
|
|
932
|
+
from: "ui",
|
|
933
|
+
to: "api",
|
|
934
|
+
mechanism: "calls",
|
|
935
|
+
file: "src/ui/BookingPage.tsx",
|
|
936
|
+
span: { startLine: 61, endLine: 61, contentHash: "proposed" },
|
|
937
|
+
purl: stepPurl("src/ui/BookingPage.tsx"),
|
|
938
|
+
symbol: "BookingPage.cancel",
|
|
939
|
+
annotation: "Cancel still sends the booking id to the API.",
|
|
940
|
+
},
|
|
941
|
+
{
|
|
942
|
+
from: "api",
|
|
943
|
+
to: "pay-gateway",
|
|
944
|
+
mechanism: "produces",
|
|
945
|
+
file: "src/api/checkout.ts",
|
|
946
|
+
span: { startLine: 34, endLine: 34, contentHash: "proposed" },
|
|
947
|
+
purl: stepPurl("src/api/checkout.ts"),
|
|
948
|
+
symbol: "checkoutApi.refundIntent",
|
|
949
|
+
annotation: "Cancel emits a refund intent to the payments gateway.",
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
from: "pay-gateway",
|
|
953
|
+
to: "store",
|
|
954
|
+
mechanism: "writes",
|
|
955
|
+
file: "src/gateway/paymentGateway.ts",
|
|
956
|
+
span: { startLine: 25, endLine: 25, contentHash: "proposed" },
|
|
957
|
+
purl: payStepPurl("src/gateway/paymentGateway.ts"),
|
|
958
|
+
symbol: "PaymentGateway.recordRefund",
|
|
959
|
+
annotation: "The gateway records the reversal against the booking.",
|
|
960
|
+
},
|
|
961
|
+
],
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
const proposedAuditComponent: SubsystemComponent = {
|
|
965
|
+
alias: "pay-audit",
|
|
966
|
+
name: "RefundAudit",
|
|
967
|
+
construct: "class",
|
|
968
|
+
file: "src/audit/refundAudit.ts",
|
|
969
|
+
purl: PAY_PURL,
|
|
970
|
+
symbol: "RefundAudit",
|
|
971
|
+
purpose: "records refund decisions",
|
|
972
|
+
process: "payments/service",
|
|
973
|
+
};
|
|
974
|
+
|
|
975
|
+
const proposedAuditTrail: SubsystemTrail = {
|
|
976
|
+
id: "pt-refund-audit",
|
|
977
|
+
title: "Record a refund decision",
|
|
978
|
+
steps: [
|
|
979
|
+
{
|
|
980
|
+
from: "pay-api",
|
|
981
|
+
to: "pay-audit",
|
|
982
|
+
mechanism: "writes",
|
|
983
|
+
file: "src/refund/refundApi.ts",
|
|
984
|
+
span: { startLine: 27, endLine: 27, contentHash: "proposed" },
|
|
985
|
+
purl: payStepPurl("src/refund/refundApi.ts"),
|
|
986
|
+
symbol: "RefundApi.audit",
|
|
987
|
+
annotation: "The refund API records why the reversal was requested.",
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
from: "pay-audit",
|
|
991
|
+
to: "ui",
|
|
992
|
+
mechanism: "feeds",
|
|
993
|
+
file: "src/audit/refundAudit.ts",
|
|
994
|
+
span: { startLine: 12, endLine: 12, contentHash: "proposed" },
|
|
995
|
+
purl: payStepPurl("src/audit/refundAudit.ts"),
|
|
996
|
+
symbol: "RefundAudit.status",
|
|
997
|
+
annotation: "The audit decision returns to the booking page.",
|
|
998
|
+
},
|
|
999
|
+
],
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
const refundHandlingChange: HostChange = {
|
|
1003
|
+
id: "chg-refund-handling",
|
|
1004
|
+
name: "Add refund handling",
|
|
1005
|
+
rationale:
|
|
1006
|
+
"Three context-specific proposals share one accept/reject decision.",
|
|
1007
|
+
status: "staged",
|
|
1008
|
+
proposals: [
|
|
1009
|
+
{
|
|
1010
|
+
id: "p-cancel-trail",
|
|
1011
|
+
name: "Replace cancel trail",
|
|
1012
|
+
context: [
|
|
1013
|
+
contextRefFromSource(
|
|
1014
|
+
"booking",
|
|
1015
|
+
"wt-cancel",
|
|
1016
|
+
1,
|
|
1017
|
+
"Cancel stops at the store",
|
|
1018
|
+
),
|
|
1019
|
+
contextRefFromSource(
|
|
1020
|
+
"payments",
|
|
1021
|
+
"pt-refund",
|
|
1022
|
+
0,
|
|
1023
|
+
"Payments already reverses charges",
|
|
1024
|
+
),
|
|
1025
|
+
],
|
|
1026
|
+
delta: {
|
|
1027
|
+
kind: "trail-replace",
|
|
1028
|
+
beforeTrailId: "wt-cancel",
|
|
1029
|
+
afterTrail: proposedCancelRefundTrail,
|
|
1030
|
+
},
|
|
1031
|
+
rationale:
|
|
1032
|
+
"One context covers the missing refund hop and the payments path that already knows how to reverse it.",
|
|
1033
|
+
status: "staged",
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
id: "p-refund-audit",
|
|
1037
|
+
name: "Add RefundAudit",
|
|
1038
|
+
context: [
|
|
1039
|
+
contextRefFromSource(
|
|
1040
|
+
"payments",
|
|
1041
|
+
"pt-refund",
|
|
1042
|
+
1,
|
|
1043
|
+
"The ledger has no audit owner",
|
|
1044
|
+
),
|
|
1045
|
+
contextRefFromSource(
|
|
1046
|
+
"booking",
|
|
1047
|
+
"wt-cancel",
|
|
1048
|
+
1,
|
|
1049
|
+
"Cancel needs a recorded reason",
|
|
1050
|
+
),
|
|
1051
|
+
],
|
|
1052
|
+
delta: {
|
|
1053
|
+
kind: "component-add",
|
|
1054
|
+
component: proposedAuditComponent,
|
|
1055
|
+
trail: proposedAuditTrail,
|
|
1056
|
+
},
|
|
1057
|
+
rationale:
|
|
1058
|
+
"The refund decision needs its own owner in the payments model, with a status seam back to booking.",
|
|
1059
|
+
status: "staged",
|
|
1060
|
+
},
|
|
1061
|
+
{
|
|
1062
|
+
id: "p-retire-mailer",
|
|
1063
|
+
name: "Retire confirmation mailer",
|
|
1064
|
+
context: [
|
|
1065
|
+
contextRefFromSource(
|
|
1066
|
+
"booking",
|
|
1067
|
+
"wt-book",
|
|
1068
|
+
2,
|
|
1069
|
+
"Mailer is the final confirmation hop",
|
|
1070
|
+
),
|
|
1071
|
+
contextRefFromSource(
|
|
1072
|
+
"payments",
|
|
1073
|
+
"pt-settlement",
|
|
1074
|
+
0,
|
|
1075
|
+
"Settlement no longer needs it",
|
|
1076
|
+
),
|
|
1077
|
+
],
|
|
1078
|
+
delta: { kind: "component-remove", componentAlias: "mailer" },
|
|
1079
|
+
rationale:
|
|
1080
|
+
"Refund status now travels through the audit seam, so the old confirmation mailer can be retired.",
|
|
1081
|
+
status: "staged",
|
|
1082
|
+
},
|
|
1083
|
+
],
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
const multiProposalEvents: MultiDriveEvent[] = [
|
|
1087
|
+
{
|
|
1088
|
+
kind: "prompt",
|
|
1089
|
+
id: "mp-prompt",
|
|
1090
|
+
text: "Show refund handling across booking and payments, then propose a change.",
|
|
1091
|
+
},
|
|
1092
|
+
{
|
|
1093
|
+
kind: "agent",
|
|
1094
|
+
id: "mp-agent-1",
|
|
1095
|
+
text: "I will project the affected trails from both models into one synthetic view, then walk the proposals in that view.",
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
kind: "open-model",
|
|
1099
|
+
id: "mp-open-model",
|
|
1100
|
+
tool: "open_subsystem_model",
|
|
1101
|
+
text: "Open the synthetic proposal context so the change has somewhere to land.",
|
|
1102
|
+
},
|
|
1103
|
+
{
|
|
1104
|
+
kind: "agent-working",
|
|
1105
|
+
id: "mp-agent-2",
|
|
1106
|
+
text: "The affected trails come from two models. I am projecting them into one context view before I stage anything.",
|
|
1107
|
+
workingOn: "projecting affected trails from Booking and Payments",
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
kind: "open-proposal-context",
|
|
1111
|
+
id: "mp-open-proposal-context",
|
|
1112
|
+
tool: "open_proposal_context",
|
|
1113
|
+
text: "Open one change containing three proposals with their own trail contexts.",
|
|
1114
|
+
change: refundHandlingChange,
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
kind: "agent-working",
|
|
1118
|
+
id: "mp-agent-3",
|
|
1119
|
+
text: "The first proposal replaces the cancel trail. Its context includes the booking gap and the payments refund path.",
|
|
1120
|
+
workingOn: "reviewing the cancel-trail replacement",
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
kind: "activate-proposal",
|
|
1124
|
+
id: "mp-focus-audit",
|
|
1125
|
+
tool: "focus_proposal_context",
|
|
1126
|
+
text: "Switch the header to the RefundAudit proposal.",
|
|
1127
|
+
proposalId: "p-refund-audit",
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
kind: "agent-working",
|
|
1131
|
+
id: "mp-agent-4",
|
|
1132
|
+
text: "The audit proposal needs the payments trail in its own model. I am opening that source explicitly, not as a focus side effect.",
|
|
1133
|
+
workingOn: "checking the Payments refund trail in its own model",
|
|
1134
|
+
},
|
|
1135
|
+
{
|
|
1136
|
+
kind: "open-source-model",
|
|
1137
|
+
id: "mp-open-source",
|
|
1138
|
+
tool: "open_source_model",
|
|
1139
|
+
text: "Open the Payments model for additional context on the ledger step.",
|
|
1140
|
+
sourceModelId: "payments",
|
|
1141
|
+
sourceTrailId: "pt-refund",
|
|
1142
|
+
},
|
|
1143
|
+
{
|
|
1144
|
+
kind: "return-to-proposal",
|
|
1145
|
+
id: "mp-return",
|
|
1146
|
+
tool: "return_to_proposal_view",
|
|
1147
|
+
text: "Return to the synthetic change view.",
|
|
1148
|
+
},
|
|
1149
|
+
{
|
|
1150
|
+
kind: "agent-working",
|
|
1151
|
+
id: "mp-agent-5",
|
|
1152
|
+
text: "The mailer retirement is the third proposal. It belongs in the same change, so it will share the same decision.",
|
|
1153
|
+
workingOn: "reviewing the mailer retirement",
|
|
1154
|
+
},
|
|
1155
|
+
{
|
|
1156
|
+
kind: "activate-proposal",
|
|
1157
|
+
id: "mp-focus-mailer",
|
|
1158
|
+
tool: "focus_proposal_context",
|
|
1159
|
+
text: "Switch the header to the mailer retirement proposal.",
|
|
1160
|
+
proposalId: "p-retire-mailer",
|
|
1161
|
+
},
|
|
1162
|
+
{
|
|
1163
|
+
kind: "agent-decision",
|
|
1164
|
+
id: "mp-decision",
|
|
1165
|
+
text: "These three proposals answer one change request, so I am accepting them together.",
|
|
1166
|
+
decision: "accepted",
|
|
1167
|
+
},
|
|
1168
|
+
];
|
|
1169
|
+
|
|
1170
|
+
const multiProposalDeclinedEvents = multiProposalEvents.map((event) =>
|
|
1171
|
+
event.kind === "agent-decision"
|
|
1172
|
+
? {
|
|
1173
|
+
...event,
|
|
1174
|
+
decision: "rejected" as const,
|
|
1175
|
+
text: "The cancel path still needs its store write, so I am declining all three proposals together.",
|
|
1176
|
+
}
|
|
1177
|
+
: event,
|
|
1178
|
+
);
|
|
1179
|
+
|
|
1180
|
+
function buildSyntheticModel(
|
|
1181
|
+
change: HostChange,
|
|
1182
|
+
activeProposal: HostProposal | undefined,
|
|
1183
|
+
accepted: boolean,
|
|
1184
|
+
) {
|
|
1185
|
+
const components = new Map<string, SubsystemComponent>();
|
|
1186
|
+
const trails = new Map<string, SubsystemTrail>();
|
|
1187
|
+
const removedComponentAliases = new Set<string>();
|
|
1188
|
+
// Accepted changes keep their original steps as layout-only ghosts. The
|
|
1189
|
+
// sidebar still renders only the live trails; the graph frames the ghosts
|
|
1190
|
+
// with dim dashed `was …` edges beside the applied change.
|
|
1191
|
+
const stepHistory: SubsystemTrailStepHistory[] = [];
|
|
1192
|
+
|
|
1193
|
+
const addSourceTrail = (ref: ContextRef) => {
|
|
1194
|
+
const source = sourceModels[ref.modelId];
|
|
1195
|
+
const trail = source.trails.find(
|
|
1196
|
+
(candidate) => candidate.id === ref.trailId,
|
|
1197
|
+
);
|
|
1198
|
+
if (!trail) return;
|
|
1199
|
+
trails.set(trail.id, {
|
|
1200
|
+
...trail,
|
|
1201
|
+
title: `${trail.title} · ${source.name}`,
|
|
1202
|
+
});
|
|
1203
|
+
for (const step of trail.steps) {
|
|
1204
|
+
for (const alias of [step.from, step.to]) {
|
|
1205
|
+
const component = source.components.find(
|
|
1206
|
+
(candidate) => candidate.alias === alias,
|
|
1207
|
+
);
|
|
1208
|
+
if (component) components.set(alias, component);
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
};
|
|
1212
|
+
|
|
1213
|
+
// The synthetic model always carries the union of context trails. Switching
|
|
1214
|
+
// proposals changes focus and chrome, not the underlying projection.
|
|
1215
|
+
change.proposals.forEach((proposal) =>
|
|
1216
|
+
proposal.context.forEach(addSourceTrail),
|
|
1217
|
+
);
|
|
1218
|
+
|
|
1219
|
+
for (const proposal of change.proposals) {
|
|
1220
|
+
const applyDelta = accepted || proposal.id === activeProposal?.id;
|
|
1221
|
+
if (!applyDelta) continue;
|
|
1222
|
+
|
|
1223
|
+
if (proposal.delta.kind === "trail-replace") {
|
|
1224
|
+
if (accepted) {
|
|
1225
|
+
const before = trails.get(proposal.delta.beforeTrailId);
|
|
1226
|
+
const liveEdgeIds = new Set(
|
|
1227
|
+
proposal.delta.afterTrail.steps.map(trailStepGraphEdgeId),
|
|
1228
|
+
);
|
|
1229
|
+
for (const [stepIndex, step] of (before?.steps ?? []).entries()) {
|
|
1230
|
+
// An unchanged step is already live in the replacement; ghosting it
|
|
1231
|
+
// would dim the applied edge. Only changed steps become `was` edges.
|
|
1232
|
+
if (liveEdgeIds.has(trailStepGraphEdgeId(step))) continue;
|
|
1233
|
+
stepHistory.push({
|
|
1234
|
+
trailId: proposal.delta.afterTrail.id,
|
|
1235
|
+
stepIndex,
|
|
1236
|
+
previous: step,
|
|
1237
|
+
kind: "changed",
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
trails.delete(proposal.delta.beforeTrailId);
|
|
1241
|
+
}
|
|
1242
|
+
trails.set(proposal.delta.afterTrail.id, proposal.delta.afterTrail);
|
|
1243
|
+
for (const step of proposal.delta.afterTrail.steps) {
|
|
1244
|
+
for (const alias of [step.from, step.to]) {
|
|
1245
|
+
const component = findComponentByAlias(alias);
|
|
1246
|
+
if (component) components.set(alias, component);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
} else if (proposal.delta.kind === "component-add") {
|
|
1250
|
+
components.set(proposal.delta.component.alias, proposal.delta.component);
|
|
1251
|
+
trails.set(proposal.delta.trail.id, proposal.delta.trail);
|
|
1252
|
+
for (const step of proposal.delta.trail.steps) {
|
|
1253
|
+
for (const alias of [step.from, step.to]) {
|
|
1254
|
+
const component =
|
|
1255
|
+
alias === proposal.delta.component.alias
|
|
1256
|
+
? proposal.delta.component
|
|
1257
|
+
: findComponentByAlias(alias);
|
|
1258
|
+
if (component) components.set(alias, component);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
} else if (accepted) {
|
|
1262
|
+
removedComponentAliases.add(proposal.delta.componentAlias);
|
|
1263
|
+
for (const [trailId, trail] of trails) {
|
|
1264
|
+
const keptSteps: SubsystemTrailStep[] = [];
|
|
1265
|
+
trail.steps.forEach((step, stepIndex) => {
|
|
1266
|
+
if (
|
|
1267
|
+
step.from === proposal.delta.componentAlias ||
|
|
1268
|
+
step.to === proposal.delta.componentAlias
|
|
1269
|
+
) {
|
|
1270
|
+
stepHistory.push({
|
|
1271
|
+
trailId,
|
|
1272
|
+
stepIndex: Math.min(stepIndex, keptSteps.length),
|
|
1273
|
+
previous: step,
|
|
1274
|
+
kind: "removed",
|
|
1275
|
+
});
|
|
1276
|
+
} else {
|
|
1277
|
+
keptSteps.push(step);
|
|
1278
|
+
}
|
|
1279
|
+
});
|
|
1280
|
+
trails.set(trailId, { ...trail, steps: keptSteps });
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
return {
|
|
1286
|
+
components: [...components.values()],
|
|
1287
|
+
trails: [...trails.values()],
|
|
1288
|
+
removedComponentAliases,
|
|
1289
|
+
stepHistory,
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
function proposalWorkingAliases(proposal: HostProposal | undefined) {
|
|
1294
|
+
const aliases = new Set<string>();
|
|
1295
|
+
if (!proposal) return aliases;
|
|
1296
|
+
for (const ref of proposal.context) {
|
|
1297
|
+
const source = sourceModels[ref.modelId];
|
|
1298
|
+
const trail = source.trails.find(
|
|
1299
|
+
(candidate) => candidate.id === ref.trailId,
|
|
1300
|
+
);
|
|
1301
|
+
const step = trail?.steps.find(
|
|
1302
|
+
(candidate) => stepClaimKey(candidate) === ref.stepKey,
|
|
1303
|
+
);
|
|
1304
|
+
if (step) {
|
|
1305
|
+
aliases.add(step.from);
|
|
1306
|
+
aliases.add(step.to);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
if (proposal.delta.kind === "trail-replace") {
|
|
1310
|
+
proposal.delta.afterTrail.steps.forEach((step) => {
|
|
1311
|
+
aliases.add(step.from);
|
|
1312
|
+
aliases.add(step.to);
|
|
1313
|
+
});
|
|
1314
|
+
} else if (proposal.delta.kind === "component-add") {
|
|
1315
|
+
aliases.add(proposal.delta.component.alias);
|
|
1316
|
+
} else {
|
|
1317
|
+
aliases.add(proposal.delta.componentAlias);
|
|
1318
|
+
}
|
|
1319
|
+
return aliases;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
function proposalFocus(
|
|
1323
|
+
proposal: HostProposal | undefined,
|
|
1324
|
+
trails: readonly SubsystemTrail[],
|
|
1325
|
+
accepted: boolean,
|
|
1326
|
+
stepHistory: readonly SubsystemTrailStepHistory[],
|
|
1327
|
+
) {
|
|
1328
|
+
if (!proposal) return undefined;
|
|
1329
|
+
// After the decision, frame the applied change and its retained ghosts —
|
|
1330
|
+
// not a surviving piece of the original context that happens to resolve.
|
|
1331
|
+
if (accepted) {
|
|
1332
|
+
if (proposal.delta.kind === "trail-replace") {
|
|
1333
|
+
return {
|
|
1334
|
+
trailId: proposal.delta.afterTrail.id,
|
|
1335
|
+
stepIndex: 1,
|
|
1336
|
+
showFile: false,
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
if (proposal.delta.kind === "component-add") {
|
|
1340
|
+
return {
|
|
1341
|
+
trailId: proposal.delta.trail.id,
|
|
1342
|
+
stepIndex: 0,
|
|
1343
|
+
showFile: false,
|
|
1344
|
+
};
|
|
1345
|
+
}
|
|
1346
|
+
const removed = stepHistory.find(
|
|
1347
|
+
(link) =>
|
|
1348
|
+
(link.previous.from === proposal.delta.componentAlias ||
|
|
1349
|
+
link.previous.to === proposal.delta.componentAlias) &&
|
|
1350
|
+
trails.some((trail) => trail.id === link.trailId),
|
|
1351
|
+
);
|
|
1352
|
+
if (removed) {
|
|
1353
|
+
return {
|
|
1354
|
+
trailId: removed.trailId,
|
|
1355
|
+
// Frame the last live step beside its ghost; the ghost itself joins
|
|
1356
|
+
// the camera bounds through the graph's linked-edge history.
|
|
1357
|
+
stepIndex: Math.max(0, removed.stepIndex - 1),
|
|
1358
|
+
showFile: false,
|
|
1359
|
+
};
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
for (const ref of proposal.context) {
|
|
1363
|
+
const sourceTrail = sourceModels[ref.modelId].trails.find(
|
|
1364
|
+
(candidate) => candidate.id === ref.trailId,
|
|
1365
|
+
);
|
|
1366
|
+
const stepIndex = sourceTrail?.steps.findIndex(
|
|
1367
|
+
(candidate) => stepClaimKey(candidate) === ref.stepKey,
|
|
1368
|
+
);
|
|
1369
|
+
const projectedTrail = trails.find((trail) => trail.id === ref.trailId);
|
|
1370
|
+
if (
|
|
1371
|
+
stepIndex != null &&
|
|
1372
|
+
stepIndex >= 0 &&
|
|
1373
|
+
projectedTrail &&
|
|
1374
|
+
stepIndex < projectedTrail.steps.length
|
|
1375
|
+
) {
|
|
1376
|
+
return {
|
|
1377
|
+
trailId: ref.trailId,
|
|
1378
|
+
stepIndex,
|
|
1379
|
+
showFile: false,
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
if (proposal.delta.kind === "trail-replace") {
|
|
1384
|
+
return {
|
|
1385
|
+
trailId: proposal.delta.afterTrail.id,
|
|
1386
|
+
stepIndex: 0,
|
|
1387
|
+
showFile: false,
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
if (proposal.delta.kind === "component-add") {
|
|
1391
|
+
return {
|
|
1392
|
+
trailId: proposal.delta.trail.id,
|
|
1393
|
+
stepIndex: 0,
|
|
1394
|
+
showFile: false,
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
return undefined;
|
|
1398
|
+
}
|
|
1399
|
+
|
|
706
1400
|
// `Animate opening` replays through the open call so the artifact appears
|
|
707
1401
|
// immediately, then lets the rest of the stream continue behind it.
|
|
708
|
-
function openingEventCountFor(events:
|
|
1402
|
+
function openingEventCountFor(events: readonly { kind: string }[]) {
|
|
709
1403
|
const index = events.findIndex((event) => event.kind === "open-model");
|
|
710
1404
|
return index < 0 ? 0 : index + 1;
|
|
711
1405
|
}
|
|
@@ -1067,7 +1761,58 @@ function usePrototypeTheme() {
|
|
|
1067
1761
|
// Slow enough to read each tool call and watch the camera settle between steps.
|
|
1068
1762
|
const AUTOPLAY_INTERVAL_MS = 1800;
|
|
1069
1763
|
|
|
1070
|
-
|
|
1764
|
+
const prototypeAnimationStyles = `
|
|
1765
|
+
@keyframes agent-working-star {
|
|
1766
|
+
0%, 100% { opacity: 0.45; }
|
|
1767
|
+
50% { opacity: 1; }
|
|
1768
|
+
}
|
|
1769
|
+
/* Only the sparkle arms twinkle; the wand, icon, and status dot stay put. */
|
|
1770
|
+
.agent-working-icon path:nth-of-type(n+3) {
|
|
1771
|
+
animation: agent-working-star 1.6s ease-in-out infinite;
|
|
1772
|
+
}
|
|
1773
|
+
.agent-working-icon path:nth-of-type(3),
|
|
1774
|
+
.agent-working-icon path:nth-of-type(6) {
|
|
1775
|
+
animation-delay: 0s;
|
|
1776
|
+
}
|
|
1777
|
+
.agent-working-icon path:nth-of-type(4),
|
|
1778
|
+
.agent-working-icon path:nth-of-type(7) {
|
|
1779
|
+
animation-delay: -0.55s;
|
|
1780
|
+
}
|
|
1781
|
+
.agent-working-icon path:nth-of-type(5),
|
|
1782
|
+
.agent-working-icon path:nth-of-type(8) {
|
|
1783
|
+
animation-delay: -1.1s;
|
|
1784
|
+
}
|
|
1785
|
+
@keyframes agent-model-opening-in {
|
|
1786
|
+
from {
|
|
1787
|
+
opacity: 0;
|
|
1788
|
+
transform: translateY(22px) scale(0.985);
|
|
1789
|
+
filter: blur(4px);
|
|
1790
|
+
}
|
|
1791
|
+
to {
|
|
1792
|
+
opacity: 1;
|
|
1793
|
+
transform: translateY(0) scale(1);
|
|
1794
|
+
filter: blur(0);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
.agent-model-opening {
|
|
1798
|
+
animation: agent-model-opening-in 700ms cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
1799
|
+
transform-origin: 50% 35%;
|
|
1800
|
+
}
|
|
1801
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1802
|
+
.agent-working-dot,
|
|
1803
|
+
.agent-working-icon,
|
|
1804
|
+
.agent-working-icon path:nth-of-type(n+3) {
|
|
1805
|
+
animation: none !important;
|
|
1806
|
+
}
|
|
1807
|
+
.agent-model-opening {
|
|
1808
|
+
animation: none !important;
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
`;
|
|
1812
|
+
|
|
1813
|
+
type ToolStreamEvent = DriveEvent | MultiDriveEvent;
|
|
1814
|
+
|
|
1815
|
+
function ToolRow({ event }: { event: ToolStreamEvent }) {
|
|
1071
1816
|
const { theme, border, muted, accent, mono, small } = usePrototypeTheme();
|
|
1072
1817
|
const isAgentEvent =
|
|
1073
1818
|
event.kind === "agent" ||
|
|
@@ -1094,7 +1839,18 @@ function ToolRow({ event }: { event: DriveEvent }) {
|
|
|
1094
1839
|
? `add ${event.trail.id}`
|
|
1095
1840
|
: event.kind === "propose-component"
|
|
1096
1841
|
? `add ${event.component.alias} + ${event.trail.id}`
|
|
1097
|
-
:
|
|
1842
|
+
: event.kind === "propose-step" ||
|
|
1843
|
+
event.kind === "propose-component-removal"
|
|
1844
|
+
? `change ${event.kind === "propose-step" ? event.trailId : event.componentAlias}${event.kind === "propose-step" ? ` step ${event.stepIndex + 1}` : ""}`
|
|
1845
|
+
: event.kind === "open-proposal-context"
|
|
1846
|
+
? `${event.change.proposals.length} proposals · ${event.change.name}`
|
|
1847
|
+
: event.kind === "activate-proposal"
|
|
1848
|
+
? `focus ${event.proposalId}`
|
|
1849
|
+
: event.kind === "open-source-model"
|
|
1850
|
+
? `${event.sourceModelId} · ${event.sourceTrailId}`
|
|
1851
|
+
: event.kind === "return-to-proposal"
|
|
1852
|
+
? "return to proposal view"
|
|
1853
|
+
: event.text;
|
|
1098
1854
|
|
|
1099
1855
|
return (
|
|
1100
1856
|
<div
|
|
@@ -1744,54 +2500,7 @@ function Prototype({
|
|
|
1744
2500
|
background: theme.colors.background,
|
|
1745
2501
|
}}
|
|
1746
2502
|
>
|
|
1747
|
-
<style>{
|
|
1748
|
-
@keyframes agent-working-star {
|
|
1749
|
-
0%, 100% { opacity: 0.45; }
|
|
1750
|
-
50% { opacity: 1; }
|
|
1751
|
-
}
|
|
1752
|
-
/* Only the sparkle arms twinkle; the wand, icon, and status dot stay put. */
|
|
1753
|
-
.agent-working-icon path:nth-of-type(n+3) {
|
|
1754
|
-
animation: agent-working-star 1.6s ease-in-out infinite;
|
|
1755
|
-
}
|
|
1756
|
-
.agent-working-icon path:nth-of-type(3),
|
|
1757
|
-
.agent-working-icon path:nth-of-type(6) {
|
|
1758
|
-
animation-delay: 0s;
|
|
1759
|
-
}
|
|
1760
|
-
.agent-working-icon path:nth-of-type(4),
|
|
1761
|
-
.agent-working-icon path:nth-of-type(7) {
|
|
1762
|
-
animation-delay: -0.55s;
|
|
1763
|
-
}
|
|
1764
|
-
.agent-working-icon path:nth-of-type(5),
|
|
1765
|
-
.agent-working-icon path:nth-of-type(8) {
|
|
1766
|
-
animation-delay: -1.1s;
|
|
1767
|
-
}
|
|
1768
|
-
@keyframes agent-model-opening-in {
|
|
1769
|
-
from {
|
|
1770
|
-
opacity: 0;
|
|
1771
|
-
transform: translateY(22px) scale(0.985);
|
|
1772
|
-
filter: blur(4px);
|
|
1773
|
-
}
|
|
1774
|
-
to {
|
|
1775
|
-
opacity: 1;
|
|
1776
|
-
transform: translateY(0) scale(1);
|
|
1777
|
-
filter: blur(0);
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
.agent-model-opening {
|
|
1781
|
-
animation: agent-model-opening-in 700ms cubic-bezier(0.16, 1, 0.3, 1) both;
|
|
1782
|
-
transform-origin: 50% 35%;
|
|
1783
|
-
}
|
|
1784
|
-
@media (prefers-reduced-motion: reduce) {
|
|
1785
|
-
.agent-working-dot,
|
|
1786
|
-
.agent-working-icon,
|
|
1787
|
-
.agent-working-icon path:nth-of-type(n+3) {
|
|
1788
|
-
animation: none !important;
|
|
1789
|
-
}
|
|
1790
|
-
.agent-model-opening {
|
|
1791
|
-
animation: none !important;
|
|
1792
|
-
}
|
|
1793
|
-
}
|
|
1794
|
-
`}</style>
|
|
2503
|
+
<style>{prototypeAnimationStyles}</style>
|
|
1795
2504
|
{state.modelOpen ? (
|
|
1796
2505
|
<div
|
|
1797
2506
|
key={openingKey}
|
|
@@ -2001,6 +2710,766 @@ function Prototype({
|
|
|
2001
2710
|
);
|
|
2002
2711
|
}
|
|
2003
2712
|
|
|
2713
|
+
type MultiDriveState = {
|
|
2714
|
+
modelOpen: boolean;
|
|
2715
|
+
change: HostChange | null;
|
|
2716
|
+
activeProposalId: string | null;
|
|
2717
|
+
view: "proposal" | "source";
|
|
2718
|
+
sourceModelId: SourceModelId | null;
|
|
2719
|
+
sourceTrailId: string | null;
|
|
2720
|
+
agentWorkingOn: string | null;
|
|
2721
|
+
decision: "accepted" | "rejected" | null;
|
|
2722
|
+
};
|
|
2723
|
+
|
|
2724
|
+
const initialMultiState = (): MultiDriveState => ({
|
|
2725
|
+
modelOpen: false,
|
|
2726
|
+
change: null,
|
|
2727
|
+
activeProposalId: null,
|
|
2728
|
+
view: "proposal",
|
|
2729
|
+
sourceModelId: null,
|
|
2730
|
+
sourceTrailId: null,
|
|
2731
|
+
agentWorkingOn: null,
|
|
2732
|
+
decision: null,
|
|
2733
|
+
});
|
|
2734
|
+
|
|
2735
|
+
function applyMultiEvent(
|
|
2736
|
+
event: MultiDriveEvent,
|
|
2737
|
+
state: MultiDriveState,
|
|
2738
|
+
): MultiDriveState {
|
|
2739
|
+
switch (event.kind) {
|
|
2740
|
+
case "open-model":
|
|
2741
|
+
return { ...state, modelOpen: true };
|
|
2742
|
+
case "agent":
|
|
2743
|
+
return { ...state, agentWorkingOn: null };
|
|
2744
|
+
case "agent-working":
|
|
2745
|
+
return { ...state, agentWorkingOn: event.workingOn };
|
|
2746
|
+
case "agent-decision":
|
|
2747
|
+
return {
|
|
2748
|
+
...state,
|
|
2749
|
+
decision: event.decision,
|
|
2750
|
+
agentWorkingOn: null,
|
|
2751
|
+
change: state.change
|
|
2752
|
+
? {
|
|
2753
|
+
...state.change,
|
|
2754
|
+
status: event.decision,
|
|
2755
|
+
proposals: state.change.proposals.map((proposal) => ({
|
|
2756
|
+
...proposal,
|
|
2757
|
+
status: event.decision,
|
|
2758
|
+
})),
|
|
2759
|
+
}
|
|
2760
|
+
: state.change,
|
|
2761
|
+
};
|
|
2762
|
+
case "open-proposal-context":
|
|
2763
|
+
return {
|
|
2764
|
+
...state,
|
|
2765
|
+
change: event.change,
|
|
2766
|
+
activeProposalId: event.change.proposals[0]?.id ?? null,
|
|
2767
|
+
view: "proposal",
|
|
2768
|
+
sourceModelId: null,
|
|
2769
|
+
sourceTrailId: null,
|
|
2770
|
+
};
|
|
2771
|
+
case "activate-proposal":
|
|
2772
|
+
return {
|
|
2773
|
+
...state,
|
|
2774
|
+
activeProposalId: event.proposalId,
|
|
2775
|
+
view: "proposal",
|
|
2776
|
+
sourceModelId: null,
|
|
2777
|
+
sourceTrailId: null,
|
|
2778
|
+
};
|
|
2779
|
+
case "open-source-model":
|
|
2780
|
+
return {
|
|
2781
|
+
...state,
|
|
2782
|
+
view: "source",
|
|
2783
|
+
sourceModelId: event.sourceModelId,
|
|
2784
|
+
sourceTrailId: event.sourceTrailId,
|
|
2785
|
+
agentWorkingOn: null,
|
|
2786
|
+
};
|
|
2787
|
+
case "return-to-proposal":
|
|
2788
|
+
return {
|
|
2789
|
+
...state,
|
|
2790
|
+
view: "proposal",
|
|
2791
|
+
sourceModelId: null,
|
|
2792
|
+
sourceTrailId: null,
|
|
2793
|
+
};
|
|
2794
|
+
default:
|
|
2795
|
+
return state;
|
|
2796
|
+
}
|
|
2797
|
+
}
|
|
2798
|
+
|
|
2799
|
+
function MultiProposalPrototype({
|
|
2800
|
+
events,
|
|
2801
|
+
title,
|
|
2802
|
+
persistKey,
|
|
2803
|
+
description,
|
|
2804
|
+
}: {
|
|
2805
|
+
events: MultiDriveEvent[];
|
|
2806
|
+
title: string;
|
|
2807
|
+
persistKey: string;
|
|
2808
|
+
description: string;
|
|
2809
|
+
}) {
|
|
2810
|
+
const { theme, border, muted, accent, proposal, mono, small, body } =
|
|
2811
|
+
usePrototypeTheme();
|
|
2812
|
+
const openingEventCount = useMemo(
|
|
2813
|
+
() => openingEventCountFor(events),
|
|
2814
|
+
[events],
|
|
2815
|
+
);
|
|
2816
|
+
const [state, setState] = useState<MultiDriveState>(initialMultiState);
|
|
2817
|
+
const [cursor, setCursor] = useState(0);
|
|
2818
|
+
const [playing, setPlaying] = useState(false);
|
|
2819
|
+
const [openingKey, setOpeningKey] = useState(0);
|
|
2820
|
+
const [proposalMenuOpen, setProposalMenuOpen] = useState(false);
|
|
2821
|
+
const proposalMenuRef = useRef<HTMLDivElement>(null);
|
|
2822
|
+
|
|
2823
|
+
const applyDriveEvent = useCallback((event: MultiDriveEvent) => {
|
|
2824
|
+
setState((prev) => applyMultiEvent(event, prev));
|
|
2825
|
+
if (event.kind === "open-model") {
|
|
2826
|
+
setOpeningKey((prev) => prev + 1);
|
|
2827
|
+
}
|
|
2828
|
+
}, []);
|
|
2829
|
+
|
|
2830
|
+
// Agent-driven proposal switches and source-model drill-outs close the menu.
|
|
2831
|
+
useEffect(() => {
|
|
2832
|
+
setProposalMenuOpen(false);
|
|
2833
|
+
}, [state.activeProposalId, state.view]);
|
|
2834
|
+
|
|
2835
|
+
useEffect(() => {
|
|
2836
|
+
if (!proposalMenuOpen) return;
|
|
2837
|
+
const onPointerDown = (event: PointerEvent) => {
|
|
2838
|
+
if (!proposalMenuRef.current?.contains(event.target as Node)) {
|
|
2839
|
+
setProposalMenuOpen(false);
|
|
2840
|
+
}
|
|
2841
|
+
};
|
|
2842
|
+
const onKeyDown = (event: KeyboardEvent) => {
|
|
2843
|
+
if (event.key === "Escape") setProposalMenuOpen(false);
|
|
2844
|
+
};
|
|
2845
|
+
window.addEventListener("pointerdown", onPointerDown);
|
|
2846
|
+
window.addEventListener("keydown", onKeyDown);
|
|
2847
|
+
return () => {
|
|
2848
|
+
window.removeEventListener("pointerdown", onPointerDown);
|
|
2849
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
2850
|
+
};
|
|
2851
|
+
}, [proposalMenuOpen]);
|
|
2852
|
+
|
|
2853
|
+
useEffect(() => {
|
|
2854
|
+
if (!playing) return;
|
|
2855
|
+
if (cursor >= events.length) {
|
|
2856
|
+
setPlaying(false);
|
|
2857
|
+
return;
|
|
2858
|
+
}
|
|
2859
|
+
const timer = window.setTimeout(() => {
|
|
2860
|
+
applyDriveEvent(events[cursor]!);
|
|
2861
|
+
setCursor((prev) => prev + 1);
|
|
2862
|
+
}, AUTOPLAY_INTERVAL_MS);
|
|
2863
|
+
return () => window.clearTimeout(timer);
|
|
2864
|
+
}, [cursor, playing, events, applyDriveEvent]);
|
|
2865
|
+
|
|
2866
|
+
const reset = useCallback(() => {
|
|
2867
|
+
setState(initialMultiState());
|
|
2868
|
+
setCursor(0);
|
|
2869
|
+
setPlaying(false);
|
|
2870
|
+
}, []);
|
|
2871
|
+
|
|
2872
|
+
const animateOpening = useCallback(() => {
|
|
2873
|
+
setState(initialMultiState());
|
|
2874
|
+
events.slice(0, openingEventCount).forEach(applyDriveEvent);
|
|
2875
|
+
setCursor(openingEventCount);
|
|
2876
|
+
setPlaying(true);
|
|
2877
|
+
}, [applyDriveEvent, events, openingEventCount]);
|
|
2878
|
+
|
|
2879
|
+
const step = useCallback(() => {
|
|
2880
|
+
if (cursor >= events.length) return;
|
|
2881
|
+
applyDriveEvent(events[cursor]!);
|
|
2882
|
+
setCursor((prev) => prev + 1);
|
|
2883
|
+
}, [cursor, events, applyDriveEvent]);
|
|
2884
|
+
|
|
2885
|
+
const change = state.change;
|
|
2886
|
+
const activeProposal = change?.proposals.find(
|
|
2887
|
+
(candidate) => candidate.id === state.activeProposalId,
|
|
2888
|
+
);
|
|
2889
|
+
const activeIndex = change?.proposals.findIndex(
|
|
2890
|
+
(candidate) => candidate.id === state.activeProposalId,
|
|
2891
|
+
);
|
|
2892
|
+
const synthetic = useMemo(
|
|
2893
|
+
() =>
|
|
2894
|
+
change
|
|
2895
|
+
? buildSyntheticModel(
|
|
2896
|
+
change,
|
|
2897
|
+
activeProposal,
|
|
2898
|
+
state.decision === "accepted",
|
|
2899
|
+
)
|
|
2900
|
+
: {
|
|
2901
|
+
components: [],
|
|
2902
|
+
trails: [],
|
|
2903
|
+
removedComponentAliases: new Set<string>(),
|
|
2904
|
+
stepHistory: [] as SubsystemTrailStepHistory[],
|
|
2905
|
+
},
|
|
2906
|
+
[change, activeProposal, state.decision],
|
|
2907
|
+
);
|
|
2908
|
+
|
|
2909
|
+
const sourceModel = state.sourceModelId
|
|
2910
|
+
? sourceModels[state.sourceModelId]
|
|
2911
|
+
: undefined;
|
|
2912
|
+
const sourceTrail = sourceModel?.trails.find(
|
|
2913
|
+
(trail) => trail.id === state.sourceTrailId,
|
|
2914
|
+
);
|
|
2915
|
+
const activeSourceRef = activeProposal?.context.find(
|
|
2916
|
+
(ref) =>
|
|
2917
|
+
ref.modelId === state.sourceModelId &&
|
|
2918
|
+
ref.trailId === state.sourceTrailId,
|
|
2919
|
+
);
|
|
2920
|
+
const sourceStepIndex = sourceTrail?.steps.findIndex(
|
|
2921
|
+
(candidate) => stepClaimKey(candidate) === activeSourceRef?.stepKey,
|
|
2922
|
+
);
|
|
2923
|
+
|
|
2924
|
+
const graphComponents =
|
|
2925
|
+
state.view === "source" && sourceModel
|
|
2926
|
+
? sourceModel.components
|
|
2927
|
+
: synthetic.components;
|
|
2928
|
+
const graphTrails =
|
|
2929
|
+
state.view === "source" && sourceTrail ? [sourceTrail] : synthetic.trails;
|
|
2930
|
+
|
|
2931
|
+
const focusedTrailStep =
|
|
2932
|
+
state.view === "source" && sourceTrail
|
|
2933
|
+
? {
|
|
2934
|
+
trailId: sourceTrail.id,
|
|
2935
|
+
stepIndex:
|
|
2936
|
+
sourceStepIndex && sourceStepIndex >= 0 ? sourceStepIndex : 0,
|
|
2937
|
+
showFile: false,
|
|
2938
|
+
}
|
|
2939
|
+
: proposalFocus(
|
|
2940
|
+
activeProposal,
|
|
2941
|
+
synthetic.trails,
|
|
2942
|
+
state.decision === "accepted",
|
|
2943
|
+
synthetic.stepHistory,
|
|
2944
|
+
);
|
|
2945
|
+
|
|
2946
|
+
const workingAliases = useMemo(() => {
|
|
2947
|
+
if (!state.agentWorkingOn) return undefined;
|
|
2948
|
+
if (state.view === "source" && focusedTrailStep?.stepIndex != null) {
|
|
2949
|
+
const step = sourceTrail?.steps[focusedTrailStep.stepIndex];
|
|
2950
|
+
if (step) return new Set([step.from, step.to]);
|
|
2951
|
+
}
|
|
2952
|
+
const aliases = proposalWorkingAliases(activeProposal);
|
|
2953
|
+
return aliases.size ? aliases : undefined;
|
|
2954
|
+
}, [
|
|
2955
|
+
state.agentWorkingOn,
|
|
2956
|
+
state.view,
|
|
2957
|
+
focusedTrailStep,
|
|
2958
|
+
sourceTrail,
|
|
2959
|
+
activeProposal,
|
|
2960
|
+
]);
|
|
2961
|
+
|
|
2962
|
+
const proposalChromeActive = state.view === "proposal" && !state.decision;
|
|
2963
|
+
const proposedTrailIds =
|
|
2964
|
+
proposalChromeActive && activeProposal?.delta.kind === "trail-replace"
|
|
2965
|
+
? new Set([activeProposal.delta.afterTrail.id])
|
|
2966
|
+
: proposalChromeActive && activeProposal?.delta.kind === "component-add"
|
|
2967
|
+
? new Set([activeProposal.delta.trail.id])
|
|
2968
|
+
: undefined;
|
|
2969
|
+
const proposedComponentAliases =
|
|
2970
|
+
proposalChromeActive && activeProposal?.delta.kind === "component-add"
|
|
2971
|
+
? new Set([activeProposal.delta.component.alias])
|
|
2972
|
+
: undefined;
|
|
2973
|
+
|
|
2974
|
+
const selectProposal = useCallback((proposalId: string) => {
|
|
2975
|
+
setState((prev) => {
|
|
2976
|
+
if (
|
|
2977
|
+
prev.view !== "proposal" ||
|
|
2978
|
+
!prev.change?.proposals.some((candidate) => candidate.id === proposalId)
|
|
2979
|
+
) {
|
|
2980
|
+
return prev;
|
|
2981
|
+
}
|
|
2982
|
+
return { ...prev, activeProposalId: proposalId, agentWorkingOn: null };
|
|
2983
|
+
});
|
|
2984
|
+
setProposalMenuOpen(false);
|
|
2985
|
+
}, []);
|
|
2986
|
+
|
|
2987
|
+
const openSourceForActive = useCallback(() => {
|
|
2988
|
+
setState((prev) => {
|
|
2989
|
+
const ref = prev.change?.proposals.find(
|
|
2990
|
+
(candidate) => candidate.id === prev.activeProposalId,
|
|
2991
|
+
)?.context[0];
|
|
2992
|
+
if (!ref) return prev;
|
|
2993
|
+
return {
|
|
2994
|
+
...prev,
|
|
2995
|
+
view: "source",
|
|
2996
|
+
sourceModelId: ref.modelId,
|
|
2997
|
+
sourceTrailId: ref.trailId,
|
|
2998
|
+
agentWorkingOn: null,
|
|
2999
|
+
};
|
|
3000
|
+
});
|
|
3001
|
+
}, []);
|
|
3002
|
+
|
|
3003
|
+
const returnToProposal = useCallback(() => {
|
|
3004
|
+
setState((prev) => ({
|
|
3005
|
+
...prev,
|
|
3006
|
+
view: "proposal",
|
|
3007
|
+
sourceModelId: null,
|
|
3008
|
+
sourceTrailId: null,
|
|
3009
|
+
}));
|
|
3010
|
+
}, []);
|
|
3011
|
+
|
|
3012
|
+
const agentStatusOverlay =
|
|
3013
|
+
state.agentWorkingOn || state.decision ? (
|
|
3014
|
+
<div
|
|
3015
|
+
aria-live="polite"
|
|
3016
|
+
style={{
|
|
3017
|
+
display: "flex",
|
|
3018
|
+
alignItems: "center",
|
|
3019
|
+
gap: 8,
|
|
3020
|
+
padding: "6px 12px",
|
|
3021
|
+
borderRadius: 999,
|
|
3022
|
+
border: `1px solid ${state.agentWorkingOn ? accent : proposal}`,
|
|
3023
|
+
background:
|
|
3024
|
+
theme.colors.backgroundSecondary ?? theme.colors.background,
|
|
3025
|
+
boxShadow: "0 6px 20px rgba(0,0,0,0.35)",
|
|
3026
|
+
fontFamily: mono,
|
|
3027
|
+
fontSize: small,
|
|
3028
|
+
whiteSpace: "nowrap",
|
|
3029
|
+
}}
|
|
3030
|
+
>
|
|
3031
|
+
{state.agentWorkingOn ? (
|
|
3032
|
+
<>
|
|
3033
|
+
<span
|
|
3034
|
+
className="agent-working-dot"
|
|
3035
|
+
style={{
|
|
3036
|
+
width: 6,
|
|
3037
|
+
height: 6,
|
|
3038
|
+
borderRadius: "50%",
|
|
3039
|
+
background: accent,
|
|
3040
|
+
flexShrink: 0,
|
|
3041
|
+
}}
|
|
3042
|
+
/>
|
|
3043
|
+
<span style={{ color: accent, fontWeight: 600 }}>
|
|
3044
|
+
AGENT WORKING ON
|
|
3045
|
+
</span>
|
|
3046
|
+
<span style={{ color: theme.colors.text }}>
|
|
3047
|
+
{state.agentWorkingOn}
|
|
3048
|
+
</span>
|
|
3049
|
+
</>
|
|
3050
|
+
) : (
|
|
3051
|
+
<span style={{ color: proposal, fontWeight: 600 }}>
|
|
3052
|
+
{state.decision === "accepted"
|
|
3053
|
+
? "AGENT COMMITTED CHANGE"
|
|
3054
|
+
: "AGENT DECLINED CHANGE"}
|
|
3055
|
+
</span>
|
|
3056
|
+
)}
|
|
3057
|
+
</div>
|
|
3058
|
+
) : null;
|
|
3059
|
+
|
|
3060
|
+
const header =
|
|
3061
|
+
state.view === "source" ? (
|
|
3062
|
+
<header
|
|
3063
|
+
style={{
|
|
3064
|
+
position: "relative",
|
|
3065
|
+
zIndex: 30,
|
|
3066
|
+
flexShrink: 0,
|
|
3067
|
+
display: "flex",
|
|
3068
|
+
alignItems: "center",
|
|
3069
|
+
gap: 12,
|
|
3070
|
+
padding: "12px 16px",
|
|
3071
|
+
background: theme.colors.background,
|
|
3072
|
+
borderBottom: `1px solid ${border}`,
|
|
3073
|
+
fontFamily: mono,
|
|
3074
|
+
}}
|
|
3075
|
+
>
|
|
3076
|
+
<span
|
|
3077
|
+
style={{
|
|
3078
|
+
fontSize: small,
|
|
3079
|
+
letterSpacing: "0.08em",
|
|
3080
|
+
fontWeight: 600,
|
|
3081
|
+
color: proposal,
|
|
3082
|
+
whiteSpace: "nowrap",
|
|
3083
|
+
}}
|
|
3084
|
+
>
|
|
3085
|
+
SOURCE CONTEXT
|
|
3086
|
+
</span>
|
|
3087
|
+
<span
|
|
3088
|
+
style={{
|
|
3089
|
+
position: "absolute",
|
|
3090
|
+
left: "50%",
|
|
3091
|
+
transform: "translateX(-50%)",
|
|
3092
|
+
fontSize: theme.fontSizes[2],
|
|
3093
|
+
color: theme.colors.text,
|
|
3094
|
+
whiteSpace: "nowrap",
|
|
3095
|
+
}}
|
|
3096
|
+
>
|
|
3097
|
+
{sourceModel?.name ?? title}
|
|
3098
|
+
</span>
|
|
3099
|
+
<button
|
|
3100
|
+
type="button"
|
|
3101
|
+
onClick={returnToProposal}
|
|
3102
|
+
aria-label="Back to proposal"
|
|
3103
|
+
style={{
|
|
3104
|
+
marginLeft: "auto",
|
|
3105
|
+
padding: "4px 10px",
|
|
3106
|
+
borderRadius: 4,
|
|
3107
|
+
border: `1px solid ${accent}`,
|
|
3108
|
+
background: `${accent}18`,
|
|
3109
|
+
color: accent,
|
|
3110
|
+
fontFamily: mono,
|
|
3111
|
+
fontSize: small,
|
|
3112
|
+
fontWeight: 600,
|
|
3113
|
+
cursor: "pointer",
|
|
3114
|
+
whiteSpace: "nowrap",
|
|
3115
|
+
}}
|
|
3116
|
+
>
|
|
3117
|
+
Back to proposal
|
|
3118
|
+
</button>
|
|
3119
|
+
</header>
|
|
3120
|
+
) : (
|
|
3121
|
+
<header
|
|
3122
|
+
style={{
|
|
3123
|
+
position: "relative",
|
|
3124
|
+
zIndex: 30,
|
|
3125
|
+
flexShrink: 0,
|
|
3126
|
+
display: "flex",
|
|
3127
|
+
alignItems: "center",
|
|
3128
|
+
gap: 12,
|
|
3129
|
+
padding: "12px 16px",
|
|
3130
|
+
background: theme.colors.background,
|
|
3131
|
+
borderBottom: `1px solid ${border}`,
|
|
3132
|
+
fontFamily: mono,
|
|
3133
|
+
}}
|
|
3134
|
+
>
|
|
3135
|
+
<span
|
|
3136
|
+
style={{
|
|
3137
|
+
fontSize: small,
|
|
3138
|
+
letterSpacing: "0.08em",
|
|
3139
|
+
fontWeight: 600,
|
|
3140
|
+
color: accent,
|
|
3141
|
+
whiteSpace: "nowrap",
|
|
3142
|
+
}}
|
|
3143
|
+
>
|
|
3144
|
+
AGENT-DRIVEN · CHANGE
|
|
3145
|
+
</span>
|
|
3146
|
+
<div
|
|
3147
|
+
ref={proposalMenuRef}
|
|
3148
|
+
style={{
|
|
3149
|
+
position: "absolute",
|
|
3150
|
+
left: "50%",
|
|
3151
|
+
transform: "translateX(-50%)",
|
|
3152
|
+
}}
|
|
3153
|
+
>
|
|
3154
|
+
<button
|
|
3155
|
+
type="button"
|
|
3156
|
+
onClick={() => setProposalMenuOpen((prev) => !prev)}
|
|
3157
|
+
aria-label="Select proposal"
|
|
3158
|
+
aria-haspopup="listbox"
|
|
3159
|
+
aria-expanded={proposalMenuOpen}
|
|
3160
|
+
disabled={(change?.proposals.length ?? 0) < 2}
|
|
3161
|
+
style={{
|
|
3162
|
+
display: "flex",
|
|
3163
|
+
alignItems: "center",
|
|
3164
|
+
gap: 8,
|
|
3165
|
+
padding: "4px 10px",
|
|
3166
|
+
borderRadius: 4,
|
|
3167
|
+
border: `1px solid ${proposal}`,
|
|
3168
|
+
background: `${proposal}18`,
|
|
3169
|
+
color: proposal,
|
|
3170
|
+
fontFamily: mono,
|
|
3171
|
+
fontSize: theme.fontSizes[2],
|
|
3172
|
+
fontWeight: 600,
|
|
3173
|
+
whiteSpace: "nowrap",
|
|
3174
|
+
cursor:
|
|
3175
|
+
(change?.proposals.length ?? 0) < 2 ? "default" : "pointer",
|
|
3176
|
+
}}
|
|
3177
|
+
>
|
|
3178
|
+
<span style={{ color: theme.colors.text }}>
|
|
3179
|
+
{activeProposal?.name ?? title}
|
|
3180
|
+
</span>
|
|
3181
|
+
{(change?.proposals.length ?? 0) > 1 ? (
|
|
3182
|
+
<span style={{ fontSize: small, color: proposal }}>
|
|
3183
|
+
{(activeIndex ?? 0) + 1} / {change?.proposals.length}
|
|
3184
|
+
</span>
|
|
3185
|
+
) : null}
|
|
3186
|
+
<span
|
|
3187
|
+
aria-hidden="true"
|
|
3188
|
+
style={{ color: proposal, fontSize: small }}
|
|
3189
|
+
>
|
|
3190
|
+
▾
|
|
3191
|
+
</span>
|
|
3192
|
+
</button>
|
|
3193
|
+
{proposalMenuOpen && change && change.proposals.length > 1 ? (
|
|
3194
|
+
<div
|
|
3195
|
+
role="listbox"
|
|
3196
|
+
aria-label="Proposals"
|
|
3197
|
+
style={{
|
|
3198
|
+
position: "absolute",
|
|
3199
|
+
top: "calc(100% + 6px)",
|
|
3200
|
+
left: "50%",
|
|
3201
|
+
transform: "translateX(-50%)",
|
|
3202
|
+
zIndex: 20,
|
|
3203
|
+
minWidth: 260,
|
|
3204
|
+
display: "grid",
|
|
3205
|
+
gap: 2,
|
|
3206
|
+
padding: 4,
|
|
3207
|
+
borderRadius: 6,
|
|
3208
|
+
border: `1px solid ${proposal}`,
|
|
3209
|
+
background:
|
|
3210
|
+
theme.colors.backgroundSecondary ?? theme.colors.background,
|
|
3211
|
+
boxShadow: "0 10px 28px rgba(0,0,0,0.4)",
|
|
3212
|
+
}}
|
|
3213
|
+
>
|
|
3214
|
+
{change.proposals.map((candidate, index) => {
|
|
3215
|
+
const selected = candidate.id === state.activeProposalId;
|
|
3216
|
+
return (
|
|
3217
|
+
<button
|
|
3218
|
+
key={candidate.id}
|
|
3219
|
+
type="button"
|
|
3220
|
+
role="option"
|
|
3221
|
+
aria-selected={selected}
|
|
3222
|
+
onClick={() => selectProposal(candidate.id)}
|
|
3223
|
+
style={{
|
|
3224
|
+
display: "flex",
|
|
3225
|
+
alignItems: "center",
|
|
3226
|
+
gap: 8,
|
|
3227
|
+
padding: "6px 8px",
|
|
3228
|
+
borderRadius: 4,
|
|
3229
|
+
border: "none",
|
|
3230
|
+
background: selected ? `${proposal}25` : "transparent",
|
|
3231
|
+
color: selected ? proposal : theme.colors.text,
|
|
3232
|
+
fontFamily: mono,
|
|
3233
|
+
fontSize: small,
|
|
3234
|
+
textAlign: "left",
|
|
3235
|
+
whiteSpace: "nowrap",
|
|
3236
|
+
cursor: "pointer",
|
|
3237
|
+
}}
|
|
3238
|
+
>
|
|
3239
|
+
<span style={{ color: proposal, minWidth: 12 }}>
|
|
3240
|
+
{index + 1}
|
|
3241
|
+
</span>
|
|
3242
|
+
<span>{candidate.name}</span>
|
|
3243
|
+
</button>
|
|
3244
|
+
);
|
|
3245
|
+
})}
|
|
3246
|
+
</div>
|
|
3247
|
+
) : null}
|
|
3248
|
+
</div>
|
|
3249
|
+
{activeProposal ? (
|
|
3250
|
+
<button
|
|
3251
|
+
type="button"
|
|
3252
|
+
onClick={openSourceForActive}
|
|
3253
|
+
aria-label="Open source model"
|
|
3254
|
+
style={{
|
|
3255
|
+
marginLeft: "auto",
|
|
3256
|
+
padding: "4px 10px",
|
|
3257
|
+
borderRadius: 4,
|
|
3258
|
+
border: `1px solid ${border}`,
|
|
3259
|
+
background: "transparent",
|
|
3260
|
+
color: muted,
|
|
3261
|
+
fontFamily: mono,
|
|
3262
|
+
fontSize: small,
|
|
3263
|
+
cursor: "pointer",
|
|
3264
|
+
whiteSpace: "nowrap",
|
|
3265
|
+
}}
|
|
3266
|
+
>
|
|
3267
|
+
Open source model
|
|
3268
|
+
</button>
|
|
3269
|
+
) : null}
|
|
3270
|
+
</header>
|
|
3271
|
+
);
|
|
3272
|
+
|
|
3273
|
+
return (
|
|
3274
|
+
<div
|
|
3275
|
+
style={{
|
|
3276
|
+
display: "flex",
|
|
3277
|
+
height: "100vh",
|
|
3278
|
+
background: theme.colors.background,
|
|
3279
|
+
}}
|
|
3280
|
+
>
|
|
3281
|
+
<style>{prototypeAnimationStyles}</style>
|
|
3282
|
+
{state.modelOpen ? (
|
|
3283
|
+
<div
|
|
3284
|
+
key={openingKey}
|
|
3285
|
+
className="agent-model-opening"
|
|
3286
|
+
style={{
|
|
3287
|
+
flex: 1,
|
|
3288
|
+
minWidth: 0,
|
|
3289
|
+
display: "flex",
|
|
3290
|
+
flexDirection: "column",
|
|
3291
|
+
}}
|
|
3292
|
+
>
|
|
3293
|
+
{header}
|
|
3294
|
+
<div style={{ flex: 1, minHeight: 0, position: "relative" }}>
|
|
3295
|
+
<SubsystemComponentGraph
|
|
3296
|
+
components={graphComponents}
|
|
3297
|
+
trails={graphTrails}
|
|
3298
|
+
focusedTrailStep={focusedTrailStep}
|
|
3299
|
+
proposedTrailIds={proposedTrailIds}
|
|
3300
|
+
proposedComponentAliases={proposedComponentAliases}
|
|
3301
|
+
workingComponentAliases={workingAliases}
|
|
3302
|
+
removedComponentAliases={
|
|
3303
|
+
state.view === "proposal"
|
|
3304
|
+
? synthetic.removedComponentAliases
|
|
3305
|
+
: undefined
|
|
3306
|
+
}
|
|
3307
|
+
stepHistory={
|
|
3308
|
+
state.view === "proposal" ? synthetic.stepHistory : undefined
|
|
3309
|
+
}
|
|
3310
|
+
canvasOverlay={agentStatusOverlay}
|
|
3311
|
+
trailFocusDurationMs={600}
|
|
3312
|
+
focusVerticalBiasPx={96}
|
|
3313
|
+
persistKey={persistKey}
|
|
3314
|
+
hideHeader
|
|
3315
|
+
title={title}
|
|
3316
|
+
graphTitle={
|
|
3317
|
+
state.view === "source"
|
|
3318
|
+
? "SOURCE SUBSYSTEM MODEL"
|
|
3319
|
+
: "SYNTHETIC CONTEXT MODEL"
|
|
3320
|
+
}
|
|
3321
|
+
showTrailTitle
|
|
3322
|
+
description={
|
|
3323
|
+
state.view === "source"
|
|
3324
|
+
? "Original trail context. Focus here never opens files; use the header to return to the change."
|
|
3325
|
+
: description
|
|
3326
|
+
}
|
|
3327
|
+
notes="**Prototype boundary:** the synthetic graph and proposal state are host-local. The source subsystem models stay untouched."
|
|
3328
|
+
/>
|
|
3329
|
+
</div>
|
|
3330
|
+
</div>
|
|
3331
|
+
) : (
|
|
3332
|
+
<div
|
|
3333
|
+
style={{
|
|
3334
|
+
flex: 1,
|
|
3335
|
+
minWidth: 0,
|
|
3336
|
+
background: theme.colors.background,
|
|
3337
|
+
}}
|
|
3338
|
+
/>
|
|
3339
|
+
)}
|
|
3340
|
+
|
|
3341
|
+
<aside
|
|
3342
|
+
style={{
|
|
3343
|
+
width: 390,
|
|
3344
|
+
flexShrink: 0,
|
|
3345
|
+
display: "flex",
|
|
3346
|
+
flexDirection: "column",
|
|
3347
|
+
borderLeft: `1px solid ${border}`,
|
|
3348
|
+
background: theme.colors.background,
|
|
3349
|
+
overflow: "hidden",
|
|
3350
|
+
}}
|
|
3351
|
+
>
|
|
3352
|
+
<header
|
|
3353
|
+
style={{
|
|
3354
|
+
padding: "14px 16px 10px",
|
|
3355
|
+
borderBottom: `1px solid ${border}`,
|
|
3356
|
+
}}
|
|
3357
|
+
>
|
|
3358
|
+
<div
|
|
3359
|
+
style={{
|
|
3360
|
+
fontFamily: mono,
|
|
3361
|
+
fontSize: body,
|
|
3362
|
+
color: theme.colors.text,
|
|
3363
|
+
}}
|
|
3364
|
+
>
|
|
3365
|
+
Agent tool stream
|
|
3366
|
+
</div>
|
|
3367
|
+
<p
|
|
3368
|
+
style={{
|
|
3369
|
+
margin: "6px 0 0",
|
|
3370
|
+
fontSize: small,
|
|
3371
|
+
lineHeight: 1.5,
|
|
3372
|
+
color: muted,
|
|
3373
|
+
}}
|
|
3374
|
+
>
|
|
3375
|
+
Step through the fake calls or play them like a live session.
|
|
3376
|
+
</p>
|
|
3377
|
+
<div style={{ display: "flex", gap: 6, marginTop: 10 }}>
|
|
3378
|
+
<button
|
|
3379
|
+
type="button"
|
|
3380
|
+
onClick={step}
|
|
3381
|
+
disabled={cursor >= events.length}
|
|
3382
|
+
style={{
|
|
3383
|
+
padding: "4px 10px",
|
|
3384
|
+
borderRadius: 4,
|
|
3385
|
+
border: `1px solid ${border}`,
|
|
3386
|
+
background:
|
|
3387
|
+
theme.colors.backgroundSecondary ?? theme.colors.background,
|
|
3388
|
+
color: theme.colors.text,
|
|
3389
|
+
fontFamily: mono,
|
|
3390
|
+
fontSize: small,
|
|
3391
|
+
cursor: cursor >= events.length ? "default" : "pointer",
|
|
3392
|
+
opacity: cursor >= events.length ? 0.5 : 1,
|
|
3393
|
+
}}
|
|
3394
|
+
>
|
|
3395
|
+
Next tool call
|
|
3396
|
+
</button>
|
|
3397
|
+
<button
|
|
3398
|
+
type="button"
|
|
3399
|
+
onClick={() => setPlaying((prev) => !prev)}
|
|
3400
|
+
disabled={cursor >= events.length && !playing}
|
|
3401
|
+
style={{
|
|
3402
|
+
padding: "4px 10px",
|
|
3403
|
+
borderRadius: 4,
|
|
3404
|
+
border: `1px solid ${accent}`,
|
|
3405
|
+
background: `${accent}18`,
|
|
3406
|
+
color: accent,
|
|
3407
|
+
fontFamily: mono,
|
|
3408
|
+
fontSize: small,
|
|
3409
|
+
fontWeight: 600,
|
|
3410
|
+
cursor: "pointer",
|
|
3411
|
+
}}
|
|
3412
|
+
>
|
|
3413
|
+
{playing ? "Pause" : "Play"}
|
|
3414
|
+
</button>
|
|
3415
|
+
<button
|
|
3416
|
+
type="button"
|
|
3417
|
+
onClick={reset}
|
|
3418
|
+
style={{
|
|
3419
|
+
padding: "4px 10px",
|
|
3420
|
+
borderRadius: 4,
|
|
3421
|
+
border: `1px solid ${border}`,
|
|
3422
|
+
background: "transparent",
|
|
3423
|
+
color: muted,
|
|
3424
|
+
fontFamily: mono,
|
|
3425
|
+
fontSize: small,
|
|
3426
|
+
cursor: "pointer",
|
|
3427
|
+
}}
|
|
3428
|
+
>
|
|
3429
|
+
Reset
|
|
3430
|
+
</button>
|
|
3431
|
+
<button
|
|
3432
|
+
type="button"
|
|
3433
|
+
onClick={animateOpening}
|
|
3434
|
+
style={{
|
|
3435
|
+
padding: "4px 10px",
|
|
3436
|
+
borderRadius: 4,
|
|
3437
|
+
border: `1px solid ${border}`,
|
|
3438
|
+
background: "transparent",
|
|
3439
|
+
color: muted,
|
|
3440
|
+
fontFamily: mono,
|
|
3441
|
+
fontSize: small,
|
|
3442
|
+
cursor: "pointer",
|
|
3443
|
+
}}
|
|
3444
|
+
>
|
|
3445
|
+
Animate opening
|
|
3446
|
+
</button>
|
|
3447
|
+
</div>
|
|
3448
|
+
<div style={{ marginTop: 8, fontSize: small, color: muted }}>
|
|
3449
|
+
{cursor} / {events.length} calls replayed
|
|
3450
|
+
</div>
|
|
3451
|
+
</header>
|
|
3452
|
+
|
|
3453
|
+
<div
|
|
3454
|
+
style={{
|
|
3455
|
+
flex: 1,
|
|
3456
|
+
minHeight: 0,
|
|
3457
|
+
overflow: "auto",
|
|
3458
|
+
padding: "12px 16px",
|
|
3459
|
+
display: "grid",
|
|
3460
|
+
gap: 8,
|
|
3461
|
+
alignContent: "start",
|
|
3462
|
+
}}
|
|
3463
|
+
>
|
|
3464
|
+
{events.slice(0, cursor).map((event) => (
|
|
3465
|
+
<ToolRow key={event.id} event={event} />
|
|
3466
|
+
))}
|
|
3467
|
+
</div>
|
|
3468
|
+
</aside>
|
|
3469
|
+
</div>
|
|
3470
|
+
);
|
|
3471
|
+
}
|
|
3472
|
+
|
|
2004
3473
|
export const Walkthrough: Story = {
|
|
2005
3474
|
render: () => (
|
|
2006
3475
|
<Prototype
|
|
@@ -2077,3 +3546,25 @@ export const ComponentProposalDeclined: Story = {
|
|
|
2077
3546
|
/>
|
|
2078
3547
|
),
|
|
2079
3548
|
};
|
|
3549
|
+
|
|
3550
|
+
export const MultiProposalChange: Story = {
|
|
3551
|
+
render: () => (
|
|
3552
|
+
<MultiProposalPrototype
|
|
3553
|
+
events={multiProposalEvents}
|
|
3554
|
+
title="Refund handling · synthetic change"
|
|
3555
|
+
persistKey="agent-driven-multi-proposal-change-prototype"
|
|
3556
|
+
description="One change groups three proposals from Booking and Payments. Click the header name to choose a proposal from the dropdown; source models open only through explicit agent steps or the header control."
|
|
3557
|
+
/>
|
|
3558
|
+
),
|
|
3559
|
+
};
|
|
3560
|
+
|
|
3561
|
+
export const MultiProposalChangeDeclined: Story = {
|
|
3562
|
+
render: () => (
|
|
3563
|
+
<MultiProposalPrototype
|
|
3564
|
+
events={multiProposalDeclinedEvents}
|
|
3565
|
+
title="Refund handling · declined change"
|
|
3566
|
+
persistKey="agent-driven-multi-proposal-change-declined-prototype"
|
|
3567
|
+
description="The same three proposals are declined as one change, so the synthetic model keeps its original source trails and components."
|
|
3568
|
+
/>
|
|
3569
|
+
),
|
|
3570
|
+
};
|