 
 (defn rules->plan [rules]
   (add-rules empty-flow-plan rules))
-
 
 (comment
   (deffact edge "[x] has an edge to [y]")
   (deffact connected "[x] is connected to [y]")
 
-  (let [plan (add-rules empty-flow-plan
-                        [(Rule. [(Recall. :known&pretended (->edge 'x 'y))
-                                 (Output. :remembered (->connected 'x 'y))])
-                         (Rule. [(Recall. :known&pretended (->edge 'x 'y))
-                                 (Recall. :known&pretended (->connected 'y 'z))
-                                 (Output. :remembered (->connected 'x 'z))])])
+  (let [plan (-> empty-flow-plan
+                 (add-shape :known edge)
+                 (add-shape :known connected)
+                 (add-rules
+                  [(Rule. [(Recall. :known|pretended (->edge 'x 'y))
+                           (Output. :remembered (->connected 'x 'y))])
+                   (Rule. [(Recall. :known|pretended (->edge 'x 'y))
+                           (Recall. :known|pretended (->connected 'y 'z))
+                           (Output. :remembered (->connected 'x 'z))])]))
         state-0 (flow-plan->flow-state plan)]
-    (add-facts state-0 :known #js [(->edge 0 1) (->edge 1 2) (->edge 2 3) (->edge 3 1)])
+    (add-facts state-0 :known|pretended edge #js [(->edge 0 1) (->edge 1 2) (->edge 2 3) (->edge 3 1)])
   (fixpoint! state-0)
   (for [state (take 5 (iterate #(tick&fixpoint plan %) state-0))]
-    (count (get-facts state :known))))
-
-  (let [rules [(Rule. [
-                       (aurora.language.Recall. :known&pretended, (js/aurora.language.fact :http/response #js ['content "google" 'some]))
-                       (aurora.language.Output. :remembered (js/aurora.language.fact "1df7454c_069e_40ab_b117_b8d43212b473" #js ['value74]))
-                       (aurora.language.Output. :forgotten (js/aurora.language.fact "1df7454c_069e_40ab_b117_b8d43212b473" #js ['value]))
-                       (aurora.language.Recall. :known&pretended, (js/aurora.language.fact "1df7454c_069e_40ab_b117_b8d43212b473" #js ['value]))
-                       (aurora.language.Compute. (->Let 'value74  #{'value} "value + \"hey\""))])]
-        plan (add-rules empty-flow-plan rules)
-        state (flow-plan->flow-state plan)]
-    (add-facts state :known [(fact. "1df7454c_069e_40ab_b117_b8d43212b473" #js ["Click me"])])
-    (add-facts state :pretended [(fact. :http/response #js ["yo" "google" 1234])])
-    (fixpoint! state)
-    (-> state
-        (get-facts :known)
-        first
-        (.-values))
-  )
-
-  (let [rules [(Rule. [
-                       (aurora.language.Recall. :known&pretended, (js/aurora.language.fact :http/response #js ['content "google" 'tim]))
-                       (aurora.language.Output. :remembered (js/aurora.language.fact "1df7454c_069e_40ab_b117_b8d43212b473" #js ['value74]))
-                       (aurora.language.Output. :forgotten (js/aurora.language.fact "1df7454c_069e_40ab_b117_b8d43212b473" #js ['value]))
-                       (aurora.language.Recall. :known&pretended, (js/aurora.language.fact "1df7454c_069e_40ab_b117_b8d43212b473" #js ['value]))
-                       (aurora.language.Compute. (->Let 'value74  #{'value 'content} "value + \" hey \" + content"))])]
-        plan (add-rules empty-flow-plan rules)
-        state (flow-plan->flow-state plan)]
-    (add-facts state :known [(fact. "1df7454c_069e_40ab_b117_b8d43212b473" #js ["Click me"])])
-    (add-facts state :pretended [(fact. :http/response #js ["yo" "google" 1234])])
-    (fixpoint! state)
-    (map #(.-values %)
-         (-> state
-             (get-facts :remembered)))
-    )
+    (count (get-facts state :known|pretended connected))))
   )
 
 ;; RESOLVE

                Lookup (lookup-update! (:index-node flow) (:key-ixes flow) (:val-ixes flow))))))
    (FlowState. node->state node->out-nodes node->facts node->update! trace plan)))

(defn memory->node [memory]
  (case memory
    :known 0
    :pretended 1
    :remembered 2
    :forgotten 3))

(defn memory->nodes [memory]
  (case memory
    :known [0]
    :pretended [1]
    :remembered [2]
    :forgotten [3]
    :known&pretended [0 1]))

(def empty-flow-plan
  (FlowPlan. [(Union. #{}) (Union. #{}) (Union. #{}) (Union. #{})] {}))

(defn add-output [flow-plan node memory]
  (update-in flow-plan [:node->flow (memory->node memory) :nodes] conj node))

(defn add-flow [{:keys [node->flow flow->node] :as flow-plan} flow]
  (if-let [node (flow->node flow)]
    [flow-plan node]
    (let [node (count node->flow)
          node->flow (conj node->flow flow)
          flow->node (assoc flow->node flow node)]
      [(FlowPlan. node->flow flow->node) node])))

;; IXES



;; FLOW PLAN

(defrecord FlowPlan [node->flow flow->node memory->shape->node kind->shape])

(defn flow-plan->flow-state [{:keys [node->flow] :as plan}]
  (let [node->state (into-array (for [_ node->flow] nil))
        node->out-nodes (into-array (for [_ node->flow] #js []))
        node->facts (into-array (for [_ node->flow] #js []))
