loopengine 0.5.9 → 0.5.11

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.
@@ -11,181 +11,189 @@
11
11
  // literal.
12
12
  import { devUiCss } from './dev-ui-styles.js';
13
13
  import { consoleShellScript, consoleSidebarHtml } from './console-shell.js';
14
+ import { MASCOT_CSS, mascotSvg } from './mascot.js';
14
15
  const goalsPageTemplate = `<!doctype html>
15
16
  <html lang="en">
16
17
  <head>
17
18
  <meta charset="utf-8">
18
19
  <meta name="viewport" content="width=device-width, initial-scale=1">
19
20
  <title>Goals</title>
20
- <style>${devUiCss}
21
- .gl { max-width: 880px; display: grid; gap: 18px; }
22
- .gl-card { border: 1px solid var(--line); border-radius: 12px; background: var(--bg); padding: 16px 18px; display: grid; gap: 10px; }
23
- .gl textarea { width: 100%; box-sizing: border-box; min-height: 64px; font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); resize: vertical; }
21
+ <style>${devUiCss}${MASCOT_CSS}
22
+ .gl { max-width: 1120px; display: grid; gap: 0; }
23
+ .gl textarea { width: 100%; box-sizing: border-box; min-height: 64px; font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); resize: vertical; }
24
24
  .gl textarea:focus, .gl select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
25
25
  .gl-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
26
- .gl-btn { height: 34px; padding: 0 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary); cursor: pointer; }
27
- .gl-btn:hover:not(:disabled) { filter: brightness(1.08); background: var(--primary); }
26
+ .gl-btn { height: 34px; padding: 0 14px; border-radius: 9px; font-size: 13.5px; font-weight: 600; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary); cursor: pointer; }
27
+ .gl-btn:hover:not(:disabled) { opacity: .88; background: var(--primary); }
28
+ .gl-btn.small { height: 30px; font-size: 13px; padding: 0 12px; }
28
29
  .gl-btn.soft { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
29
- .gl-btn.soft:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); filter: none; }
30
- .gl-btn.plain { background: none; border-color: var(--line); color: var(--ink); font-weight: 500; }
31
- .gl-btn.danger { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
32
- .gl-link { background: none; border: 0; padding: 0; color: var(--accent-ink); font-size: 13px; cursor: pointer; font-weight: 500; }
33
- .gl-goal-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
34
- .gl-focus { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-muted); }
35
- .gl-focus select { font: inherit; font-size: 13px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
36
- .gl-section { display: grid; gap: 10px; }
37
- .gl-section h3 { margin: 6px 0 0; font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-muted); display: flex; gap: 8px; align-items: center; }
38
- .gl-count { font-size: 11px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); letter-spacing: 0; }
39
- .gl-wf { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: grid; gap: 8px; background: var(--bg); }
40
- .gl-wf.built { border-color: var(--good); }
41
- .gl-wf-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; justify-content: space-between; }
42
- .gl-wf-title { font-size: 15px; font-weight: 650; }
43
- .gl-agent { font-size: 12.5px; color: var(--ink-muted); }
44
- .gl-agent strong { color: var(--ink); font-weight: 600; font-family: var(--font-mono); font-size: 12px; }
45
- .gl-new { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); margin-right: 4px; }
46
- .gl-why { margin: 0; font-size: 14px; color: var(--ink); }
47
- .gl-needs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
48
- .gl-need { padding: 1px 8px; border-radius: 6px; background: var(--surface); border: 1px solid var(--line); }
49
- .gl-need.ok { background: var(--good-soft); color: var(--good); border-color: transparent; }
50
- .gl-need.missing { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
51
- .gl-wf details summary { cursor: pointer; font-size: 12.5px; color: var(--ink-muted); }
52
- .gl-wf details p { margin: 6px 0 0; font-size: 13px; white-space: pre-wrap; background: var(--surface); padding: 8px 10px; border-radius: 6px; }
53
- .gl-state { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; }
54
- .gl-state.saved { background: var(--accent-soft); color: var(--accent-ink); }
55
- .gl-state.built { background: var(--good-soft); color: var(--good); }
56
- .gl-job { padding: 0; gap: 0; }
57
- .gl-job-head { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; border-radius: 10px; }
58
- .gl-job-head:hover { background: var(--surface); }
59
- .gl-job-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
60
- .gl-caret { width: 7px; height: 7px; border-right: 2px solid var(--ink-muted); border-bottom: 2px solid var(--ink-muted); transform: rotate(-45deg); transition: transform .15s; }
61
- .gl-job.is-open .gl-caret { transform: rotate(45deg); }
62
- .gl-job-detail .gl-job-head { grid-template-columns: minmax(0, 1fr) auto auto; cursor: default; }
63
- .gl-job-detail .gl-job-head:hover { background: none; }
64
- .gl-job-detail .gl-wf-title { font-size: 17px; }
65
- .gl-job-detail .gl-job-body, .gl-job-detail .gl-job-status-line { padding-left: 14px; }
66
- .gl-job-link { color: inherit; text-decoration: none; }
67
- .gl-define { margin: 0; max-width: 72ch; }
68
- .gl-doneby { display: grid; gap: 3px; justify-items: start; font-size: 13px; margin-top: 4px; }
69
- .gl-doneby-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
70
- .gl-doneby-row a { color: var(--ink); font-weight: 600; }
71
- .gl-slug { font-family: var(--font-mono); font-size: 12.5px; font-weight: 500; background: var(--code-bg); padding: 1px 6px; border-radius: 4px; }
72
- .gl-tag-wf { font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink); }
73
- .gl-doneby-then { font-size: 12px; color: var(--ink-muted); padding-left: 4px; }
74
- .gl-agent-pill { font-size: 11.5px; font-weight: 600; padding: 0 7px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); }
75
- .gl-doneby-manage { font-size: 12.5px; color: var(--accent-ink); }
76
- .gl-job-link:hover { text-decoration: underline; }
77
- .gl-job-main { display: grid; gap: 3px; min-width: 0; }
78
- .gl-job-sub { display: flex; gap: 8px; align-items: center; min-width: 0; font-size: 12.5px; color: var(--ink-muted); }
79
- .gl-job-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
80
- .gl-job-from { display: block; margin-top: 2px; font-size: 12px; color: var(--ink-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
81
- .gl-job-from a { color: var(--accent-ink); }
82
- .gl-listed { font-size: 12px; font-weight: 600; color: var(--accent-ink); white-space: nowrap; }
83
- .gl-job-primary { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
84
- .gl-push { margin-left: auto; }
85
- .gl-job-status { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
86
- .gl-job-primary .gl-btn { height: 30px; font-size: 13px; padding: 0 12px; }
87
- .gl-job-body { display: grid; gap: 10px; padding: 2px 16px 14px 40px; }
88
- .gl-job-body[hidden] { display: none; }
89
- .gl-job-measure { margin: 0; font-size: 13px; color: var(--ink-muted); }
90
- .gl-job-status-line:empty { display: none; }
91
- .gl-job-status-line { padding: 0 16px 10px 40px; }
92
- @media (max-width: 560px) { .gl-job-head { grid-template-columns: 12px minmax(0, 1fr); } .gl-job-status, .gl-job-primary { grid-column: 2; } .gl-job-body, .gl-job-status-line { padding-left: 16px; } }
93
- .gl-job-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 12.5px; color: var(--ink-muted); }
94
- .gl-kind { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-muted); }
95
- .gl-kind.group { background: var(--accent-soft); color: var(--accent-ink); }
96
- .gl-gsteps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
97
- .gl-gstep { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
98
- .gl-gstep.built { border-color: var(--good-soft); }
99
- .gl-gstep-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 13.5px; }
100
- .gl-gstep-n { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); color: var(--ink-muted); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
101
- .gl-gstep.built .gl-gstep-n { background: var(--good-soft); color: var(--good); }
102
- .gl-gstep-build { margin-left: auto; }
103
- .gl-gstep-then { font-size: 12px; color: var(--ink-muted); padding: 6px 0 0 32px; margin-bottom: -4px; }
104
- .gl-gstep + .gl-gstep { margin-top: 8px; }
105
- .gl-order summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent-ink); }
106
- .gl-doer { font-size: 13px; color: var(--ink-muted); }
107
- .gl-doer strong { color: var(--ink); font-family: var(--font-mono); font-size: 12px; }
30
+ .gl-btn.soft:hover:not(:disabled) { background: var(--accent); color: var(--on-accent); opacity: 1; }
31
+ .gl-btn.plain { background: var(--bg); border-color: var(--line); color: var(--ink); font-weight: 500; }
32
+ .gl-btn.plain:hover:not(:disabled) { background: var(--surface); opacity: 1; }
33
+ .gl-link { background: none; border: 0; padding: 0; height: auto; color: var(--accent-ink); font-size: 13px; cursor: pointer; font-weight: 500; }
108
34
  .gl-link-btn { display: inline-flex; align-items: center; text-decoration: none; }
109
- .gl-how { display: grid; gap: 6px; }
110
- .gl-how-head { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
111
- .gl-how-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; }
112
- .gl-how-main { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; min-width: 0; }
113
- .gl-how-wf { font-weight: 600; font-size: 13.5px; }
114
- .gl-how-agent { font-size: 12.5px; color: var(--ink-muted); }
115
- .gl-how-agent strong { color: var(--ink); font-family: var(--font-mono); font-size: 12px; font-weight: 500; }
116
- .gl-how-meta { grid-column: 1; font-size: 12.5px; color: var(--ink-muted); }
117
- .gl-how-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 10px; align-items: center; }
118
- .gl-how-open { font-size: 13px; font-weight: 600; color: var(--accent-ink); text-decoration: none; }
119
- .gl-chain { display: grid; gap: 4px; }
120
- .gl-step { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; justify-content: space-between; font-size: 13px; padding: 6px 10px; border-left: 2px solid var(--accent); background: var(--surface); border-radius: 0 6px 6px 0; }
121
- .gl-panel { display: grid; gap: 8px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; }
122
- .gl-panel[hidden] { display: none; }
35
+ .gl-select { font: inherit; font-size: 13px; height: 30px; padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); }
123
36
  .gl-input { font: inherit; font-size: 13px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
124
37
  .gl-input[hidden] { display: none; }
125
- .gl-step-inputs { display: grid; gap: 6px; }
126
- .gl-how-open:hover { text-decoration: underline; }
38
+ .gl-crumb { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 15px; }
39
+ .gl-crumb a { color: var(--ink-muted); text-decoration: none; font-weight: 600; }
40
+ .gl-crumb a:hover { color: var(--ink); }
41
+ .gl-crumb span { color: var(--ink); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
42
+ .gl-new-btn { text-decoration: none; }
43
+ .gl-new-btn[hidden], .le-search[hidden] { display: none; }
44
+ /* The top of each view: a big, light title, a line under it, the mascot. */
45
+ .gl-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; padding: 36px 32px 28px; border: 1px solid var(--line); border-bottom: 0; }
46
+ .gl-hero .le-mascot { flex: none; margin-bottom: -6px; filter: drop-shadow(0 8px 10px rgba(0, 0, 0, .12)); }
47
+ .gl-hero-text { display: grid; gap: 10px; min-width: 0; }
48
+ .gl-eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-faint); }
49
+ .gl-display { margin: 0; font-size: 32px; line-height: 1.18; font-weight: 400; letter-spacing: -0.025em; color: var(--ink); overflow-wrap: anywhere; }
50
+ .gl-hero-sub { margin: 0; font-size: 15px; line-height: 1.5; color: var(--ink-muted); max-width: 70ch; }
51
+ .gl-section-title { margin: 0; padding: 30px 32px 16px; font-size: 22px; font-weight: 400; letter-spacing: -0.02em; border-left: 1px solid var(--line); border-right: 1px solid var(--line); display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
52
+ .gl-section-title .hint { font-size: 13px; letter-spacing: 0; }
53
+ .gl-cols2 { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: row dense; }
54
+ .gl-cols3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
55
+ .gl-cols1 { grid-template-columns: minmax(0, 1fr); }
56
+ .gl-wide { grid-column: 1 / -1; }
57
+ .gl-cell { padding: 20px 22px; background: var(--bg); display: grid; gap: 14px; align-content: start; }
58
+ .gl-filler { background: var(--bg); }
59
+ /* Chips, as on Schedules. */
60
+ .gl-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
61
+ .gl-chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line); font-size: 12px; color: var(--ink-muted); white-space: nowrap; text-decoration: none; background: var(--bg); }
62
+ .gl-chip.strong { background: var(--surface); border-color: transparent; color: var(--ink); font-weight: 500; }
63
+ .gl-chip.good { background: var(--good-soft); border-color: transparent; color: var(--good); font-weight: 600; }
64
+ .gl-chip.warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); font-weight: 600; }
65
+ .gl-chip.bad { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
66
+ .gl-chip.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-ink); font-weight: 600; }
67
+ .gl-chip[hidden] { display: none; }
68
+ .gl-chip .gl-select { height: 22px; border: 0; padding: 0 2px; background: none; font-weight: 500; }
69
+ .gl-chip-k { color: var(--ink-faint); font-weight: 400; }
70
+ .gl-next { font-size: 12px; color: var(--ink-faint); margin-left: 4px; white-space: nowrap; }
71
+ /* A card: an icon, its title and a line or two, and what to do. */
72
+ .gl-card-head { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: start; }
73
+ .gl-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); color: var(--ink-muted); box-shadow: 0 1px 2px rgba(0, 0, 0, .05); background: var(--bg); }
74
+ .gl-icon svg { width: 16px; height: 16px; }
75
+ .gl-icon.good { color: var(--good); }
76
+ .gl-card-text { display: grid; gap: 3px; min-width: 0; }
77
+ .gl-card-kind { font-size: 11.5px; font-weight: 600; color: var(--ink-faint); }
78
+ .gl-card-title { font-size: 15px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; line-height: 1.35; }
79
+ .gl-card-desc { font-size: 13px; line-height: 1.5; color: var(--ink-muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
80
+ .gl-card-side { display: flex; gap: 8px; align-items: center; }
81
+ a.gl-cell { text-decoration: none; color: inherit; transition: background .15s; }
82
+ a.gl-cell:hover { background: var(--surface); }
83
+ .gl-cell.discarded .gl-card-text { opacity: .6; }
84
+ .gl-menu { position: relative; }
85
+ .gl-menu summary { list-style: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; cursor: pointer; color: var(--ink-muted); }
86
+ .gl-menu summary::-webkit-details-marker { display: none; }
87
+ .gl-menu summary:hover { background: var(--surface); color: var(--ink); }
88
+ .gl-menu[open] .gl-menu-list { display: grid; }
89
+ .gl-menu-list { display: none; position: absolute; right: 0; top: 32px; z-index: 20; min-width: 170px; padding: 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); box-shadow: 0 8px 24px rgba(0, 0, 0, .12); }
90
+ .gl-menu-list a, .gl-menu-list button { display: block; width: 100%; text-align: left; height: auto; padding: 7px 10px; border: 0; border-radius: 7px; background: none; font-size: 13px; font-weight: 400; color: var(--ink); text-decoration: none; cursor: pointer; }
91
+ .gl-menu-list a:hover, .gl-menu-list button:hover:not(:disabled) { background: var(--surface); }
92
+ .gl-what summary { cursor: pointer; font-size: 13px; color: var(--accent-ink); font-weight: 600; }
93
+ .gl-what p { margin: 8px 0 0; font-size: 13.5px; line-height: 1.5; white-space: pre-wrap; background: var(--surface); padding: 10px 12px; border-radius: 8px; }
94
+ .gl-card-foot { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
95
+ /* The goal's numbers. */
96
+ .gl-stat { padding: 20px 22px; background: var(--bg); display: grid; gap: 2px; }
97
+ .gl-stat b { font-size: 34px; font-weight: 400; letter-spacing: -0.02em; line-height: 1.1; color: var(--ink); }
98
+ .gl-stat span { font-size: 13px; color: var(--ink-muted); }
99
+ .gl-stat.attn b { color: var(--warn); }
100
+ /* Before you start: one step a cell. */
101
+ .gl-setup-step { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 12px; align-items: start; padding: 16px 22px; background: var(--bg); font-size: 13.5px; line-height: 1.5; }
102
+ .gl-setup-n { width: 24px; height: 24px; border-radius: 50%; background: var(--surface); color: var(--ink-muted); font-size: 12px; font-weight: 600; display: grid; place-items: center; }
103
+ /* A built workflow's workflows, in the order they run. */
104
+ .gl-flows { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
105
+ .gl-flow { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; background: var(--bg); }
106
+ .gl-flow + .gl-flow { border-top: 1px solid var(--line); }
107
+ .gl-flow-n { width: 24px; height: 24px; border-radius: 50%; background: var(--surface); color: var(--ink-muted); font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; align-self: start; margin-top: 1px; }
108
+ .gl-flow.built .gl-flow-n { background: var(--good-soft); color: var(--good); }
109
+ .gl-flow-main { display: grid; gap: 4px; min-width: 0; justify-items: start; }
110
+ .gl-flow-title { font-size: 14px; font-weight: 600; color: var(--ink); text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
111
+ a.gl-flow-title:hover { text-decoration: underline; }
112
+ .gl-flow-meta { font-size: 12.5px; color: var(--ink-muted); line-height: 1.45; }
113
+ .gl-flow-actions { display: flex; gap: 12px; align-items: center; }
114
+ .gl-flow-actions .gl-unlink { color: var(--ink-faint); font-size: 12.5px; }
115
+ .gl-flow-actions .gl-unlink:hover { color: var(--bad); }
116
+ .gl-flow-then { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; padding: 6px 14px 6px 50px; font-size: 12.5px; color: var(--ink-muted); background: var(--surface); border-top: 1px solid var(--line); }
117
+ .gl-flow-then .gl-link { font-size: 12px; color: var(--ink-faint); }
118
+ .gl-paused { font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; background: var(--surface); color: var(--ink-muted); }
127
119
  .gl-waiting { color: var(--warn); font-weight: 600; }
120
+ .gl-needs { display: contents; }
121
+ .gl-new { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
122
+ .gl-panel { display: grid; gap: 8px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; }
123
+ .gl-panel[hidden] { display: none; }
124
+ .gl-step-inputs { display: grid; gap: 6px; }
128
125
  [data-attn][hidden] { display: none; }
129
- .gl-add { display: grid; gap: 8px; }
130
- .gl-add-form { display: grid; gap: 6px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 10px; }
131
- .gl-add-form[hidden], #glAddToggle[hidden] { display: none; }
132
- #glAddToggle { justify-self: start; }
133
- .gl-notice { display: grid; gap: 4px; padding: 10px 14px; border-radius: 10px; font-size: 13.5px; }
126
+ .gl-job-status-line:empty { display: none; }
127
+ /* Tiles that do something: suggest more, add your own. */
128
+ .gl-tile { display: grid; gap: 6px; align-content: start; padding: 22px; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-radius: 0; background: var(--bg); text-align: left; height: auto; cursor: pointer; transition: background .15s; font: inherit; color: inherit; text-decoration: none; }
129
+ .gl-tile:hover:not(:disabled) { background: var(--surface); }
130
+ .gl-tile:disabled { cursor: default; opacity: .6; }
131
+ .gl-tile b { font-size: 15px; font-weight: 600; color: var(--ink); }
132
+ .gl-tile span { font-size: 13px; color: var(--ink-muted); line-height: 1.45; }
133
+ .gl-add-form { display: grid; gap: 8px; padding: 20px 22px; background: var(--bg); }
134
+ .gl-add-form[hidden] { display: none; }
135
+ .gl-notice { display: grid; gap: 4px; padding: 12px 22px; font-size: 13.5px; }
134
136
  .gl-notice.good { background: var(--good-soft); }
135
137
  .gl-notice.warn { background: var(--warn-soft); }
136
138
  .gl-notice.bad { background: var(--bad-soft); }
137
- .gl-try { display: grid; gap: 6px; padding: 10px 12px; border-radius: 8px; background: var(--surface); }
138
- .gl-try + .gl-try { margin-top: 6px; }
139
- .gl-result { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13.5px; line-height: 1.55; max-height: 360px; overflow: auto; padding: 10px 12px; border-radius: 8px; background: var(--bg); border: 1px solid var(--line); }
140
- .gl-result-wrap summary { cursor: pointer; font-size: 12.5px; color: var(--ink-muted); }
141
- .gl-again { display: grid; gap: 6px; }
142
- .gl-again[hidden] { display: none; }
143
- .gl-setup { margin: 0; padding-left: 18px; font-size: 13.5px; display: grid; gap: 4px; }
144
- .gl-setup-more { margin-top: 4px; font-size: 13px; }
145
- .gl-setup-more summary { cursor: pointer; color: var(--accent-ink); font-weight: 600; }
146
- .gl-setup-more .gl-setup { margin-top: 4px; }
147
- .gl-select { font: inherit; font-size: 13px; padding: 3px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
148
- .gl-examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
149
- .gl-example { font: inherit; font-size: 12.5px; color: var(--accent-ink); background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; cursor: pointer; }
150
- .gl-example:hover { border-color: var(--accent-ink); }
139
+ .gl-discarded-note { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 14px 22px; background: var(--surface); font-size: 13.5px; border: 1px solid var(--line); border-bottom: 0; }
140
+ .gl-empty { padding: 36px 32px; text-align: center; color: var(--ink-muted); font-size: 14px; background: var(--bg); margin: 0; }
141
+ .gl-foot { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; padding: 22px 2px 0; }
142
+ .gl-foot .gl-danger { color: var(--bad); }
143
+ .gl-status { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 14px; color: var(--ink-muted); }
144
+ .gl-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: gl-spin .8s linear infinite; }
145
+ @keyframes gl-spin { to { transform: rotate(360deg); } }
146
+ /* A new goal, in a dialog like Create schedule. */
147
+ .gl-dialog { width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--bg); color: var(--ink); box-shadow: 0 24px 60px rgba(0, 0, 0, .22); overflow: hidden; }
148
+ .gl-dialog::backdrop { background: rgba(20, 24, 25, .35); backdrop-filter: blur(3px); }
149
+ .gl-dialog form { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; max-height: calc(100vh - 50px); }
150
+ .gl-dlg-head { display: flex; align-items: center; gap: 8px; padding: 16px 22px; border-bottom: 1px solid var(--line); }
151
+ .gl-dlg-head h2 { margin: 0 auto 0 0; font-size: 18px; font-weight: 500; }
152
+ .gl-dlg-head button { height: 34px; padding: 0 14px; border-radius: 9px; font-size: 13px; }
153
+ .gl-dlg-body { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); overflow: auto; }
154
+ .gl-dlg-col { display: grid; align-content: start; }
155
+ .gl-dlg-col + .gl-dlg-col { border-left: 1px solid var(--line); background: var(--surface); }
156
+ .gl-field { display: grid; gap: 10px; padding: 18px 22px; }
157
+ .gl-field-k { font-size: 14px; font-weight: 500; color: var(--ink); }
158
+ .gl-dialog textarea { min-height: 110px; background: var(--bg); }
159
+ .gl-dlg-foot { padding: 12px 22px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-muted); min-height: 46px; display: flex; align-items: center; }
160
+ .gl-dlg-foot:has(span:empty) { display: none; }
161
+ .gl-about { display: grid; gap: 8px; margin-top: 8px; }
162
+ @media (max-width: 860px) { .gl-dlg-body { grid-template-columns: minmax(0, 1fr); } .gl-dlg-col + .gl-dlg-col { border-left: 0; border-top: 1px solid var(--line); } }
163
+ /* A new goal. */
164
+ .gl-form { padding: 24px 26px; background: var(--bg); display: grid; gap: 12px; }
165
+ .gl-examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
166
+ .gl-example { font: inherit; font-size: 12.5px; height: 28px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 0 10px; cursor: pointer; }
167
+ .gl-example:hover { border-color: var(--ink-faint); background: var(--surface); }
151
168
  .gl-share { display: flex; gap: 8px; align-items: flex-start; margin-top: 8px; line-height: 1.45; }
152
169
  .gl-share input { margin-top: 2px; }
153
- .gl-discarded-note { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; border-radius: 10px; background: var(--surface); font-size: 13.5px; }
154
- .gl-discarded-note .gl-btn { height: 28px; font-size: 12.5px; }
155
- .gl-empty { font-size: 13.5px; color: var(--ink-muted); margin: 0; }
156
- .gl-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); overflow: hidden; }
157
- .gl-list li + li { border-top: 1px solid var(--line); }
158
- .gl-list a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; align-items: center; padding: 12px 16px; text-decoration: none; color: var(--ink); }
159
- .gl-list a:hover { background: var(--surface); }
160
- .gl-list a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
161
- .gl-list-goal { font-size: 14.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
162
- .gl-list-meta { grid-column: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--ink-muted); }
163
- .gl-list-date { grid-row: 1 / span 2; grid-column: 2; font-size: 12px; color: var(--ink-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
164
- .gl-new-btn { display: inline-flex; align-items: center; text-decoration: none; }
165
- .gl-new-btn[hidden] { display: none; }
166
- .gl-state.planning { background: var(--warn-soft); color: var(--warn); }
167
- .gl-state.failed { background: var(--bad-soft); color: var(--bad); }
168
- @media (max-width: 520px) { .gl-list a { grid-template-columns: minmax(0, 1fr); } .gl-list-date { grid-row: auto; grid-column: 1; } }
169
- .gl-status { font-size: 13.5px; color: var(--ink-muted); }
170
+ .gl-form details summary { cursor: pointer; }
170
171
  .hint { font-size: 12.5px; color: var(--ink-muted); }
171
172
  .error { font-size: 13px; color: var(--bad); margin: 0; }
173
+ @media (max-width: 860px) {
174
+ .gl-hero { padding: 24px 18px 20px; }
175
+ .gl-hero .le-mascot { display: none; }
176
+ .gl-cols2, .gl-cols3 { grid-template-columns: minmax(0, 1fr); }
177
+ .gl-section-title { padding: 24px 18px 14px; }
178
+ .le-search { display: none; }
179
+ }
172
180
  </style>
173
181
  </head>
174
182
  <body data-le-page="goals">
175
183
  <div class="le-app">
176
184
  ${consoleSidebarHtml}
177
185
  <main class="le-main">
178
- <div class="le-head plain">
179
- <div class="le-head-row">
180
- <div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">&#9776;</button>
181
- <div>__GL_HEAD__</div>
182
- </div>
183
- <a class="gl-btn gl-new-btn" id="glNewBtn" href="__GL_NEW_HREF__"__GL_NEW_HIDDEN__>__GL_NEW_LABEL__</a>
184
- </div>
185
- </div>
186
+ <header class="le-topbar">
187
+ <button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">&#9776;</button>
188
+ <h1 class="le-topbar-title gl-crumb" id="glTitle">__GL_HEAD__</h1>
189
+ <span class="le-topbar-gap"></span>
190
+ <label class="le-search" id="glSearchWrap"__GL_SEARCH_HIDDEN__><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><circle cx="11" cy="11" r="7"/><path d="M20 20l-3.5-3.5"/></svg><input type="search" id="glSearch" placeholder="Search goals" aria-label="Search goals"></label>
191
+ <a class="le-btn-dark gl-new-btn" id="glNewBtn" href="/goals?new=1"__GL_NEW_HIDDEN__>+ New goal</a>
192
+ </header>
186
193
  <div class="le-scroll"><div class="le-page"><div class="gl" id="glPage"><p class="hint">Loading&hellip;</p></div></div></div>
187
194
  </main>
188
195
  </div>
196
+ <template id="glMascot">${mascotSvg(92)}</template>
189
197
  ${consoleShellScript}
190
198
  <script>
191
199
  (function () {
@@ -241,7 +249,12 @@ ${consoleShellScript}
241
249
  if (Array.isArray(r.body.focuses) && r.body.focuses.length) FOCUS = r.body.focuses.map(function (f) { return [f.id, f.label]; }).concat([['other', 'Something else']]);
242
250
  var id = selectId || new URLSearchParams(location.search).get('goal');
243
251
  state.current = state.goals.filter(function (g) { return g.id === id; })[0] || null;
252
+ // With goals already, a new one is a dialog over the list; the whole
253
+ // page is for the first goal, or one handed over from Home.
254
+ var dialog = state.creating && state.goals.length && !startText && location.pathname !== '/';
255
+ if (dialog) { state.creating = false; setUrl(''); }
244
256
  render();
257
+ if (dialog) openNewGoal();
245
258
  });
246
259
  }
247
260
 
@@ -275,134 +288,191 @@ ${consoleShellScript}
275
288
  return state.current ? (state.current.jobs || []).filter(function (j) { return j.id === id; })[0] : undefined;
276
289
  }
277
290
 
291
+ var DOT = ' ' + String.fromCharCode(183) + ' ';
292
+ var ICON_GOAL = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="5"/><circle cx="12" cy="12" r="1.5"/></svg>';
293
+ var ICON_FLOW = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="8" height="8" rx="2"/><rect x="13" y="13" width="8" height="8" rx="2"/><path d="M7 11v3a3 3 0 0 0 3 3h3"/></svg>';
294
+ var ICON_GROUP = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h16"/><path d="M4 12h16"/><path d="M4 18h10"/></svg>';
295
+ var ICON_DOTS = '<svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="5" r="1.7"/><circle cx="12" cy="12" r="1.7"/><circle cx="12" cy="19" r="1.7"/></svg>';
296
+ var mascotTpl = document.getElementById('glMascot');
297
+ var mascot = mascotTpl ? mascotTpl.innerHTML : '';
298
+ // An agent by the name it was given, when the sidebar knows it.
299
+ function agentLabel(name) {
300
+ return window.leShell && window.leShell.displayNameOf ? window.leShell.displayNameOf(name) : name;
301
+ }
302
+ function wfHref(agent, id) {
303
+ return '/agents/config?agent=' + encodeURIComponent(agent) + '&tab=workflows&workflow=' + encodeURIComponent(id);
304
+ }
305
+ // Empty cells to fill a grid's last row.
306
+ function fillers(count, cols) {
307
+ var n = count % cols ? cols - (count % cols) : 0;
308
+ return new Array(n + 1).join('<div class="gl-filler" aria-hidden="true"></div>');
309
+ }
310
+
278
311
  function listHtml() {
312
+ var q = ((document.getElementById('glSearch') || {}).value || '').trim().toLowerCase();
279
313
  var count = function (g, s) { return (g.jobs || []).filter(function (w) { return w.state === s; }).length; };
280
- return '<ul class="gl-list">' + state.goals.map(function (g) {
281
- var parts = [];
282
- if (g.status === 'planning') parts.push('<span class="gl-state planning">Suggesting' + ELLIPSIS + '</span>');
283
- if (g.status === 'failed') parts.push('<span class="gl-state failed">Failed</span>');
314
+ var running = state.goals.reduce(function (n, g) { return n + count(g, 'active'); }, 0);
315
+ var shown = state.goals.filter(function (g) { return !q || g.goal.toLowerCase().indexOf(q) !== -1; });
316
+ var cards = shown.map(function (g) {
317
+ var chips = [];
318
+ if (g.status === 'planning') chips.push('<span class="gl-chip warn">Suggesting' + ELLIPSIS + '</span>');
319
+ if (g.status === 'failed') chips.push('<span class="gl-chip bad">Planning failed</span>');
284
320
  var suggested = count(g, 'suggested'), active = count(g, 'active');
285
- if (suggested) parts.push(suggested + ' suggested');
286
- if (active) parts.push('<span class="gl-state built">' + active + ' running</span>');
287
- if (!parts.length) parts.push('Nothing kept yet');
321
+ if (active) chips.push('<span class="gl-chip good">' + active + ' built</span>');
322
+ if (suggested) chips.push('<span class="gl-chip strong">' + suggested + ' to review</span>');
323
+ if (!active && !suggested && g.status === 'ready') chips.push('<span class="gl-chip">Nothing kept yet</span>');
324
+ var focus = g.focus || (g.brief && g.brief.focus) || '';
325
+ if (focus && focus !== 'other') chips.push('<span class="gl-chip">' + esc(focusLabel(focus)) + '</span>');
288
326
  var date = g.createdAt ? new Date(g.createdAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : '';
289
- return '<li><a href="/goals?goal=' + encodeURIComponent(g.id) + '"><span class="gl-list-goal" title="' + esc(g.goal) + '">' + esc(g.goal) + '</span>' +
290
- '<span class="gl-list-date">' + esc(date) + '</span>' +
291
- '<span class="gl-list-meta">' + parts.join(' <span aria-hidden="true">' + String.fromCharCode(183) + '</span> ') + '</span></a></li>';
292
- }).join('') + '</ul>';
327
+ return '<a class="gl-cell" href="/goals?goal=' + encodeURIComponent(g.id) + '">' +
328
+ '<div class="gl-card-head"><span class="gl-icon' + (active ? ' good' : '') + '">' + ICON_GOAL + '</span>' +
329
+ '<span class="gl-card-text"><span class="gl-card-title">' + esc(g.goal) + '</span>' + (g.message ? '<span class="gl-card-desc">' + esc(g.message) + '</span>' : '') + '</span><span></span></div>' +
330
+ '<div class="gl-chips">' + chips.join('') + (date ? '<span class="gl-next">Set ' + esc(date) + '</span>' : '') + '</div></a>';
331
+ });
332
+ var newTile = '<a class="gl-tile" href="/goals?new=1" data-new-goal><b>+ New goal</b><span>Say what your agents should take care of, and get workflows suggested for it.</span></a>';
333
+ return '<div class="gl-hero"><div class="gl-hero-text"><h2 class="le-display">Your goals</h2><p class="le-display-sub">' +
334
+ state.goals.length + (state.goals.length === 1 ? ' goal' : ' goals') + (running ? ', ' + running + (running === 1 ? ' workflow' : ' workflows') + ' built for them' : '') + '. Open one to see its workflows and suggestions.</p></div>' + mascot + '</div>' +
335
+ '<div class="le-grid gl-cols2">' + (cards.length ? cards.join('') + (q ? fillers(cards.length, 2) : newTile + fillers(cards.length + 1, 2)) : '<p class="gl-empty gl-wide">No goal matches.</p>') + '</div>';
293
336
  }
294
337
 
295
- function newGoalHtml() {
296
- return '<div class="gl-card">' +
297
- '<label for="glGoal"><strong>What should your agents take care of?</strong></label>' +
298
- '<p class="hint" style="margin:2px 0 8px">Big or small: work to hand off, or a result to reach.</p>' +
338
+ // The goal box and its examples; and what LoopEngine knows about you.
339
+ function goalFieldHtml() {
340
+ return '<label for="glGoal" class="gl-field-k">Your goal</label>' +
299
341
  '<textarea id="glGoal" placeholder="e.g. Help me research AI industry trends and publish a weekly report">' + esc(startText) + '</textarea>' +
300
- '<div class="gl-examples hint">Or try: ' + GOAL_EXAMPLES.map(function (x) { return '<button type="button" class="gl-example" data-example="' + esc(x) + '">' + esc(x) + '</button>'; }).join('') + '</div>' +
301
- '<details' + (state.about ? '' : ' open') + '><summary class="hint">About you or your business ' + (state.about ? '(saved, used for every goal)' : '(optional, makes suggestions fit you)') + '</summary>' +
302
- '<textarea id="glAbout" style="margin-top:8px" placeholder="What you do, for whom, and the tools you use (Gmail, Shopify, Slack' + ELLIPSIS + ')">' + esc(state.about) + '</textarea>' +
303
- '<div class="gl-row" style="margin-top:8px"><label class="hint" for="glKind">Kind of business</label><select id="glKind" class="gl-select">' + KINDS.map(function (k) { return '<option value="' + k[0] + '"' + ((state.settings.businessKind || '') === k[0] ? ' selected' : '') + '>' + k[1] + '</option>'; }).join('') + '</select></div>' +
304
- (state.settings.cloud ? '<label class="hint gl-share"><input type="checkbox" id="glShare"' + (state.settings.shareLeverStats ? ' checked' : '') + '> Share anonymous stats about which suggestions you save, build and keep, to improve suggestions for everyone. Never your goals, requests or data.</label>' : '') +
305
- '</details>' +
306
- '<div class="gl-row"><button type="button" class="gl-btn" id="glSubmit">Suggest workflows</button><span class="hint" id="glSubmitStatus"></span></div>' +
307
- '</div>';
342
+ '<div class="gl-examples"><span class="hint">Or try:</span>' + GOAL_EXAMPLES.map(function (x) { return '<button type="button" class="gl-example" data-example="' + esc(x) + '">' + esc(x) + '</button>'; }).join('') + '</div>';
343
+ }
344
+ function aboutFieldsHtml() {
345
+ return '<textarea id="glAbout" placeholder="What you do, for whom, and the tools you use (Gmail, Shopify, Slack' + ELLIPSIS + ')">' + esc(state.about) + '</textarea>' +
346
+ '<div class="gl-row"><label class="hint" for="glKind">Kind of business</label><select id="glKind" class="gl-select">' + KINDS.map(function (k) { return '<option value="' + k[0] + '"' + ((state.settings.businessKind || '') === k[0] ? ' selected' : '') + '>' + k[1] + '</option>'; }).join('') + '</select></div>' +
347
+ (state.settings.cloud ? '<label class="hint gl-share"><input type="checkbox" id="glShare"' + (state.settings.shareLeverStats ? ' checked' : '') + '> Share anonymous stats about which suggestions you save, build and keep, to improve suggestions for everyone. Never your goals, requests or data.</label>' : '');
348
+ }
349
+ function aboutLabel() {
350
+ return 'About you or your business ' + (state.about ? '(saved, used for every goal)' : '(optional, makes suggestions fit you)');
308
351
  }
309
352
 
310
- function needsHtml(w) {
311
- if (!w.needs || !w.needs.length) return '';
312
- return '<div class="gl-needs">' + w.needs.map(function (n) {
313
- return '<span class="gl-need ' + (n.connected ? 'ok' : 'missing') + '">' + esc(n.name) + ' ' + (n.connected ? String.fromCharCode(10003) : 'to connect') + '</span>';
314
- }).join('') + (w.humanMinutesPerWeek ? '<span class="gl-need">about ' + esc(w.humanMinutesPerWeek) + ' min/week to review</span>' : '') + '</div>';
353
+ // The first goal, or one handed over from Home: the whole page.
354
+ function newGoalHtml() {
355
+ return '<div class="gl-hero"><div class="gl-hero-text"><h2 class="le-display">What should your agents <span class="soft">take care of?</span></h2><p class="le-display-sub">Big or small: work to hand off, or a result to reach. LoopEngine suggests the workflows it needs.</p></div>' + mascot + '</div>' +
356
+ '<div class="le-grid gl-cols1"><div class="gl-form">' + goalFieldHtml() +
357
+ '<details' + (state.about ? '' : ' open') + '><summary class="hint">' + aboutLabel() + '</summary><div class="gl-about">' + aboutFieldsHtml() + '</div></details>' +
358
+ '<div class="gl-row"><button type="button" class="le-btn-dark" id="glSubmit">Suggest workflows</button><span class="hint" id="glSubmitStatus"></span></div>' +
359
+ '</div></div>';
315
360
  }
316
361
 
317
- function agentHtml(w) {
318
- return '<span class="gl-agent">' + ARROW + ' ' + (w.agent.isNew ? '<span class="gl-new">New agent</span>' : '') + '<strong>' + esc(w.agent.name) + '</strong></span>';
362
+ // Another goal, in a dialog like Create schedule, over the list or a goal.
363
+ function openNewGoal() {
364
+ var old = document.getElementById('glDialog');
365
+ if (old) old.remove();
366
+ var dlg = document.createElement('dialog');
367
+ dlg.className = 'gl-dialog';
368
+ dlg.id = 'glDialog';
369
+ dlg.setAttribute('aria-labelledby', 'glDlgTitle');
370
+ dlg.innerHTML = '<form method="dialog">' +
371
+ '<div class="gl-dlg-head"><h2 id="glDlgTitle">New goal</h2><button type="button" data-dlg-cancel>Cancel</button><button type="submit" class="primary" id="glSubmit">Suggest workflows</button></div>' +
372
+ '<div class="gl-dlg-body">' +
373
+ '<div class="gl-dlg-col"><div class="gl-field">' + goalFieldHtml() + '<p class="hint" style="margin:0">Big or small: work to hand off, or a result to reach. LoopEngine reads your workspace and suggests the workflows it needs, in about a minute.</p></div></div>' +
374
+ '<div class="gl-dlg-col"><div class="gl-field"><span class="gl-field-k">' + aboutLabel() + '</span>' + aboutFieldsHtml() + '</div></div>' +
375
+ '</div>' +
376
+ '<div class="gl-dlg-foot"><span id="glSubmitStatus"></span></div>' +
377
+ '</form>';
378
+ document.body.appendChild(dlg);
379
+ dlg.addEventListener('close', function () { dlg.remove(); });
380
+ dlg.addEventListener('click', function (ev) { if (ev.target === dlg) dlg.close(); });
381
+ dlg.querySelector('[data-dlg-cancel]').addEventListener('click', function () { dlg.close(); });
382
+ dlg.querySelector('form').addEventListener('submit', function (ev) { ev.preventDefault(); });
383
+ wireNewGoal(dlg, function () { dlg.close(); });
384
+ dlg.showModal();
385
+ dlg.querySelector('#glGoal').focus();
319
386
  }
320
387
 
321
- // A suggestion under the goal: one workflow, or a group of workflows
322
- // that run in order. One row: its title, which it is, its measure, what
323
- // does it, its state and the one action that matters now. Click it for
324
- // the rest: why, what it needs, each workflow and their order.
325
- function itemHtml(w) {
388
+ // The new-goal fields, in the page or the dialog: examples fill the box;
389
+ // Suggest workflows starts the goal and opens it.
390
+ function wireNewGoal(root, done) {
391
+ root.querySelectorAll('[data-example]').forEach(function (b) {
392
+ b.addEventListener('click', function () {
393
+ var box = root.querySelector('#glGoal');
394
+ box.value = b.dataset.example;
395
+ box.focus();
396
+ });
397
+ });
398
+ var submit = root.querySelector('#glSubmit');
399
+ if (submit) submit.addEventListener('click', function () {
400
+ var goal = root.querySelector('#glGoal').value.trim();
401
+ startText = '';
402
+ var aboutBox = root.querySelector('#glAbout');
403
+ var status = root.querySelector('#glSubmitStatus');
404
+ if (goal.length < 5) { status.textContent = 'Say what your agents should take care of first.'; return; }
405
+ submit.disabled = true;
406
+ status.textContent = 'Starting' + ELLIPSIS;
407
+ api('POST', '/goals', { goal: goal, about: aboutBox ? aboutBox.value : state.about }).then(function (r) {
408
+ if (!r.ok) { submit.disabled = false; status.innerHTML = '<span class="error">' + esc(r.body.error || 'Could not start.') + '</span>'; return; }
409
+ state.about = aboutBox ? aboutBox.value.trim() : state.about;
410
+ state.startedAt = Date.now();
411
+ state.creating = false;
412
+ replaceGoal(r.body.goal);
413
+ setUrl(r.body.goal.id);
414
+ reloadSidebar();
415
+ if (done) done();
416
+ render();
417
+ });
418
+ });
419
+ if (submit && autoStart && !done) { autoStart = false; submit.click(); }
420
+ var kind = root.querySelector('#glKind');
421
+ if (kind) kind.addEventListener('change', function () { saveSettings({ businessKind: kind.value || null }); });
422
+ var share = root.querySelector('#glShare');
423
+ if (share) share.addEventListener('change', function () { saveSettings({ shareLeverStats: share.checked }); });
424
+ }
425
+
426
+ // What a suggestion needs: apps connected or to connect, as chips.
427
+ function needChips(list) {
428
+ return (list || []).map(function (n) {
429
+ return '<span class="gl-chip ' + (n.connected ? 'good' : 'warn') + '">' + esc(n.name) + (n.connected ? ' ' + String.fromCharCode(10003) : DOT + 'connect') + '</span>';
430
+ }).join('');
431
+ }
432
+ function agentChip(a) {
433
+ return '<span class="gl-chip"><span class="gl-chip-k">Runs on</span> ' + esc(a.isNew ? a.name : agentLabel(a.name)) + (a.isNew ? ' <span class="gl-new">New agent</span>' : '') + '</span>';
434
+ }
435
+ function factChips(w, withAgent) {
436
+ return (w.measure ? '<span class="gl-chip strong"><span class="gl-chip-k">Measured by</span> ' + esc(w.measure) + '</span>' : '') +
437
+ (w.humanMinutesPerWeek ? '<span class="gl-chip"><span class="gl-chip-k">Your time</span> ~' + esc(w.humanMinutesPerWeek) + ' min a week</span>' : '') +
438
+ (withAgent && w.agent ? agentChip(w.agent) : '');
439
+ }
440
+ function btn(act, label, cls, step) {
441
+ return '<button type="button" class="gl-btn ' + (cls || '') + '" data-act="' + act + '"' + (step ? ' data-step="' + esc(step) + '"' : '') + '>' + label + '</button>';
442
+ }
443
+ function cardHead(w, icon, iconCls, side) {
326
444
  var group = w.group && w.group.steps && w.group.steps.length ? w.group : null;
327
- var steps = group ? group.steps : [];
328
- var builtSteps = steps.filter(function (st) { return st.built; }).length;
329
- var nextStep = group ? steps.filter(function (st) { return !st.built; })[0] : null;
330
- var active = w.state === 'active';
331
- var btn = function (act, label, cls, step) { return '<button type="button" class="gl-btn ' + (cls || '') + '" data-act="' + act + '"' + (step ? ' data-step="' + esc(step) + '"' : '') + '>' + label + '</button>'; };
332
- var primary = w.state === 'discarded' ? btn('restore', 'Restore', 'plain')
333
- : group && nextStep ? btn('buildstep', builtSteps ? 'Build step ' + (builtSteps + 1) : 'Build step 1', '', nextStep.id)
334
- : !group && w.state === 'suggested' ? btn('build', 'Build the workflow') : '';
335
- var more = w.state === 'suggested' ? btn('discard', 'Discard', 'plain') : '';
336
- var pill = active && group && nextStep ? '<span class="gl-state saved">' + builtSteps + ' of ' + steps.length + ' built</span>'
337
- : active ? '<span class="gl-state built">Running</span>'
338
- : w.state === 'discarded' ? '<span class="gl-state">Discarded</span>' : '';
339
- var kind = group ? 'Group ' + String.fromCharCode(183) + ' ' + steps.length + ' workflows in order' : 'Workflow';
340
- var sub = w.measure ? 'Measured by ' + w.measure : w.why || '';
341
- var open = !!state.openJobs[w.id];
342
- return '<div class="gl-wf gl-job' + (open ? ' is-open' : '') + (active ? ' built' : '') + '" data-wf="' + esc(w.id) + '">' +
343
- '<div class="gl-job-head" role="button" tabindex="0" aria-expanded="' + open + '"><span class="gl-caret" aria-hidden="true"></span>' +
344
- '<div class="gl-job-main"><span class="gl-wf-title">' + esc(w.title) + '</span>' +
345
- '<span class="gl-job-sub"><span class="gl-kind' + (group ? ' group' : '') + '">' + kind + '</span>' + (sub ? '<span class="gl-job-line">' + esc(sub) + '</span>' : '') + '</span>' +
346
- (!open && active && !group ? doneByHtml(w) : '') + '</div>' +
347
- '<span class="gl-job-status">' + pill + '<span class="gl-state planning" data-attn hidden>Needs you</span></span>' +
348
- '<span class="gl-job-primary">' + primary + '</span>' +
349
- '</div>' +
350
- '<div class="gl-job-body"' + (open ? '' : ' hidden') + '>' +
351
- (w.added ? '<p class="hint" style="margin:0">You added this: ' + String.fromCharCode(8220) + esc(w.added.idea) + String.fromCharCode(8221) + (w.added.note ? ' ' + String.fromCharCode(183) + ' ' + esc(w.added.note) : '') + (w.keepPrivate ? ' ' + String.fromCharCode(183) + ' kept to your workspace' : ' ' + String.fromCharCode(183) + ' its approach may be shared') + '</p>' : '') +
352
- (w.why && sub !== w.why ? '<p class="gl-why">' + esc(w.why) + '</p>' : '') +
353
- (w.measure && sub.indexOf(w.measure) < 0 ? '<p class="gl-job-measure">Measured by ' + esc(w.measure) + '</p>' : '') +
354
- (group ? stepsHtml(w, steps) + (active && (w.doers || []).length > 1 ? '<details class="gl-order"><summary>Change the order</summary>' + howHtml(w) + '</details>' : '')
355
- : active ? howHtml(w)
356
- : '<div class="gl-row">' + agentHtml(w) + '</div>' + needsHtml(w) + '<details><summary>What the workflow will do</summary><p>' + esc(w.request) + '</p></details>') +
357
- (more ? '<div class="gl-row">' + more + '</div>' : '') +
358
- '</div>' +
359
- '<span class="hint gl-job-status-line" data-wf-status></span>' +
360
- '</div>';
445
+ var kind = group ? 'Group of ' + group.steps.length + ' workflows that run in order' : 'Workflow';
446
+ return '<div class="gl-card-head"><span class="gl-icon' + (iconCls ? ' ' + iconCls : '') + '">' + icon + '</span>' +
447
+ '<span class="gl-card-text"><span class="gl-card-kind">' + kind + '</span><span class="gl-card-title gl-wf-title">' + esc(w.title) + '</span>' +
448
+ (w.why ? '<span class="gl-card-desc">' + esc(w.why) + '</span>' : '') + '</span>' +
449
+ '<span class="gl-card-side">' + side + '</span></div>';
361
450
  }
362
451
 
363
- // A group's workflows, in the order they run: each built one with how
364
- // it's doing (filled by fillEvidence), each to build with its agent,
365
- // what it needs and what it will do; then what it passes on.
452
+ // A group's workflows, in the order they run: a built one with how it's
453
+ // doing (filled by fillEvidence) and Open; one to build with its agent,
454
+ // what it needs, what it will do and Build.
366
455
  function stepsHtml(w, steps) {
367
- return '<ol class="gl-gsteps">' + steps.map(function (st, i) {
368
- var head = '<span class="gl-gstep-n">' + (i + 1) + '</span><strong class="gl-gstep-name">' + esc(st.name) + '</strong>';
456
+ var next = steps.filter(function (st) { return !st.built; })[0];
457
+ return '<div class="gl-flows">' + steps.map(function (st, i) {
369
458
  var row = st.built
370
- ? '<div class="gl-gstep-head" data-how="' + esc(st.built.agent) + '|' + esc(st.built.workflowId) + '">' + head +
371
- '<a class="gl-slug" href="/agents/config?agent=' + encodeURIComponent(st.built.agent) + '&tab=workflows&workflow=' + encodeURIComponent(st.built.workflowId) + '">' + esc(st.built.workflowId) + '</a>' +
372
- '<span class="gl-agent-pill">' + esc(st.built.agent) + '</span><span class="hint" data-how-meta>' + ELLIPSIS + '</span></div>'
373
- : '<div class="gl-gstep-head">' + head + agentHtml(st) +
374
- (w.state !== 'discarded' ? '<button type="button" class="gl-btn soft gl-gstep-build" data-act="buildstep" data-step="' + esc(st.id) + '">Build</button>' : '') + '</div>' +
375
- needsHtml(st) + '<details><summary>What it will do</summary><p>' + esc(st.request) + '</p></details>';
376
- return '<li class="gl-gstep' + (st.built ? ' built' : '') + '">' + row +
377
- (i < steps.length - 1 ? '<div class="gl-gstep-then">then ' + ARROW + ' starts when this one finishes, with its result</div>' : '') + '</li>';
378
- }).join('') + '</ol>';
459
+ ? '<div class="gl-flow built" data-how="' + esc(st.built.agent) + '|' + esc(st.built.workflowId) + '"><span class="gl-flow-n">' + (i + 1) + '</span>' +
460
+ '<div class="gl-flow-main"><a class="gl-flow-title" data-how-title href="' + wfHref(st.built.agent, st.built.workflowId) + '">' + esc(st.name) + '</a>' +
461
+ '<span class="gl-flow-meta">' + esc(agentLabel(st.built.agent)) + DOT + '<span data-how-meta>' + ELLIPSIS + '</span></span></div>' +
462
+ '<div class="gl-flow-actions"><a class="gl-btn plain small gl-link-btn" href="' + wfHref(st.built.agent, st.built.workflowId) + '">Open</a></div></div>'
463
+ : '<div class="gl-flow"><span class="gl-flow-n">' + (i + 1) + '</span>' +
464
+ '<div class="gl-flow-main"><span class="gl-flow-title">' + esc(st.name) + '</span>' +
465
+ '<span class="gl-flow-meta">' + esc(st.request) + '</span>' +
466
+ '<div class="gl-chips">' + agentChip(st.agent) + needChips(st.needs) + '</div></div>' +
467
+ '<div class="gl-flow-actions">' + (w.state !== 'discarded' ? btn('buildstep', 'Build', st === next ? 'small' : 'plain small', st.id) : '') + '</div></div>';
468
+ return row + (i < steps.length - 1 ? '<div class="gl-flow-then">then ' + ARROW + ' starts when step ' + (i + 1) + ' finishes, with its result</div>' : '');
469
+ }).join('') + '</div>';
379
470
  }
380
471
 
381
- // A workflow of the person's own: typed in their words, shaped and judged by
382
- // the planner (added, changed, warned or refused), with what it said.
383
- function addJobHtml(planning) {
384
- var n = state.addNotice;
385
- var notice = !n ? '' : '<div class="gl-notice ' + (n.verdict === 'refused' ? 'bad' : n.verdict === 'added' ? 'good' : 'warn') + '">' +
386
- '<strong>' + (n.verdict === 'refused' ? 'Not added' : n.verdict === 'changed' ? 'Added, with changes' : n.verdict === 'warned' ? 'Added, with a caution' : 'Added') + '</strong>' +
387
- (n.note ? '<span>' + esc(n.note) + '</span>' : '') +
388
- (n.alternative ? '<span class="hint">Instead, you could: ' + esc(n.alternative) + '</span>' : '') + '</div>';
389
- return '<div class="gl-add">' +
390
- '<button type="button" class="gl-link" id="glAddToggle"' + (state.addOpen ? ' hidden' : '') + '>+ Add your own workflow</button>' +
391
- '<div class="gl-add-form"' + (state.addOpen ? '' : ' hidden') + '>' +
392
- '<label for="glAddIdea"><strong>A workflow you have in mind</strong> <span class="hint">in your own words; LoopEngine shapes it into a workflow (or a group, when it has stages) and says if anything looks off</span></label>' +
393
- '<textarea id="glAddIdea" rows="2" placeholder="e.g. Thank every new customer by email within a day">' + esc(state.addDraft || '') + '</textarea>' +
394
- '<label class="hint gl-share"><input type="checkbox" id="glAddShare"' + (state.addShare ? ' checked' : '') + '> Share the approach behind it to improve suggestions for everyone</label>' +
395
- '<p class="hint" style="margin:0">Your idea stays in your workspace unless you tick that. If you do, only a generic description of the approach is shared, never your words, and only once many workspaces use something similar.</p>' +
396
- '<div class="gl-row"><button type="button" class="gl-btn soft" id="glAddJob"' + (planning ? ' disabled' : '') + '>Add it</button><button type="button" class="gl-btn plain" id="glAddCancel">Cancel</button><span class="hint" id="glAddStatus"></span></div>' +
397
- '</div>' + notice + '</div>';
398
- }
399
-
400
- // On a built workflow's card: what does it, one line per workflow, each
401
- // with how it's going (filled by fillEvidence); "then" marks one that
402
- // starts after another.
403
- function doneByHtml(w) {
472
+ // A built workflow's workflows in the order they run: one that another
473
+ // starts follows it, with "then".
474
+ function orderedFlows(w) {
404
475
  var flows = (w.doers || []).filter(function (d) { return d.type === 'workflow'; });
405
- // A chained workflow follows the one that starts it, marked "then".
406
476
  var after = {};
407
477
  (w.chain || []).forEach(function (st) { after[st.run.agent + '|' + st.run.workflowId] = st.after.agent + '|' + st.after.workflowId; });
408
478
  var keyOf = function (d) { return d.agent + '|' + d.workflowId; };
@@ -411,57 +481,124 @@ ${consoleShellScript}
411
481
  flows.forEach(function (d) { if (after[keyOf(d)] === keyOf(ordered[i]) && ordered.indexOf(d) < 0) ordered.splice(i + 1, 0, d); });
412
482
  }
413
483
  flows.forEach(function (d) { if (ordered.indexOf(d) < 0) ordered.push(d); });
414
- return '<span class="gl-doneby">' + ordered.map(function (d, i) {
415
- var then = i > 0 && after[keyOf(d)] === keyOf(ordered[i - 1]);
416
- return '<span class="gl-doneby-row" data-how="' + esc(d.agent) + '|' + esc(d.workflowId) + '">' +
417
- (then ? '<span class="gl-doneby-then">then ' + String.fromCharCode(8594) + '</span>' : '<span class="gl-tag-wf">Workflow</span>') +
418
- '<a href="/agents/config?agent=' + encodeURIComponent(d.agent) + '&tab=workflows&workflow=' + encodeURIComponent(d.workflowId) + '" class="gl-slug">' + esc(d.workflowId) + '</a>' +
419
- '<span class="gl-agent-pill">' + esc(d.agent) + '</span><span class="hint" data-how-meta>' + ELLIPSIS + '</span></span>';
420
- }).join('') + '</span>';
484
+ return ordered;
485
+ }
486
+
487
+ function flowsHtml(w) {
488
+ var flows = orderedFlows(w);
489
+ var stepFor = function (d) { return (w.chain || []).filter(function (st) { return st.run.agent === d.agent && st.run.workflowId === d.workflowId; })[0]; };
490
+ var whenText = function (wh) { return wh.kind === 'always' ? 'when it finishes' : wh.kind === 'contains' ? 'when its result contains ' + String.fromCharCode(8220) + esc(wh.text) + String.fromCharCode(8221) : 'when its result has a line starting ' + String.fromCharCode(8220) + esc(wh.text) + String.fromCharCode(8221); };
491
+ return '<div class="gl-flows">' + flows.map(function (d, i) {
492
+ var st = stepFor(d);
493
+ var then = st ? '<div class="gl-flow-then">then ' + ARROW + ' ' + whenText(st.when) + '<button type="button" class="gl-link" data-chain-remove="' + esc(st.id) + '">Remove this step</button></div>' : '';
494
+ return then + '<div class="gl-flow built" data-how="' + esc(d.agent) + '|' + esc(d.workflowId) + '"><span class="gl-flow-n">' + (i + 1) + '</span>' +
495
+ '<div class="gl-flow-main"><a class="gl-flow-title" data-how-title href="' + wfHref(d.agent, d.workflowId) + '">' + esc(d.title || d.workflowId) + '</a>' +
496
+ '<span class="gl-flow-meta">' + esc(agentLabel(d.agent)) + DOT + '<span data-how-meta>' + ELLIPSIS + '</span></span></div>' +
497
+ '<div class="gl-flow-actions">' + (flows.length > 1 ? '<button type="button" class="gl-link gl-unlink" data-unlink="' + esc(d.agent) + '|' + esc(d.workflowId) + '">Remove</button>' : '') +
498
+ '<a class="gl-btn plain small gl-link-btn" href="' + wfHref(d.agent, d.workflowId) + '">Open</a></div></div>';
499
+ }).join('') + '</div>';
421
500
  }
422
501
 
423
- function howHtml(w) {
502
+ // Add another workflow to a built one, or a step that runs one after another.
503
+ function manageHtml(w) {
424
504
  var flows = (w.doers || []).filter(function (d) { return d.type === 'workflow'; });
425
- var titleOf = function (r) { return r.workflowId; };
426
- var whenText = function (wh) { return wh.kind === 'always' ? '' : wh.kind === 'contains' ? ', when its result contains ' + String.fromCharCode(8220) + esc(wh.text) + String.fromCharCode(8221) : ', when its result has a line starting ' + String.fromCharCode(8220) + esc(wh.text) + String.fromCharCode(8221); };
427
- var chain = (w.chain || []).map(function (st) {
428
- var inputs = Object.keys(st.with || {}).map(function (p) { var src = st.with[p]; return esc(p) + ' ' + String.fromCharCode(8592) + ' ' + (src === 'result' ? 'its result' : 'its ' + esc(src.slice(6))); }).join(', ');
429
- return '<div class="gl-step" data-step="' + esc(st.id) + '"><span>After <strong>' + esc(titleOf(st.after)) + '</strong>' + whenText(st.when) + ', run <strong>' + esc(titleOf(st.run)) + '</strong>' + (inputs ? ' <span class="hint">(' + inputs + ')</span>' : '') + '</span><button type="button" class="gl-link" data-chain-remove="' + esc(st.id) + '">Remove</button></div>';
430
- }).join('');
431
- return '<div class="gl-how"><div class="gl-how-head">Workflows</div>' + flows.map(function (d) {
432
- return '<div class="gl-how-row" data-how="' + esc(d.agent) + '|' + esc(d.workflowId) + '">' +
433
- '<div class="gl-how-main"><span class="gl-how-wf gl-slug">' + esc(d.workflowId) + '</span><span class="gl-how-agent">on <strong>' + esc(d.agent) + '</strong></span></div>' +
434
- '<span class="gl-how-meta" data-how-meta>' + ELLIPSIS + '</span>' +
435
- '<span class="gl-how-actions"><a class="gl-how-open" href="/agents/config?agent=' + encodeURIComponent(d.agent) + '&tab=workflows&workflow=' + encodeURIComponent(d.workflowId) + '">Open</a>' +
436
- (flows.length > 1 ? '<button type="button" class="gl-link gl-unlink" data-unlink="' + esc(d.agent) + '|' + esc(d.workflowId) + '">Remove</button>' : '') + '</span></div>';
437
- }).join('') +
438
- (chain ? '<div class="gl-chain"><div class="gl-how-head">Then</div>' + chain + '</div>' : '') +
439
- '<div class="gl-row"><button type="button" class="gl-btn plain" data-act="addwf">Add a workflow</button>' + (flows.length > 1 ? '<button type="button" class="gl-btn plain" data-act="addstep">Add a step</button>' : '') + '</div>' +
505
+ var opt = function (d, sel) { return '<option value="' + esc(d.agent) + '|' + esc(d.workflowId) + '"' + (sel ? ' selected' : '') + '>' + esc(d.title || d.workflowId) + '</option>'; };
506
+ return '<div class="gl-card-foot"><button type="button" class="gl-link" data-act="addwf">+ Add a workflow</button>' + (flows.length > 1 ? '<button type="button" class="gl-link" data-act="addstep">+ Run one after another</button>' : '') + '</div>' +
440
507
  '<div class="gl-panel" data-panel="addwf" hidden><label class="hint" for="addwf-' + esc(w.id) + '">A workflow already on one of your agents</label>' +
441
- '<div class="gl-row"><select class="gl-select" id="addwf-' + esc(w.id) + '" data-pick-workflow><option value="">Loading' + ELLIPSIS + '</option></select><button type="button" class="gl-btn soft" data-act="link">Add it</button></div>' +
508
+ '<div class="gl-row"><select class="gl-select" id="addwf-' + esc(w.id) + '" data-pick-workflow><option value="">Loading' + ELLIPSIS + '</option></select><button type="button" class="gl-btn soft small" data-act="link">Add it</button></div>' +
442
509
  '<div class="gl-row"><span class="hint">or</span><button type="button" class="gl-link" data-act="another">build a new one for it</button></div></div>' +
443
510
  '<div class="gl-panel" data-panel="addstep" hidden>' +
444
- '<div class="gl-row"><span class="hint">After</span><select class="gl-select" data-step-after>' + flows.map(function (d) { return '<option value="' + esc(d.agent) + '|' + esc(d.workflowId) + '">' + esc(d.workflowId) + '</option>'; }).join('') + '</select>' +
511
+ '<div class="gl-row"><span class="hint">After</span><select class="gl-select" data-step-after>' + flows.map(function (d) { return opt(d, false); }).join('') + '</select>' +
445
512
  '<span class="hint">finishes</span><select class="gl-select" data-step-when><option value="always">every time</option><option value="contains">when its result contains</option><option value="line_starts">when its result has a line starting</option></select><input class="gl-input" data-step-text placeholder="e.g. Lead:" hidden></div>' +
446
- '<div class="gl-row"><span class="hint">run</span><select class="gl-select" data-step-run>' + flows.map(function (d, i) { return '<option value="' + esc(d.agent) + '|' + esc(d.workflowId) + '"' + (i === 1 ? ' selected' : '') + '>' + esc(d.workflowId) + '</option>'; }).join('') + '</select></div>' +
513
+ '<div class="gl-row"><span class="hint">run</span><select class="gl-select" data-step-run>' + flows.map(function (d, i) { return opt(d, i === 1); }).join('') + '</select></div>' +
447
514
  '<div class="gl-step-inputs" data-step-inputs></div>' +
448
- '<div class="gl-row"><button type="button" class="gl-btn soft" data-act="savestep">Save the step</button></div></div>' +
515
+ '<div class="gl-row"><button type="button" class="gl-btn soft small" data-act="savestep">Save the step</button></div></div>';
516
+ }
517
+
518
+ // A workflow (or group) built for the goal: what it's for, then each of
519
+ // its workflows once, with how it's going.
520
+ function builtHtml(w) {
521
+ var group = w.group && w.group.steps && w.group.steps.length ? w.group : null;
522
+ var steps = group ? group.steps : [];
523
+ var builtSteps = steps.filter(function (st) { return st.built; }).length;
524
+ var pill = group && builtSteps < steps.length ? '<span class="gl-chip accent">' + builtSteps + ' of ' + steps.length + ' built</span>' : '<span class="gl-chip" data-card-pill hidden></span>';
525
+ return '<div class="gl-cell" data-wf="' + esc(w.id) + '">' +
526
+ cardHead(w, group ? ICON_GROUP : ICON_FLOW, 'good', '<span class="gl-chip warn" data-attn hidden>Needs you</span>' + pill) +
527
+ '<div class="gl-chips">' + factChips(w, false) + '</div>' +
528
+ (group ? stepsHtml(w, steps) : flowsHtml(w) + manageHtml(w)) +
529
+ '<span class="hint gl-job-status-line" data-wf-status></span>' +
449
530
  '</div>';
450
531
  }
451
532
 
533
+ // A suggestion: what it is and why, what it's worth, where it runs and
534
+ // what it needs; Build, or Discard from its menu.
535
+ function suggestionHtml(w) {
536
+ var group = w.group && w.group.steps && w.group.steps.length ? w.group : null;
537
+ var steps = group ? group.steps : [];
538
+ var discarded = w.state === 'discarded';
539
+ var side = discarded ? btn('restore', 'Restore', 'plain small')
540
+ : '<details class="gl-menu"><summary aria-label="More">' + ICON_DOTS + '</summary><div class="gl-menu-list"><button type="button" data-act="discard">Discard</button></div></details>';
541
+ return '<div class="gl-cell' + (group ? ' gl-wide' : '') + (discarded ? ' discarded' : '') + '" data-wf="' + esc(w.id) + '">' +
542
+ cardHead(w, group ? ICON_GROUP : ICON_FLOW, '', side) +
543
+ (w.added ? '<p class="hint" style="margin:0">You added this: ' + String.fromCharCode(8220) + esc(w.added.idea) + String.fromCharCode(8221) + (w.added.note ? DOT + esc(w.added.note) : '') + '</p>' : '') +
544
+ '<div class="gl-chips">' + factChips(w, !group) + (group ? '' : needChips(w.needs)) + '</div>' +
545
+ (group ? stepsHtml(w, steps)
546
+ : (w.request ? '<details class="gl-what"><summary>What it will do</summary><p>' + esc(w.request) + '</p></details>' : '') +
547
+ (discarded ? '' : '<div class="gl-card-foot">' + btn('build', 'Build it', 'small') + '</div>')) +
548
+ '<span class="hint gl-job-status-line" data-wf-status></span>' +
549
+ '</div>';
550
+ }
551
+
552
+ // A workflow of the person's own: typed in their words, shaped and judged by
553
+ // the planner (added, changed, warned or refused), with what it said.
554
+ function addJobHtml(planning) {
555
+ var n = state.addNotice;
556
+ var notice = !n ? '' : '<div class="gl-notice gl-wide ' + (n.verdict === 'refused' ? 'bad' : n.verdict === 'added' ? 'good' : 'warn') + '">' +
557
+ '<strong>' + (n.verdict === 'refused' ? 'Not added' : n.verdict === 'changed' ? 'Added, with changes' : n.verdict === 'warned' ? 'Added, with a caution' : 'Added') + '</strong>' +
558
+ (n.note ? '<span>' + esc(n.note) + '</span>' : '') +
559
+ (n.alternative ? '<span class="hint">Instead, you could: ' + esc(n.alternative) + '</span>' : '') + '</div>';
560
+ return '<div class="gl-add-form gl-wide"' + (state.addOpen ? '' : ' hidden') + '>' +
561
+ '<label for="glAddIdea"><strong>A workflow you have in mind</strong> <span class="hint">in your own words; LoopEngine shapes it into a workflow (or a group, when it has stages) and says if anything looks off</span></label>' +
562
+ '<textarea id="glAddIdea" rows="2" placeholder="e.g. Thank every new customer by email within a day">' + esc(state.addDraft || '') + '</textarea>' +
563
+ '<label class="hint gl-share"><input type="checkbox" id="glAddShare"' + (state.addShare ? ' checked' : '') + '> Share the approach behind it to improve suggestions for everyone</label>' +
564
+ '<p class="hint" style="margin:0">Your idea stays in your workspace unless you tick that. If you do, only a generic description of the approach is shared, never your words, and only once many workspaces use something similar.</p>' +
565
+ '<div class="gl-row"><button type="button" class="gl-btn small" id="glAddJob"' + (planning ? ' disabled' : '') + '>Add it</button><button type="button" class="gl-btn plain small" id="glAddCancel">Cancel</button><span class="hint" id="glAddStatus"></span></div>' +
566
+ '</div>' + notice;
567
+ }
568
+
452
569
  function startsText(w) {
453
570
  var schedules = (w.schedules || []).filter(function (x) { return x.status !== 'cancelled'; });
454
- if (schedules.length) return schedules[0].describe.charAt(0).toUpperCase() + schedules[0].describe.slice(1) + (schedules[0].status === 'paused' ? ' (paused)' : '');
571
+ if (schedules.length) return schedules[0].describe.charAt(0).toUpperCase() + schedules[0].describe.slice(1);
455
572
  if (w.webhooks || w.webhooksWaiting) return w.webhooksWaiting && !w.webhooks ? 'Webhook, needs its signing secret' : 'On a webhook';
456
- return 'When started by hand or an app';
573
+ return 'Runs when started';
574
+ }
575
+ // live: a schedule or webhook starts it; paused: its schedules are all
576
+ // paused; manual: it runs when someone starts it.
577
+ function flowState(w) {
578
+ var schedules = (w.schedules || []).filter(function (x) { return x.status !== 'cancelled'; });
579
+ if (w.webhooks || schedules.some(function (x) { return x.status !== 'paused'; })) return 'live';
580
+ return schedules.length ? 'paused' : 'manual';
581
+ }
582
+ // A built card's chip, from its workflows: Running when any is started
583
+ // by a schedule or webhook, Paused when all are paused, else Ready to run.
584
+ function refreshPill(card) {
585
+ var pill = card && card.querySelector('[data-card-pill]');
586
+ if (!pill) return;
587
+ var states = Array.prototype.map.call(card.querySelectorAll('[data-flow-state]'), function (el) { return el.getAttribute('data-flow-state'); });
588
+ if (!states.length) return;
589
+ var s = states.indexOf('live') >= 0 ? ['good', 'Running'] : states.every(function (x) { return x === 'paused'; }) ? ['', 'Paused'] : ['accent', 'Ready to run'];
590
+ pill.className = 'gl-chip ' + s[0];
591
+ pill.textContent = s[1];
592
+ pill.hidden = false;
457
593
  }
458
594
 
459
595
  // Fills each workflow row from its agent's workflow list, and marks the
460
- // suggestion when one is waiting for a decision.
596
+ // card when one is waiting for a decision.
461
597
  function fillEvidence() {
462
598
  var rows = page.querySelectorAll('[data-how]');
463
599
  var agents = {};
464
600
  for (var i = 0; i < rows.length; i++) agents[rows[i].getAttribute('data-how').split('|')[0]] = true;
601
+ var waitingTotal = 0;
465
602
  Object.keys(agents).forEach(function (agent) {
466
603
  api('GET', '/agents/' + encodeURIComponent(agent) + '/workflows').then(function (r) {
467
604
  if (!r.ok) return;
@@ -474,19 +611,26 @@ ${consoleShellScript}
474
611
  if (parts[0] !== agent) continue;
475
612
  var meta = mine[j].querySelector('[data-how-meta]');
476
613
  var w = byId[parts[1]];
477
- if (!w) { meta.textContent = 'Its workflow is gone from this agent'; continue; }
614
+ var card = mine[j].closest('[data-wf]');
615
+ if (!w) { meta.textContent = 'This workflow is gone from its agent'; continue; }
616
+ var title = mine[j].querySelector('[data-how-title]');
617
+ if (title && w.title) title.textContent = w.title;
478
618
  var sc = w.scores || { runs: 0, failed: 0 };
479
619
  var waiting = (w.recentRuns || []).filter(function (x) { return x.status === 'awaiting_approval'; }).length + (w.schedules || []).filter(function (x) { return x.waiting; }).length;
480
- var bits = [startsText(w), sc.runs ? sc.runs + ' run' + (sc.runs === 1 ? '' : 's') + (sc.failed ? ', ' + sc.failed + ' failed' : '') : 'no runs yet'];
620
+ var st = flowState(w);
621
+ mine[j].setAttribute('data-flow-state', st);
622
+ var bits = [startsText(w), sc.runs ? sc.runs + ' run' + (sc.runs === 1 ? '' : 's') + (sc.failed ? ', ' + sc.failed + ' failed' : '') : 'No runs yet'];
481
623
  var round = w.evals && w.evals.rounds && w.evals.rounds[0];
482
- if (round && round.passRates) bits.push('evals: ' + round.allPassed + ' of ' + round.cases.length + ' passed every check');
483
- else if (round && typeof round.average === 'number') bits.push('evals ' + round.average.toFixed(1) + ' / 5');
484
- meta.innerHTML = esc(bits.join(' ' + String.fromCharCode(183) + ' ')) + (waiting ? ' <span class="gl-waiting">' + waiting + ' waiting for your decision</span>' : '');
624
+ if (round && round.passRates) bits.push('evals: ' + round.allPassed + ' of ' + round.cases.length + ' passed');
625
+ meta.innerHTML = (st === 'paused' ? '<span class="gl-paused">Paused</span> ' : '') + esc(bits.join(DOT)) + (waiting ? ' <span class="gl-waiting">' + waiting + ' waiting for you</span>' : '');
485
626
  if (waiting) {
486
- var card = mine[j].closest('[data-wf]');
627
+ waitingTotal += waiting;
487
628
  var attn = card && card.querySelector('[data-attn]');
488
629
  if (attn) attn.hidden = false;
630
+ var stat = document.getElementById('glWaiting');
631
+ if (stat) { stat.textContent = String(waitingTotal); stat.closest('.gl-stat').classList.add('attn'); }
489
632
  }
633
+ refreshPill(card);
490
634
  }
491
635
  });
492
636
  });
@@ -501,43 +645,50 @@ ${consoleShellScript}
501
645
  var planning = g.status === 'planning';
502
646
  var focus = g.focus || (g.brief && g.brief.focus) || '';
503
647
  var secs = state.startedAt ? Math.round((Date.now() - state.startedAt) / 1000) : 0;
504
- return '<div class="gl-card">' +
505
- '<h2 class="gl-goal-title">' + esc(g.goal) + '</h2>' +
506
- (focus ? '<div class="gl-focus"><label for="glFocus">Focus</label> <select id="glFocus"' + (planning ? ' disabled' : '') + '>' + (FOCUS.some(function (f) { return f[0] === focus; }) ? FOCUS : FOCUS.concat([[focus, (g.brief && g.brief.newFocus && g.brief.newFocus.label) || focus]])).map(function (f) { return '<option value="' + esc(f[0]) + '"' + (f[0] === focus ? ' selected' : '') + '>' + esc(f[1]) + '</option>'; }).join('') + '</select>' +
507
- (focus.indexOf('x-') === 0 ? '<span class="hint" title="No focus in the playbook fit this goal, so its planner named one and wrote the approaches it needed. They stay in this workspace for next time.">written for your goals</span>' : '') +
508
- (g.brief && g.brief.measure ? '<span>' + String.fromCharCode(183) + ' measured by ' + esc(g.brief.measure) + '</span>' : '') + '</div>' : '') +
509
- (g.message ? '<p class="gl-why">' + esc(g.message) + '</p>' : '') +
510
- (planning ? '<p class="gl-status">Suggesting workflows' + ELLIPSIS + (secs ? ' ' + secs + 's' : '') + ' It reads your workspace first; this takes about a minute.</p>' : '') +
511
- (g.status === 'failed' ? '<p class="error">' + esc(g.error || 'Planning failed.') + '</p>' : '') +
512
- (g.setup && g.setup.length ? '<div><strong style="font-size:13.5px">Before you start</strong><ol class="gl-setup">' + g.setup.slice(0, 4).map(function (s) { return '<li>' + esc(s) + '</li>'; }).join('') + '</ol>' +
513
- (g.setup.length > 4 ? '<details class="gl-setup-more"><summary>' + (g.setup.length - 4) + ' more</summary><ol class="gl-setup" start="5">' + g.setup.slice(4).map(function (s) { return '<li>' + esc(s) + '</li>'; }).join('') + '</ol></details>' : '') + '</div>' : '') +
514
- '</div>' +
648
+ var focusChip = focus ? '<label class="gl-chip strong"><span class="gl-chip-k">Focus</span><select id="glFocus" class="gl-select"' + (planning ? ' disabled' : '') + '>' + (FOCUS.some(function (f) { return f[0] === focus; }) ? FOCUS : FOCUS.concat([[focus, (g.brief && g.brief.newFocus && g.brief.newFocus.label) || focus]])).map(function (f) { return '<option value="' + esc(f[0]) + '"' + (f[0] === focus ? ' selected' : '') + '>' + esc(f[1]) + '</option>'; }).join('') + '</select></label>' : '';
649
+ var stat = function (n, label, id) { return '<div class="gl-stat"><b' + (id ? ' id="' + id + '"' : '') + '>' + n + '</b><span>' + label + '</span></div>'; };
650
+ var setup = g.setup || [];
651
+ var date = g.createdAt ? new Date(g.createdAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : '';
652
+ var section = function (title, hint) { return '<h3 class="gl-section-title">' + title + (hint ? '<span class="hint">' + hint + '</span>' : '') + '</h3>'; };
653
+ return '<div class="gl-hero"><div class="gl-hero-text"><span class="gl-eyebrow">Goal' + (date ? DOT + 'set ' + esc(date) : '') + '</span>' +
654
+ '<h2 class="gl-display">' + esc(g.goal) + '</h2>' +
655
+ (g.message ? '<p class="gl-hero-sub">' + esc(g.message) + '</p>' : '') +
656
+ '<div class="gl-chips">' + focusChip + (g.brief && g.brief.measure ? '<span class="gl-chip"><span class="gl-chip-k">Measured by</span> ' + esc(g.brief.measure) + '</span>' : '') +
657
+ (focus.indexOf('x-') === 0 ? '<span class="gl-chip" title="No focus in the playbook fit this goal, so its planner named one and wrote the approaches it needed. They stay in this workspace for next time.">Written for your goals</span>' : '') + '</div>' +
658
+ (planning ? '<p class="gl-status"><span class="gl-spinner" aria-hidden="true"></span>Suggesting workflows' + ELLIPSIS + (secs ? ' ' + secs + 's.' : '') + ' It reads your workspace first; this takes about a minute.</p>' : '') +
659
+ (g.status === 'failed' ? '<p class="error">' + esc(g.error || 'Planning failed.') + '</p>' : '') +
660
+ '</div>' + mascot + '</div>' +
661
+ '<div class="le-grid gl-cols3">' + stat(kept.length, kept.length === 1 ? 'workflow built' : 'workflows built') + stat(suggested.length, suggested.length === 1 ? 'suggestion to review' : 'suggestions to review') + stat(0, 'runs waiting for you', 'glWaiting') + '</div>' +
662
+ (setup.length ? section('Before you start', 'Do these first, so its workflows can run') +
663
+ '<div class="le-grid gl-cols2">' + setup.map(function (s, i) { return '<div class="gl-setup-step"><span class="gl-setup-n">' + (i + 1) + '</span><span>' + esc(s) + '</span></div>'; }).join('') + fillers(setup.length, 2) + '</div>' : '') +
664
+ (kept.length ? section('Your workflows', 'Built for this goal') + '<div class="le-grid gl-cols1">' + kept.map(builtHtml).join('') + '</div>' : '') +
665
+ section('Suggested', 'Workflows that would move this goal: build the ones you want') +
515
666
  (state.justDiscarded ? '<div class="gl-discarded-note" data-discarded="' + esc(state.justDiscarded.id) + '"><span>Discarded <strong>' + esc(state.justDiscarded.title) + '</strong>. Why?</span>' +
516
- REASONS.map(function (r) { return '<button type="button" class="gl-btn plain" data-reason="' + r[0] + '">' + r[1] + '</button>'; }).join('') +
667
+ REASONS.map(function (r) { return '<button type="button" class="gl-btn plain small" data-reason="' + r[0] + '">' + r[1] + '</button>'; }).join('') +
517
668
  '<button type="button" class="gl-link" data-undo="1">Undo</button></div>' : '') +
518
- '<div class="gl-section"><h3>Suggested <span class="gl-count">' + suggested.length + '</span></h3>' +
519
- '<p class="hint gl-define">Workflows that move this goal, and groups of workflows that run in order, one after another.</p>' +
520
- (suggested.length ? suggested.map(function (w) { return itemHtml(w); }).join('') : '<p class="gl-empty">' + (planning ? 'On their way' + ELLIPSIS : 'No suggestions waiting. Generate more for new ideas.') + '</p>') +
521
- '<div class="gl-row"><button type="button" class="gl-btn soft" id="glMore"' + (planning ? ' disabled' : '') + '>Generate more</button><span class="hint">More workflows or groups: nothing already here, built or discarded comes back.</span></div>' +
522
- addJobHtml(planning) +
669
+ '<div class="le-grid gl-cols2">' +
670
+ (suggested.length ? suggested.map(suggestionHtml).join('') + fillers(suggested.filter(function (w) { return !(w.group && w.group.steps && w.group.steps.length); }).length, 2)
671
+ : '<p class="gl-empty gl-wide">' + (planning ? 'On their way' + ELLIPSIS : 'No suggestions waiting. Ask for more below.') + '</p>') +
523
672
  '</div>' +
524
- '<div class="gl-section"><h3>Your workflows <span class="gl-count">' + kept.length + '</span></h3>' +
525
- (kept.length ? kept.map(function (w) { return itemHtml(w); }).join('') : '<p class="gl-empty">Nothing built yet. Build a suggested workflow, or a group' + String.fromCharCode(8217) + 's workflows one by one.</p>') +
673
+ '<div class="le-grid gl-cols3" style="border-top:0">' +
674
+ '<button type="button" class="gl-tile" id="glMore"' + (planning ? ' disabled' : '') + '><b>Suggest more</b><span>New ideas only: nothing already here, built or discarded comes back.</span></button>' +
675
+ '<button type="button" class="gl-tile" id="glAddToggle"><b>Add your own</b><span>Describe a workflow in your words, and LoopEngine shapes it for this goal.</span></button>' +
676
+ (discarded.length ? '<button type="button" class="gl-tile" id="glShowDiscarded"><b>' + (state.showDiscarded ? 'Hide' : 'Show') + ' discarded</b><span>' + discarded.length + (discarded.length === 1 ? ' suggestion' : ' suggestions') + ' you set aside. Restore any of them.</span></button>' : '<div class="gl-filler" aria-hidden="true"></div>') +
677
+ addJobHtml(planning) +
526
678
  '</div>' +
527
- (discarded.length ? '<div class="gl-section"><button type="button" class="gl-link" id="glShowDiscarded">' + (state.showDiscarded ? 'Hide' : 'Show') + ' discarded (' + discarded.length + ')</button>' +
528
- (state.showDiscarded ? discarded.map(function (w) { return itemHtml(w); }).join('') : '') + '</div>' : '') +
529
- '<div><button type="button" class="gl-link" id="glDelete" style="color:var(--bad)">Delete this goal</button></div>';
679
+ (discarded.length && state.showDiscarded ? section('Discarded') + '<div class="le-grid gl-cols2">' + discarded.map(suggestionHtml).join('') + fillers(discarded.filter(function (w) { return !(w.group && w.group.steps && w.group.steps.length); }).length, 2) + '</div>' : '') +
680
+ '<div class="gl-foot"><button type="button" class="gl-link gl-danger" id="glDelete">Delete this goal</button><span class="hint">The workflows built for it stay on their agents.</span></div>';
530
681
  }
531
682
 
532
683
  function render() {
533
684
  var title = document.getElementById('glTitle');
534
- var lead = document.getElementById('glLead');
535
685
  var newBtn = document.getElementById('glNewBtn');
686
+ var search = document.getElementById('glSearchWrap');
536
687
  // The list, unless there are no goals yet: then the new-goal form.
537
688
  var listing = !state.current && !state.creating && state.goals.length > 0;
538
- if (title) title.textContent = state.current ? 'Goal' : listing ? 'Goals' : 'New goal';
539
- if (lead) lead.style.display = state.current || listing ? 'none' : '';
540
- if (newBtn) newBtn.hidden = !listing;
689
+ if (title) title.innerHTML = state.current ? '<a href="/goals">Goals</a><span aria-hidden="true" style="color:var(--ink-faint);font-weight:400">/</span><span>' + esc(state.current.goal) + '</span>' : listing ? 'Goals' : 'New goal';
690
+ if (newBtn) newBtn.hidden = !listing && !state.current;
691
+ if (search) search.hidden = !listing;
541
692
  page.innerHTML = (state.current ? goalHtml(state.current) : listing ? listHtml() : newGoalHtml()) + (state.error ? '<p class="error">' + esc(state.error) + '</p>' : '');
542
693
  state.error = '';
543
694
  wire();
@@ -546,38 +697,9 @@ ${consoleShellScript}
546
697
  }
547
698
 
548
699
  function wire() {
549
- page.querySelectorAll('[data-example]').forEach(function (b) {
550
- b.addEventListener('click', function () {
551
- var box = document.getElementById('glGoal');
552
- box.value = b.dataset.example;
553
- box.focus();
554
- });
555
- });
556
- var submit = document.getElementById('glSubmit');
557
- if (submit) submit.addEventListener('click', function () {
558
- var goal = document.getElementById('glGoal').value.trim();
559
- startText = '';
560
- var aboutBox = document.getElementById('glAbout');
561
- var status = document.getElementById('glSubmitStatus');
562
- if (goal.length < 5) { status.textContent = 'Say what your agents should take care of first.'; return; }
563
- this.disabled = true;
564
- status.textContent = 'Starting' + ELLIPSIS;
565
- api('POST', '/goals', { goal: goal, about: aboutBox ? aboutBox.value : state.about }).then(function (r) {
566
- if (!r.ok) { state.error = r.body.error || 'Could not start.'; render(); return; }
567
- state.about = aboutBox ? aboutBox.value.trim() : state.about;
568
- state.startedAt = Date.now();
569
- state.creating = false;
570
- replaceGoal(r.body.goal);
571
- setUrl(r.body.goal.id);
572
- reloadSidebar();
573
- render();
574
- });
575
- });
576
- if (submit && autoStart) { autoStart = false; submit.click(); }
577
- var kind = document.getElementById('glKind');
578
- if (kind) kind.addEventListener('change', function () { saveSettings({ businessKind: kind.value || null }); });
579
- var share = document.getElementById('glShare');
580
- if (share) share.addEventListener('change', function () { saveSettings({ shareLeverStats: share.checked }); });
700
+ wireNewGoal(page, null);
701
+ var tile = page.querySelector('[data-new-goal]');
702
+ if (tile) tile.addEventListener('click', function (ev) { ev.preventDefault(); openNewGoal(); });
581
703
  if (!state.current) return;
582
704
  var g = state.current;
583
705
  var base = '/goals/' + encodeURIComponent(g.id);
@@ -697,27 +819,9 @@ ${consoleShellScript}
697
819
  box.innerHTML = params.map(function (p) { return '<div class="gl-row"><span class="hint"><code>' + esc(p) + '</code>' + (target.parameters[p].required ? '' : ' (optional)') + ' from</span><select class="gl-select" data-input="' + esc(p) + '">' + choices(p) + '</select></div>'; }).join('');
698
820
  }
699
821
 
700
- function setJobOpen(card, open) {
701
- var id = card.getAttribute('data-wf');
702
- state.openJobs[id] = open;
703
- card.classList.toggle('is-open', open);
704
- card.querySelector('.gl-job-head').setAttribute('aria-expanded', String(open));
705
- card.querySelector('.gl-job-body').hidden = !open;
706
- }
707
-
708
822
  function wireCard(card, base) {
709
823
  var id = card.getAttribute('data-wf');
710
824
  var status = card.querySelector('[data-wf-status]');
711
- var head = card.querySelector('.gl-job-head');
712
- head.addEventListener('click', function (ev) {
713
- if (card.classList.contains('gl-job-detail') || ev.target.closest('button, a')) return;
714
- setJobOpen(card, !card.classList.contains('is-open'));
715
- });
716
- head.addEventListener('keydown', function (ev) {
717
- if (card.classList.contains('gl-job-detail') || ev.target !== head || (ev.key !== 'Enter' && ev.key !== ' ')) return;
718
- ev.preventDefault();
719
- setJobOpen(card, !card.classList.contains('is-open'));
720
- });
721
825
  // A suggestion's chain: change the step being written, remove a step or a workflow.
722
826
  ['[data-step-run]', '[data-step-after]', '[data-step-when]'].forEach(function (sel) {
723
827
  var el = card.querySelector(sel);
@@ -807,21 +911,28 @@ ${consoleShellScript}
807
911
  });
808
912
  }
809
913
 
914
+ // + New goal (the top bar's, the sidebar's) opens the dialog over the
915
+ // page, once there are goals to go back to.
916
+ document.addEventListener('click', function (ev) {
917
+ var a = ev.target.closest && ev.target.closest('#glNewBtn, [data-le-goal-new]');
918
+ if (!a || !state.goals.length || ev.metaKey || ev.ctrlKey) return;
919
+ ev.preventDefault();
920
+ openNewGoal();
921
+ });
922
+ // Search narrows the list as you type.
923
+ var searchBox = document.getElementById('glSearch');
924
+ if (searchBox) searchBox.addEventListener('input', function () { if (!state.current && !state.creating) render(); });
810
925
  load();
811
926
  })();
812
927
  </script>
813
928
  </body>
814
929
  </html>`;
815
- const GOALS_LEAD = 'LoopEngine suggests the workflows a goal needs: one for a small goal; more, or groups that run in order, for a big one. Build the ones you want.';
816
930
  function goalsPageFor(view) {
817
- const title = view === 'goal' ? 'Goal' : view === 'goals' ? 'Goals' : 'New goal';
818
- // A list or one goal shows no lead; a new goal explains itself.
819
- const hideLead = view === 'goal' || view === 'goals';
931
+ const title = view === 'goal' ? 'Goals' : view === 'goals' ? 'Goals' : 'New goal';
820
932
  return goalsPageTemplate
821
- .replace('__GL_HEAD__', `<h1 id="glTitle">${title}</h1><p id="glLead"${hideLead ? ' style="display:none"' : ''}>${GOALS_LEAD}</p>`)
822
- .replace('__GL_NEW_HREF__', '/goals?new=1')
823
- .replace('__GL_NEW_HIDDEN__', view === 'goals' ? '' : ' hidden')
824
- .replace('__GL_NEW_LABEL__', 'New goal');
933
+ .replace('__GL_HEAD__', title)
934
+ .replace('__GL_SEARCH_HIDDEN__', view === 'goals' ? '' : ' hidden')
935
+ .replace('__GL_NEW_HIDDEN__', view === 'new' ? ' hidden' : '');
825
936
  }
826
937
  const goalsPages = { goals: goalsPageFor('goals'), goal: goalsPageFor('goal'), new: goalsPageFor('new') };
827
938
  export function goalsPageAs(view) {