internal/core/adt: exclude definitions in data conversion

Definitions incorrectly trigger closedness for sub structures.
They also don't belong in data.

IMPORTANT: this implies that it is no longer possible to
refer to definitions from within tool files. As a workaround
we will allow it still for single-instance commands.

Fixes #525

Change-Id: I481dd16e7cacb1096f68d446ce1c5349b5cd4531
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/7143
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.org.uk>
diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go
index 0b03a1c..aa47081 100644
--- a/cmd/cue/cmd/common.go
+++ b/cmd/cue/cmd/common.go
@@ -605,7 +605,12 @@
 		return nil, err
 	}
 
-	inst := cue.Merge(insts...).Build(ti)
+	inst := insts[0]
+	if len(insts) > 1 {
+		inst = cue.Merge(insts...)
+	}
+
+	inst = inst.Build(ti)
 	return inst, inst.Err
 }
 
diff --git a/cmd/cue/cmd/testdata/script/issue525.txt b/cmd/cue/cmd/testdata/script/issue525.txt
new file mode 100644
index 0000000..234662a
--- /dev/null
+++ b/cmd/cue/cmd/testdata/script/issue525.txt
@@ -0,0 +1,29 @@
+cue cmd gengithub
+
+-- x.cue --
+package x
+
+test: #Workflow & {
+}
+
+#Workflow: {
+	#: "working-directory": string
+}
+-- x_tool.cue --
+package x
+
+import (
+ "tool/file"
+ "encoding/yaml"
+)
+
+command: gengithub: {
+ write: file.Create & {
+  filename: "test.yml"
+  contents: """
+   # Generated by ci_tool.cue; do not edit
+
+   \(yaml.Marshal(test))
+   """
+ }
+}
\ No newline at end of file
diff --git a/internal/core/adt/composite.go b/internal/core/adt/composite.go
index 5dfaa12..c68c5b5 100644
--- a/internal/core/adt/composite.go
+++ b/internal/core/adt/composite.go
@@ -274,9 +274,11 @@
 // ToDataAll returns a new v where v and all its descendents contain only
 // the regular fields.
 func (v *Vertex) ToDataAll() *Vertex {
-	arcs := make([]*Vertex, len(v.Arcs))
-	for i, a := range v.Arcs {
-		arcs[i] = a.ToDataAll()
+	arcs := make([]*Vertex, 0, len(v.Arcs))
+	for _, a := range v.Arcs {
+		if a.Label.IsRegular() {
+			arcs = append(arcs, a.ToDataAll())
+		}
 	}
 	w := *v