loopengine 0.4.11 → 0.4.13

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.
@@ -1,11 +1,10 @@
1
1
  // The console's Goals page: /goals lists the goals made so far, /goals?new=1
2
2
  // (and the workspace's front page, /) starts one, and /goals?goal=<id>
3
- // opens one. A goal breaks into jobs, each with its own measure: recurring
4
- // ones are built into a workflow on an agent, one-off ones are assigned to
5
- // an agent (each try's result shown, accepted or sent back with a note).
6
- // Type a goal, get suggested jobs (each with the agent it would go into),
7
- // generate more, and build or assign one straight from the suggestions,
8
- // which makes its agent first when it doesn't exist (web/goals-admin.ts
3
+ // opens one. Type a goal, get suggested workflows, each with its own
4
+ // measure and the agent it would go into: one workflow, or for a bigger
5
+ // piece of the goal a group of workflows that run in order. Generate more,
6
+ // and build one (or a group's step) straight from the suggestions, which
7
+ // makes its agent first when it doesn't exist (web/goals-admin.ts
9
8
  // behind /goals/*). Same shell and
10
9
  // styles as the other console pages; like them, its inline script avoids
11
10
  // backslashes and template placeholders, since it lives inside a template
@@ -93,6 +92,17 @@ const goalsPageTemplate = `<!doctype html>
93
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; } }
94
93
  .gl-job-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 12.5px; color: var(--ink-muted); }
95
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); }
96
106
  .gl-doer { font-size: 13px; color: var(--ink-muted); }
97
107
  .gl-doer strong { color: var(--ink); font-family: var(--font-mono); font-size: 12px; }
98
108
  .gl-link-btn { display: inline-flex; align-items: center; text-decoration: none; }
@@ -186,18 +196,11 @@ ${consoleShellScript}
186
196
  var REASONS = [['not-relevant', 'Not relevant'], ['too-much-work', 'Too much work'], ['already-doing-it', 'Already doing it']];
187
197
  // Which view: the list (/goals), a new goal (?new=1, or the front page)
188
198
  // or one goal (?goal=).
189
- // The Jobs page (/jobs): the person's own list of jobs, from any goal
190
- // or submitted there without one.
191
- var jobsView = location.pathname === '/jobs';
192
- // On the Jobs page, the new-job form (?new=1, or no jobs yet) or the list.
193
- var jobCreating = jobsView && new URLSearchParams(location.search).has('new');
194
- // One job's page (?job=, from the sidebar or after submitting one).
195
- var jobPage = jobsView && !jobCreating ? new URLSearchParams(location.search).get('job') : null;
196
- var startNew = !jobsView && (location.pathname === '/' || new URLSearchParams(location.search).has('new'));
199
+ var startNew = location.pathname === '/' || new URLSearchParams(location.search).has('new');
197
200
  // A goal to start from (?new=1&text=...): one typed on the website's
198
201
  // goal box before signing up, carried in by "Open workspace".
199
202
  var startText = (new URLSearchParams(location.search).get('text') || '').slice(0, 500);
200
- var state = { jobs: [], jobsLoaded: false, jobsStale: false, jobDraft: '', jobNotice: null, addOpen: false, addDraft: '', addShare: false, addNotice: null, flows: {}, openJobs: {}, goals: [], about: '', settings: {}, current: null, creating: startNew, showDiscarded: false, justDiscarded: null, error: '', poll: null, startedAt: 0 };
203
+ var state = { addOpen: false, addDraft: '', addShare: false, addNotice: null, flows: {}, openJobs: {}, goals: [], about: '', settings: {}, current: null, creating: startNew, showDiscarded: false, justDiscarded: null, error: '', poll: null, startedAt: 0 };
201
204
 
202
205
  function esc(s) {
203
206
  return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) {
@@ -221,25 +224,7 @@ ${consoleShellScript}
221
224
  history.replaceState(null, '', url);
222
225
  }
223
226
 
224
- function loadJobs() {
225
- api('GET', '/jobs').then(function (r) {
226
- if (!r.ok) { page.innerHTML = '<p class="error">Could not load jobs: ' + esc(r.body.error || 'unknown error') + '</p>'; return; }
227
- var first = !state.jobsLoaded;
228
- state.jobs = r.body.jobs || [];
229
- if (first && !state.jobs.length) jobCreating = true;
230
- state.jobsLoaded = true;
231
- state.jobsStale = false;
232
- // A job picked in the sidebar (?job=): open, and brought into view.
233
- var picked = first ? new URLSearchParams(location.search).get('job') : null;
234
- if (picked) state.openJobs[picked] = true;
235
- if (!first) reloadSidebar();
236
- render();
237
- if (picked) { var el = page.querySelector('.gl-job[data-wf="' + picked.replace(/[^a-z0-9-]/gi, '') + '"]'); if (el) el.scrollIntoView({ block: 'center' }); }
238
- });
239
- }
240
-
241
227
  function load(selectId) {
242
- if (jobsView) { loadJobs(); return; }
243
228
  api('GET', '/goals').then(function (r) {
244
229
  if (!r.ok) { page.innerHTML = '<p class="error">Could not load goals: ' + esc(r.body.error || 'unknown error') + '</p>'; return; }
245
230
  state.goals = r.body.goals || [];
@@ -253,16 +238,11 @@ ${consoleShellScript}
253
238
  }
254
239
 
255
240
  // While a goal is planning, check every few seconds.
256
- // While a goal is planning, or a one-off job's try is going, check again
257
- // every few seconds (not while a note is being written).
258
- function lastTry(job) { return job.tries && job.tries.length ? job.tries[job.tries.length - 1] : null; }
259
- function tryGoing(t) { return t && (t.status === 'running' || t.status === 'awaiting_approval'); }
260
241
  function watch() {
261
242
  if (state.poll) { clearTimeout(state.poll); state.poll = null; }
262
243
  if (!state.current) return;
263
244
  var planning = state.current.status === 'planning';
264
- var going = (state.current.jobs || []).some(function (j) { return j.state === 'active' && tryGoing(lastTry(j)); });
265
- if (!planning && !going) return;
245
+ if (!planning) return;
266
246
  state.poll = setTimeout(function () {
267
247
  var typing = document.activeElement && document.activeElement.classList && document.activeElement.classList.contains('gl-note');
268
248
  if (typing) { watch(); return; }
@@ -272,34 +252,19 @@ ${consoleShellScript}
272
252
  if (planning && r.body.goal.status !== 'planning') reloadSidebar();
273
253
  render();
274
254
  });
275
- }, planning ? 3000 : 4000);
276
- }
277
- function watchJobs() {
278
- if (state.poll) { clearTimeout(state.poll); state.poll = null; }
279
- var going = state.jobs.some(function (x) { return x.job.state === 'active' && tryGoing(lastTry(x.job)); });
280
- if (!going) return;
281
- state.poll = setTimeout(function () {
282
- var typing = document.activeElement && document.activeElement.classList && document.activeElement.classList.contains('gl-note');
283
- if (typing) { watchJobs(); return; }
284
- loadJobs();
285
- }, 4000);
255
+ }, 3000);
286
256
  }
287
257
  function reloadSidebar() {
288
258
  if (window.leShell && window.leShell.reloadGoals) window.leShell.reloadGoals();
289
- if (window.leShell && window.leShell.reloadJobs) window.leShell.reloadJobs();
290
259
  }
291
260
  function replaceGoal(goal) {
292
- // On the Jobs page, a job's goal coming back means the list changed.
293
- if (jobsView) { state.jobsStale = true; return; }
294
261
  state.goals = state.goals.map(function (g) { return g.id === goal.id ? goal : g; });
295
262
  if (!state.goals.some(function (g) { return g.id === goal.id; })) state.goals.unshift(goal);
296
263
  state.current = goal;
297
264
  }
298
- // A job on this page, wherever it's listed.
265
+ // A workflow or group under the current goal.
299
266
  function findJob(id) {
300
- if (state.current) return (state.current.jobs || []).filter(function (j) { return j.id === id; })[0];
301
- var hit = state.jobs.filter(function (x) { return x.job.id === id; })[0];
302
- return hit ? hit.job : undefined;
267
+ return state.current ? (state.current.jobs || []).filter(function (j) { return j.id === id; })[0] : undefined;
303
268
  }
304
269
 
305
270
  function listHtml() {
@@ -308,11 +273,10 @@ ${consoleShellScript}
308
273
  var parts = [];
309
274
  if (g.status === 'planning') parts.push('<span class="gl-state planning">Suggesting' + ELLIPSIS + '</span>');
310
275
  if (g.status === 'failed') parts.push('<span class="gl-state failed">Failed</span>');
311
- var suggested = count(g, 'suggested'), active = count(g, 'active'), done = count(g, 'done');
276
+ var suggested = count(g, 'suggested'), active = count(g, 'active');
312
277
  if (suggested) parts.push(suggested + ' suggested');
313
278
  if (active) parts.push('<span class="gl-state built">' + active + ' running</span>');
314
- if (done) parts.push(done + ' done');
315
- if (!parts.length) parts.push('No jobs kept yet');
279
+ if (!parts.length) parts.push('Nothing kept yet');
316
280
  var date = g.createdAt ? new Date(g.createdAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' }) : '';
317
281
  return '<li><a href="/goals?goal=' + encodeURIComponent(g.id) + '"><span class="gl-list-goal" title="' + esc(g.goal) + '">' + esc(g.goal) + '</span>' +
318
282
  '<span class="gl-list-date">' + esc(date) + '</span>' +
@@ -329,7 +293,7 @@ ${consoleShellScript}
329
293
  '<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>' +
330
294
  (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>' : '') +
331
295
  '</details>' +
332
- '<div class="gl-row"><button type="button" class="gl-btn" id="glSubmit">Suggest jobs</button><span class="hint" id="glSubmitStatus"></span></div>' +
296
+ '<div class="gl-row"><button type="button" class="gl-btn" id="glSubmit">Suggest workflows</button><span class="hint" id="glSubmitStatus"></span></div>' +
333
297
  '</div>';
334
298
  }
335
299
 
@@ -344,68 +308,67 @@ ${consoleShellScript}
344
308
  return '<span class="gl-agent">' + ARROW + ' ' + (w.agent.isNew ? '<span class="gl-new">New agent</span>' : '') + '<strong>' + esc(w.agent.name) + '</strong></span>';
345
309
  }
346
310
 
347
- // A job: one piece of the goal, with its measure, and what does it.
348
- // A job as one row: its title, kind and one line (its measure, else why
349
- // it helps), what does it (Done by), its status, and the one action
350
- // that matters now. Click it for the rest: why, what it needs and the
351
- // other actions; its own page also manages its workflows.
352
- function jobHtml(w, listed) {
353
- // On its own page a job is shown whole, not folded, with its workflows.
354
- var detail = jobPage === w.id;
355
- var once = w.kind === 'once';
356
- var doer = (w.doers || [])[0];
357
- var t = lastTry(w);
358
- var btn = function (act, label, cls) { return '<button type="button" class="gl-btn ' + (cls || '') + '" data-act="' + act + '">' + label + '</button>'; };
359
- var primary = w.state === 'suggested' && once ? btn('assign', 'Give it to an agent')
360
- : w.state === 'suggested' ? btn('build', 'Build a workflow')
361
- : w.state === 'active' && once && t && t.status === 'done' ? btn('accept', 'Accept')
362
- : w.state === 'active' && once && t && (t.status === 'error' || t.status === 'gone') ? btn('again', 'Try again')
363
- : w.state === 'discarded' ? btn('restore', 'Restore', 'plain') : '';
364
- // On a goal's page, a job not yet on the person's list can be added to it.
365
- var onList = !!(w.addedAt || ((w.state === 'active' || w.state === 'done') && (w.doers || []).length));
366
- var listBtn = listed || w.state === 'discarded' ? '' : onList ? '<span class="gl-listed">In my jobs</span>' : btn('list', 'Add to my jobs', 'soft');
367
- var more = w.state === 'suggested' && once ? btn('build', 'Open in Chat', 'plain') + btn('done', 'Mark done', 'plain') + btn('discard', 'Discard', 'plain')
368
- : w.state === 'suggested' ? btn('discard', 'Discard', 'plain')
369
- : w.state === 'active' && once ? (t && t.status === 'done' ? btn('again', 'Ask again', 'soft') : '') + btn('done', 'Mark done', 'plain') + btn('discard', 'Discard', 'plain')
370
- : w.state === 'done' ? btn('undone', 'Reopen', 'plain') : '';
371
- if (listed && listed.goalId !== 'g-my-jobs') more += btn('unlist', 'Remove from my jobs', 'plain');
372
- var pill = w.state === 'active' && once ? (t && t.status === 'done' ? '<span class="gl-state built">Result ready</span>' : t && t.status === 'awaiting_approval' ? '<span class="gl-state planning">Needs you</span>' : t && t.status === 'running' ? '<span class="gl-state saved">Working' + ELLIPSIS + '</span>' : '<span class="gl-state failed">Failed</span>')
373
- : w.state === 'active' ? '<span class="gl-state built">Running</span>'
374
- : w.state === 'done' ? '<span class="gl-state built">Done</span>'
311
+ // A suggestion under the goal: one workflow, or a group of workflows
312
+ // that run in order. One row: its title, which it is, its measure, what
313
+ // does it, its state and the one action that matters now. Click it for
314
+ // the rest: why, what it needs, each workflow and their order.
315
+ function itemHtml(w) {
316
+ var group = w.group && w.group.steps && w.group.steps.length ? w.group : null;
317
+ var steps = group ? group.steps : [];
318
+ var builtSteps = steps.filter(function (st) { return st.built; }).length;
319
+ var nextStep = group ? steps.filter(function (st) { return !st.built; })[0] : null;
320
+ var active = w.state === 'active';
321
+ 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>'; };
322
+ var primary = w.state === 'discarded' ? btn('restore', 'Restore', 'plain')
323
+ : group && nextStep ? btn('buildstep', builtSteps ? 'Build step ' + (builtSteps + 1) : 'Build step 1', '', nextStep.id)
324
+ : !group && w.state === 'suggested' ? btn('build', 'Build the workflow') : '';
325
+ var more = w.state === 'suggested' ? btn('discard', 'Discard', 'plain') : '';
326
+ var pill = active && group && nextStep ? '<span class="gl-state saved">' + builtSteps + ' of ' + steps.length + ' built</span>'
327
+ : active ? '<span class="gl-state built">Running</span>'
375
328
  : w.state === 'discarded' ? '<span class="gl-state">Discarded</span>' : '';
376
- // A job is about its outcome: its measure leads, then why it matters.
377
- var sub = w.measure ? (once ? '' : 'Measured by ') + w.measure : w.why || '';
378
- var doneBy = once && (w.state === 'active' || w.state === 'done') && w.tries && w.tries.length ? triesHtml(w)
379
- : w.state === 'active' && doer && doer.type === 'workflow' ? (detail ? howHtml(w) : '')
380
- : w.state === 'done' && w.doneAt ? '<div class="gl-doer">Done ' + esc(new Date(w.doneAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })) + '</div>' : '';
381
- var open = detail || !!state.openJobs[w.id];
382
- return '<div class="gl-wf gl-job' + (open ? ' is-open' : '') + (detail ? ' gl-job-detail' : '') + (w.state === 'active' || w.state === 'done' ? ' built' : '') + '" data-wf="' + esc(w.id) + '"' + (listed ? ' data-goal="' + esc(listed.goalId) + '"' : '') + '>' +
383
- (detail ? '<div class="gl-job-head">' : '<div class="gl-job-head" role="button" tabindex="0" aria-expanded="' + open + '">' +
384
- '<span class="gl-caret" aria-hidden="true"></span>') +
385
- '<div class="gl-job-main">' + (listed && !detail ? '<a class="gl-wf-title gl-job-link" href="/jobs?job=' + encodeURIComponent(w.id) + '">' + esc(w.title) + '</a>' : '<span class="gl-wf-title">' + esc(w.title) + '</span>') +
386
- '<span class="gl-job-sub"><span class="gl-kind">' + (once ? 'One-off' : 'Recurring') + '</span>' + (sub ? '<span class="gl-job-line">' + esc(sub) + '</span>' : '') + '</span>' +
387
- (!detail && w.state === 'active' && !once && doer && doer.type === 'workflow' ? doneByHtml(w) : '') +
388
- (!detail && once && (w.state === 'active' || w.state === 'done') && w.tries && w.tries.length ? assignedHtml(w) : '') +
389
- (listed ? '<span class="gl-job-from">Added ' + esc(new Date(listed.addedAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric', year: 'numeric' })) + ' ' + String.fromCharCode(183) + ' ' +
390
- (listed.goal ? 'Goal: <a href="/goals?goal=' + encodeURIComponent(listed.goalId) + '">' + esc(listed.goal) + '</a>' : 'No goal') + '</span>' : '') + '</div>' +
329
+ var kind = group ? 'Group ' + String.fromCharCode(183) + ' ' + steps.length + ' workflows in order' : 'Workflow';
330
+ var sub = w.measure ? 'Measured by ' + w.measure : w.why || '';
331
+ var open = !!state.openJobs[w.id];
332
+ return '<div class="gl-wf gl-job' + (open ? ' is-open' : '') + (active ? ' built' : '') + '" data-wf="' + esc(w.id) + '">' +
333
+ '<div class="gl-job-head" role="button" tabindex="0" aria-expanded="' + open + '"><span class="gl-caret" aria-hidden="true"></span>' +
334
+ '<div class="gl-job-main"><span class="gl-wf-title">' + esc(w.title) + '</span>' +
335
+ '<span class="gl-job-sub"><span class="gl-kind' + (group ? ' group' : '') + '">' + kind + '</span>' + (sub ? '<span class="gl-job-line">' + esc(sub) + '</span>' : '') + '</span>' +
336
+ (!open && active && !group ? doneByHtml(w) : '') + '</div>' +
391
337
  '<span class="gl-job-status">' + pill + '<span class="gl-state planning" data-attn hidden>Needs you</span></span>' +
392
- '<span class="gl-job-primary">' + listBtn + primary + '</span>' +
338
+ '<span class="gl-job-primary">' + primary + '</span>' +
393
339
  '</div>' +
394
340
  '<div class="gl-job-body"' + (open ? '' : ' hidden') + '>' +
395
341
  (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>' : '') +
396
342
  (w.why && sub !== w.why ? '<p class="gl-why">' + esc(w.why) + '</p>' : '') +
397
- (w.measure && sub.indexOf(w.measure) < 0 ? '<p class="gl-job-measure">' + (once ? '' : 'Measured by ') + esc(w.measure) + '</p>' : '') +
398
- (w.state === 'active' || w.state === 'done' ? '' : '<div class="gl-row">' + agentHtml(w) + '</div>' + needsHtml(w)) +
399
- doneBy +
400
- (w.state === 'active' && !once ? '' : '<details><summary>' + (once ? 'What the agent is asked to do' : 'What its workflow will do') + '</summary><p>' + esc(w.request) + '</p></details>') +
343
+ (w.measure && sub.indexOf(w.measure) < 0 ? '<p class="gl-job-measure">Measured by ' + esc(w.measure) + '</p>' : '') +
344
+ (group ? stepsHtml(w, steps) + (active && (w.doers || []).length > 1 ? '<details class="gl-order"><summary>Change the order</summary>' + howHtml(w) + '</details>' : '')
345
+ : active ? howHtml(w)
346
+ : '<div class="gl-row">' + agentHtml(w) + '</div>' + needsHtml(w) + '<details><summary>What the workflow will do</summary><p>' + esc(w.request) + '</p></details>') +
401
347
  (more ? '<div class="gl-row">' + more + '</div>' : '') +
402
- (once && w.state === 'active' ? '<div class="gl-again" hidden><label class="hint" for="note-' + esc(w.id) + '">What should change this time? (optional)</label><textarea class="gl-note" id="note-' + esc(w.id) + '" rows="2" placeholder="e.g. Add 5 more, and skip the paid ones."></textarea><div class="gl-row"><button type="button" class="gl-btn" data-act="assign">Send it back</button></div></div>' : '') +
403
348
  '</div>' +
404
349
  '<span class="hint gl-job-status-line" data-wf-status></span>' +
405
350
  '</div>';
406
351
  }
407
352
 
408
- // A job of the person's own: typed in their words, shaped and judged by
353
+ // A group's workflows, in the order they run: each built one with how
354
+ // it's doing (filled by fillEvidence), each to build with its agent,
355
+ // what it needs and what it will do; then what it passes on.
356
+ function stepsHtml(w, steps) {
357
+ return '<ol class="gl-gsteps">' + steps.map(function (st, i) {
358
+ var head = '<span class="gl-gstep-n">' + (i + 1) + '</span><strong class="gl-gstep-name">' + esc(st.name) + '</strong>';
359
+ var row = st.built
360
+ ? '<div class="gl-gstep-head" data-how="' + esc(st.built.agent) + '|' + esc(st.built.workflowId) + '">' + head +
361
+ '<a class="gl-slug" href="/agents/config?agent=' + encodeURIComponent(st.built.agent) + '&tab=workflows&workflow=' + encodeURIComponent(st.built.workflowId) + '">' + esc(st.built.workflowId) + '</a>' +
362
+ '<span class="gl-agent-pill">' + esc(st.built.agent) + '</span><span class="hint" data-how-meta>' + ELLIPSIS + '</span></div>'
363
+ : '<div class="gl-gstep-head">' + head + agentHtml(st) +
364
+ (w.state !== 'discarded' ? '<button type="button" class="gl-btn soft gl-gstep-build" data-act="buildstep" data-step="' + esc(st.id) + '">Build</button>' : '') + '</div>' +
365
+ needsHtml(st) + '<details><summary>What it will do</summary><p>' + esc(st.request) + '</p></details>';
366
+ return '<li class="gl-gstep' + (st.built ? ' built' : '') + '">' + row +
367
+ (i < steps.length - 1 ? '<div class="gl-gstep-then">then ' + ARROW + ' starts when this one finishes, with its result</div>' : '') + '</li>';
368
+ }).join('') + '</ol>';
369
+ }
370
+
371
+ // A workflow of the person's own: typed in their words, shaped and judged by
409
372
  // the planner (added, changed, warned or refused), with what it said.
410
373
  function addJobHtml(planning) {
411
374
  var n = state.addNotice;
@@ -414,46 +377,19 @@ ${consoleShellScript}
414
377
  (n.note ? '<span>' + esc(n.note) + '</span>' : '') +
415
378
  (n.alternative ? '<span class="hint">Instead, you could: ' + esc(n.alternative) + '</span>' : '') + '</div>';
416
379
  return '<div class="gl-add">' +
417
- '<button type="button" class="gl-link" id="glAddToggle"' + (state.addOpen ? ' hidden' : '') + '>+ Add your own job</button>' +
380
+ '<button type="button" class="gl-link" id="glAddToggle"' + (state.addOpen ? ' hidden' : '') + '>+ Add your own workflow</button>' +
418
381
  '<div class="gl-add-form"' + (state.addOpen ? '' : ' hidden') + '>' +
419
- '<label for="glAddIdea"><strong>A job you have in mind</strong> <span class="hint">in your own words; LoopEngine shapes it into a job and says if anything looks off</span></label>' +
382
+ '<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>' +
420
383
  '<textarea id="glAddIdea" rows="2" placeholder="e.g. Thank every new customer by email within a day">' + esc(state.addDraft || '') + '</textarea>' +
421
- '<label class="hint gl-share"><input type="checkbox" id="glAddShare"' + (state.addShare ? ' checked' : '') + '> Share the approach behind this job to improve suggestions for everyone</label>' +
384
+ '<label class="hint gl-share"><input type="checkbox" id="glAddShare"' + (state.addShare ? ' checked' : '') + '> Share the approach behind it to improve suggestions for everyone</label>' +
422
385
  '<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>' +
423
386
  '<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>' +
424
387
  '</div>' + notice + '</div>';
425
388
  }
426
389
 
427
- // A one-off job's tries: the latest with its state and result, earlier
428
- // ones folded away.
429
- function tryHtml(t, n) {
430
- var pill = t.status === 'running' ? '<span class="gl-state saved">Working' + ELLIPSIS + '</span>'
431
- : t.status === 'awaiting_approval' ? '<span class="gl-state planning">Waiting for your decision</span>'
432
- : t.status === 'done' ? '<span class="gl-state built">Finished</span>'
433
- : t.status === 'error' ? '<span class="gl-state failed">Failed</span>' : '<span class="gl-state failed">Its record is gone</span>';
434
- return '<div class="gl-try"><div class="gl-row"><strong>Try ' + n + '</strong>' + pill + '<span class="hint">' + esc(new Date(t.at).toLocaleString(undefined, { month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' })) + '</span></div>' +
435
- (t.note ? '<p class="hint" style="margin:0">You asked: ' + esc(t.note) + '</p>' : '') +
436
- (t.status === 'awaiting_approval' ? '<p class="hint" style="margin:0">It asked you something: answer in the agent' + String.fromCharCode(8217) + 's messaging app, or on its Approvals.</p>' : '') +
437
- (t.result ? '<div class="gl-result">' + esc(t.result) + '</div>' : '') +
438
- (t.error ? '<p class="error">' + esc(t.error) + '</p>' : '') + '</div>';
439
- }
440
- function triesHtml(w) {
441
- var tries = w.tries;
442
- var latest = tries[tries.length - 1];
443
- var earlier = tries.slice(0, -1);
444
- var done = w.state === 'done';
445
- return '<div class="gl-doer">Assigned to <strong>' + esc(w.agent.name) + '</strong>' + (done && w.doneAt ? ' ' + String.fromCharCode(183) + ' done ' + esc(new Date(w.doneAt).toLocaleDateString(undefined, { month: 'short', day: 'numeric' })) : '') + '</div>' +
446
- (done ? (w.result ? '<details class="gl-result-wrap" open><summary>The accepted result</summary><div class="gl-result">' + esc(w.result) + '</div></details>' : '') : tryHtml(latest, tries.length)) +
447
- (earlier.length || done ? '<details class="gl-result-wrap"><summary>' + (done ? 'All tries (' + tries.length + ')' : 'Earlier tries (' + earlier.length + ')') + '</summary>' +
448
- (done ? tries : earlier).map(function (t, i) { return tryHtml(t, i + 1); }).join('') + '</details>' : '');
449
- }
450
-
451
- // How a recurring job is done: each workflow that does it, on its agent,
452
- // with how it starts and how it's doing. The detail (its instructions,
453
- // tools, runs) is on the workflow itself: Open.
454
- // On a job's card: what does it, in one line per workflow, each with
455
- // how it's going (filled by fillEvidence) and a link to manage them on
456
- // the job's page.
390
+ // On a built workflow's card: what does it, one line per workflow, each
391
+ // with how it's going (filled by fillEvidence); "then" marks one that
392
+ // starts after another.
457
393
  function doneByHtml(w) {
458
394
  var flows = (w.doers || []).filter(function (d) { return d.type === 'workflow'; });
459
395
  // A chained workflow follows the one that starts it, marked "then".
@@ -471,12 +407,7 @@ ${consoleShellScript}
471
407
  (then ? '<span class="gl-doneby-then">then ' + String.fromCharCode(8594) + '</span>' : '<span class="gl-tag-wf">Workflow</span>') +
472
408
  '<a href="/agents/config?agent=' + encodeURIComponent(d.agent) + '&tab=workflows&workflow=' + encodeURIComponent(d.workflowId) + '" class="gl-slug">' + esc(d.workflowId) + '</a>' +
473
409
  '<span class="gl-agent-pill">' + esc(d.agent) + '</span><span class="hint" data-how-meta>' + ELLIPSIS + '</span></span>';
474
- }).join('') + '<a class="gl-doneby-manage" href="/jobs?job=' + encodeURIComponent(w.id) + '">Manage</a></span>';
475
- }
476
-
477
- // A one-off job's card: the agent it's assigned to.
478
- function assignedHtml(w) {
479
- return '<span class="gl-doneby"><span class="gl-doneby-row"><span class="gl-tag-wf">Assignment</span><span class="gl-agent-pill">' + esc(w.agent.name) + '</span><span class="hint">one run, its result kept with the job</span></span></span>';
410
+ }).join('') + '</span>';
480
411
  }
481
412
 
482
413
  function howHtml(w) {
@@ -498,7 +429,7 @@ ${consoleShellScript}
498
429
  '<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>' +
499
430
  '<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>' +
500
431
  '<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>' +
501
- '<div class="gl-row"><span class="hint">or</span><button type="button" class="gl-link" data-act="another">build a new one for this job</button></div></div>' +
432
+ '<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>' +
502
433
  '<div class="gl-panel" data-panel="addstep" hidden>' +
503
434
  '<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>' +
504
435
  '<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>' +
@@ -516,7 +447,7 @@ ${consoleShellScript}
516
447
  }
517
448
 
518
449
  // Fills each workflow row from its agent's workflow list, and marks the
519
- // job when one is waiting for a decision.
450
+ // suggestion when one is waiting for a decision.
520
451
  function fillEvidence() {
521
452
  var rows = page.querySelectorAll('[data-how]');
522
453
  var agents = {};
@@ -551,76 +482,11 @@ ${consoleShellScript}
551
482
  });
552
483
  }
553
484
 
554
- // The Jobs page: submit a job (no goal needed), then every job on the
555
- // person's list, newest added first, each with when and which goal.
556
- function jobsHtml() {
557
- var n = state.jobNotice;
558
- var notice = !n ? '' : '<div class="gl-notice ' + (n.verdict === 'refused' ? 'bad' : n.verdict === 'added' ? 'good' : 'warn') + '">' +
559
- '<strong>' + (n.verdict === 'refused' ? 'Not added' : n.verdict === 'changed' ? 'Added, with changes' : n.verdict === 'warned' ? 'Added, with a caution' : 'Added to your jobs') + '</strong>' +
560
- (n.note ? '<span>' + esc(n.note) + '</span>' : '') +
561
- (n.alternative ? '<span class="hint">Instead, you could: ' + esc(n.alternative) + '</span>' : '') + '</div>';
562
- var items = state.jobs;
563
- if (jobCreating) return '<div class="gl-card">' +
564
- '<label for="glJobIdea"><strong>Submit a job</strong> <span class="hint">in your own words; LoopEngine shapes it into a job, with its measure and the agent that would do it</span></label>' +
565
- '<textarea id="glJobIdea" rows="2" placeholder="e.g. Answer every customer email within an hour">' + esc(state.jobDraft || '') + '</textarea>' +
566
- '<div class="gl-row"><button type="button" class="gl-btn" id="glJobSubmit">Submit job</button><span class="hint" id="glJobStatus"></span>' +
567
- '<span class="hint gl-push">Not sure what to do? <a href="/goals?new=1">Start from a goal</a> and add the jobs it suggests.</span></div>' +
568
- notice +
569
- '</div>' +
570
- (items.length ? '<div><a class="gl-link" href="/jobs">' + String.fromCharCode(8592) + ' My jobs (' + items.length + ')</a></div>' : '');
571
- if (jobPage) {
572
- var here = items.filter(function (x) { return x.job.id === jobPage; })[0];
573
- return '<div><a class="gl-link" href="/jobs">' + String.fromCharCode(8592) + ' My jobs (' + items.length + ')</a></div>' + notice +
574
- (here ? jobHtml(here.job, here) : '<p class="gl-empty">This job isn' + String.fromCharCode(8217) + 't on your list any more: it may have been removed or discarded.</p>');
575
- }
576
- return notice +
577
- '<p class="hint gl-define">A job is something that needs doing, with a way to tell it' + String.fromCharCode(8217) + 's done. Workflows and agents do jobs: a workflow for a recurring job, an agent for a one-off.</p>' +
578
- '<div class="gl-section"><h3>My jobs <span class="gl-count">' + items.length + '</span></h3>' +
579
- (items.length ? items.map(function (x) { return jobHtml(x.job, x); }).join('')
580
- : '<p class="gl-empty">No jobs yet. <a href="/jobs?new=1">Submit one</a>, or add jobs from a goal' + String.fromCharCode(8217) + 's suggestions with Add to my jobs.</p>') +
581
- '</div>';
582
- }
583
-
584
- function wireJobs() {
585
- var idea = document.getElementById('glJobIdea');
586
- if (idea) idea.addEventListener('input', function () { state.jobDraft = idea.value; });
587
- // The sidebar's Jobs "+ New" (?new=1): straight to the box, once.
588
- if (idea && !state.jobFocused && new URLSearchParams(location.search).has('new')) { state.jobFocused = true; idea.focus(); }
589
- var submit = document.getElementById('glJobSubmit');
590
- if (submit) submit.addEventListener('click', function () {
591
- var text = idea.value.trim();
592
- var status = document.getElementById('glJobStatus');
593
- if (text.length < 5) { status.textContent = 'Say what the job is first.'; return; }
594
- submit.disabled = true;
595
- status.textContent = 'Shaping it' + ELLIPSIS;
596
- api('POST', '/jobs', { idea: text }).then(function (r) {
597
- submit.disabled = false;
598
- if (!r.ok) { status.textContent = r.body.error || 'Could not add it.'; return; }
599
- state.jobNotice = { verdict: r.body.verdict, note: r.body.note, alternative: r.body.alternative };
600
- if (r.body.jobId) {
601
- state.jobDraft = '';
602
- state.openJobs[r.body.jobId] = true;
603
- // Added: back to the list, with it open. A refused one stays on the form.
604
- jobCreating = false;
605
- jobPage = r.body.jobId;
606
- var url = new URL(location.href);
607
- url.searchParams.delete('new');
608
- url.searchParams.set('job', r.body.jobId);
609
- history.replaceState(null, '', url);
610
- }
611
- loadJobs();
612
- });
613
- });
614
- var cards = page.querySelectorAll('.gl-job[data-goal]');
615
- for (var i = 0; i < cards.length; i++) wireCard(cards[i], '/goals/' + encodeURIComponent(cards[i].getAttribute('data-goal')));
616
- }
617
-
618
485
  function goalHtml(g) {
619
486
  var jobs = g.jobs || [];
620
487
  var by = function (s) { return jobs.filter(function (w) { return w.state === s; }); };
621
488
  var suggested = by('suggested');
622
- // Yours: running first, then done.
623
- var kept = by('active').concat(by('done'));
489
+ var kept = by('active');
624
490
  var discarded = by('discarded');
625
491
  var planning = g.status === 'planning';
626
492
  var focus = g.focus || (g.brief && g.brief.focus) || '';
@@ -631,7 +497,7 @@ ${consoleShellScript}
631
497
  (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>' : '') +
632
498
  (g.brief && g.brief.measure ? '<span>' + String.fromCharCode(183) + ' measured by ' + esc(g.brief.measure) + '</span>' : '') + '</div>' : '') +
633
499
  (g.message ? '<p class="gl-why">' + esc(g.message) + '</p>' : '') +
634
- (planning ? '<p class="gl-status">Suggesting jobs' + ELLIPSIS + (secs ? ' ' + secs + 's' : '') + ' It reads your workspace first; this takes about a minute.</p>' : '') +
500
+ (planning ? '<p class="gl-status">Suggesting workflows' + ELLIPSIS + (secs ? ' ' + secs + 's' : '') + ' It reads your workspace first; this takes about a minute.</p>' : '') +
635
501
  (g.status === 'failed' ? '<p class="error">' + esc(g.error || 'Planning failed.') + '</p>' : '') +
636
502
  (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>' +
637
503
  (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>' : '') +
@@ -639,16 +505,17 @@ ${consoleShellScript}
639
505
  (state.justDiscarded ? '<div class="gl-discarded-note" data-discarded="' + esc(state.justDiscarded.id) + '"><span>Discarded <strong>' + esc(state.justDiscarded.title) + '</strong>. Why?</span>' +
640
506
  REASONS.map(function (r) { return '<button type="button" class="gl-btn plain" data-reason="' + r[0] + '">' + r[1] + '</button>'; }).join('') +
641
507
  '<button type="button" class="gl-link" data-undo="1">Undo</button></div>' : '') +
642
- '<div class="gl-section"><h3>Suggested jobs <span class="gl-count">' + suggested.length + '</span></h3>' +
643
- (suggested.length ? suggested.map(function (w) { return jobHtml(w); }).join('') : '<p class="gl-empty">' + (planning ? 'On their way' + ELLIPSIS : 'No suggestions waiting. Generate more for new ideas.') + '</p>') +
644
- '<div class="gl-row"><button type="button" class="gl-btn soft" id="glMore"' + (planning ? ' disabled' : '') + '>Generate more</button><span class="hint">New ideas only: nothing already here, built or discarded comes back.</span></div>' +
508
+ '<div class="gl-section"><h3>Suggested <span class="gl-count">' + suggested.length + '</span></h3>' +
509
+ '<p class="hint gl-define">Workflows that move this goal, and groups of workflows that run in order, one after another.</p>' +
510
+ (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>') +
511
+ '<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>' +
645
512
  addJobHtml(planning) +
646
513
  '</div>' +
647
- '<div class="gl-section"><h3>Your jobs <span class="gl-count">' + kept.length + '</span></h3>' +
648
- (kept.length ? kept.map(function (w) { return jobHtml(w); }).join('') : '<p class="gl-empty">Nothing running yet. Build a workflow for a recurring job, or give a one-off job to an agent.</p>') +
514
+ '<div class="gl-section"><h3>Your workflows <span class="gl-count">' + kept.length + '</span></h3>' +
515
+ (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>') +
649
516
  '</div>' +
650
517
  (discarded.length ? '<div class="gl-section"><button type="button" class="gl-link" id="glShowDiscarded">' + (state.showDiscarded ? 'Hide' : 'Show') + ' discarded (' + discarded.length + ')</button>' +
651
- (state.showDiscarded ? discarded.map(function (w) { return jobHtml(w); }).join('') : '') + '</div>' : '') +
518
+ (state.showDiscarded ? discarded.map(function (w) { return itemHtml(w); }).join('') : '') + '</div>' : '') +
652
519
  '<div><button type="button" class="gl-link" id="glDelete" style="color:var(--bad)">Delete this goal</button></div>';
653
520
  }
654
521
 
@@ -656,23 +523,6 @@ ${consoleShellScript}
656
523
  var title = document.getElementById('glTitle');
657
524
  var lead = document.getElementById('glLead');
658
525
  var newBtn = document.getElementById('glNewBtn');
659
- if (jobsView) {
660
- if (state.jobsStale) { loadJobs(); return; }
661
- var shown = jobPage && state.jobs.filter(function (x) { return x.job.id === jobPage; })[0];
662
- if (title) title.textContent = jobCreating ? 'New job' : jobPage ? 'Job' : 'Jobs';
663
- if (shown) document.title = shown.job.title;
664
- if (lead) {
665
- lead.textContent = 'Everything you want done. Submit a job in your own words, or add jobs from a goal' + String.fromCharCode(8217) + 's suggestions. Build a recurring job into a workflow, or give a one-off job to an agent.';
666
- lead.style.display = jobCreating ? '' : 'none';
667
- }
668
- if (newBtn) { newBtn.hidden = jobCreating; newBtn.textContent = 'New job'; newBtn.setAttribute('href', '/jobs?new=1'); }
669
- page.innerHTML = state.jobsLoaded ? jobsHtml() + (state.error ? '<p class="error">' + esc(state.error) + '</p>' : '') : '<p class="hint">Loading' + ELLIPSIS + '</p>';
670
- state.error = '';
671
- wireJobs();
672
- watchJobs();
673
- fillEvidence();
674
- return;
675
- }
676
526
  // The list, unless there are no goals yet: then the new-goal form.
677
527
  var listing = !state.current && !state.creating && state.goals.length > 0;
678
528
  if (title) title.textContent = state.current ? 'Goal' : listing ? 'Goals' : 'New goal';
@@ -744,9 +594,9 @@ ${consoleShellScript}
744
594
  if (addJob) addJob.addEventListener('click', function () {
745
595
  var idea = document.getElementById('glAddIdea').value.trim();
746
596
  var status = document.getElementById('glAddStatus');
747
- if (idea.length < 5) { status.textContent = 'Say what the job is first.'; return; }
597
+ if (idea.length < 5) { status.textContent = 'Say what the workflow should do first.'; return; }
748
598
  addJob.disabled = true;
749
- status.textContent = 'Shaping it into a job' + ELLIPSIS;
599
+ status.textContent = 'Shaping it into a workflow' + ELLIPSIS;
750
600
  var shareBox = document.getElementById('glAddShare');
751
601
  api('POST', base + '/jobs', { idea: idea, share: !!(shareBox && shareBox.checked) }).then(function (r) {
752
602
  if (!r.ok) { addJob.disabled = false; status.textContent = r.body.error || 'Could not add it.'; return; }
@@ -760,7 +610,7 @@ ${consoleShellScript}
760
610
  if (shown) shown.addEventListener('click', function () { state.showDiscarded = !state.showDiscarded; render(); });
761
611
  var del = document.getElementById('glDelete');
762
612
  if (del) del.addEventListener('click', function () {
763
- if (del.dataset.confirming !== '1') { del.dataset.confirming = '1'; del.textContent = 'Click again to delete this goal (the workflows that do its jobs stay in their agents)'; return; }
613
+ if (del.dataset.confirming !== '1') { del.dataset.confirming = '1'; del.textContent = 'Click again to delete this goal (the workflows built for it stay in their agents)'; return; }
764
614
  api('DELETE', base).then(function () { state.current = null; setUrl(''); reloadSidebar(); load(); });
765
615
  });
766
616
  var cards = page.querySelectorAll('[data-wf]');
@@ -844,7 +694,7 @@ ${consoleShellScript}
844
694
  ev.preventDefault();
845
695
  setJobOpen(card, !card.classList.contains('is-open'));
846
696
  });
847
- // A job's chain: change the step being written, remove a step or a workflow.
697
+ // A suggestion's chain: change the step being written, remove a step or a workflow.
848
698
  ['[data-step-run]', '[data-step-after]', '[data-step-when]'].forEach(function (sel) {
849
699
  var el = card.querySelector(sel);
850
700
  if (el) el.addEventListener('change', function () { stepInputs(card); });
@@ -866,7 +716,7 @@ ${consoleShellScript}
866
716
  var unlinks = card.querySelectorAll('[data-unlink]');
867
717
  for (var ul = 0; ul < unlinks.length; ul++) unlinks[ul].addEventListener('click', function (ev) {
868
718
  var b = ev.currentTarget;
869
- if (b.dataset.confirming !== '1') { b.dataset.confirming = '1'; b.textContent = 'Click again to remove it from this job (it stays on its agent)'; return; }
719
+ if (b.dataset.confirming !== '1') { b.dataset.confirming = '1'; b.textContent = 'Click again to remove it from this goal (it stays on its agent)'; return; }
870
720
  var parts = b.getAttribute('data-unlink').split('|');
871
721
  patch({ action: 'unlink', agent: parts[0], workflowId: parts[1] }, b);
872
722
  });
@@ -913,26 +763,10 @@ ${consoleShellScript}
913
763
  });
914
764
  return;
915
765
  }
916
- if (act === 'again') {
917
- setJobOpen(card, true);
918
- var box = card.querySelector('.gl-again');
919
- if (box) { box.hidden = false; box.querySelector('textarea').focus(); }
920
- return;
921
- }
922
766
  btn.disabled = true;
923
- if (act === 'assign' || act === 'accept') {
924
- var noteBox = card.querySelector('.gl-note');
925
- status.textContent = act === 'assign' ? 'Assigning' + ELLIPSIS : '';
926
- api('POST', base + '/jobs/' + encodeURIComponent(id) + '/' + act, act === 'assign' ? { note: noteBox ? noteBox.value : '' } : {}).then(function (r) {
927
- if (!r.ok) { status.textContent = r.body.error || 'Could not do that.'; btn.disabled = false; return; }
928
- replaceGoal(r.body.goal);
929
- render();
930
- });
931
- return;
932
- }
933
- if (act === 'build') {
767
+ if (act === 'build' || act === 'buildstep') {
934
768
  status.textContent = 'Getting the agent ready' + ELLIPSIS;
935
- api('POST', base + '/jobs/' + encodeURIComponent(id) + '/build').then(function (r) {
769
+ api('POST', base + '/jobs/' + encodeURIComponent(id) + '/build', act === 'buildstep' ? { step: btn.getAttribute('data-step') } : undefined).then(function (r) {
936
770
  if (!r.ok) { status.textContent = r.body.error || 'Could not build it.'; btn.disabled = false; return; }
937
771
  location.href = r.body.url;
938
772
  });
@@ -954,20 +788,18 @@ ${consoleShellScript}
954
788
  </script>
955
789
  </body>
956
790
  </html>`;
957
- const GOALS_LEAD = 'Say what you want to achieve. LoopEngine breaks it into jobs that move it, each with the agent that would do it. Build the recurring ones into workflows, assign the one-off ones to their agent, and generate more when you want new ideas.';
958
- const JOBS_LEAD = 'Everything you want done. Submit a job in your own words, or add jobs from a goal&#8217;s suggestions. Build a recurring job into a workflow, or give a one-off job to an agent.';
791
+ const GOALS_LEAD = 'Say what you want to achieve. LoopEngine suggests workflows that move it, and groups of workflows that run in order, each with the agent that would run it. Build the ones you want, and generate more when you want new ideas.';
959
792
  function goalsPageFor(view) {
960
- const jobs = view === 'jobs' || view === 'job' || view === 'new-job';
961
- const title = view === 'jobs' ? 'Jobs' : view === 'job' ? 'Job' : view === 'new-job' ? 'New job' : view === 'goal' ? 'Goal' : view === 'goals' ? 'Goals' : 'New goal';
962
- // A list or one goal shows no lead; a new goal or job explains itself.
963
- const hideLead = view === 'goal' || view === 'goals' || view === 'jobs' || view === 'job';
793
+ const title = view === 'goal' ? 'Goal' : view === 'goals' ? 'Goals' : 'New goal';
794
+ // A list or one goal shows no lead; a new goal explains itself.
795
+ const hideLead = view === 'goal' || view === 'goals';
964
796
  return goalsPageTemplate
965
- .replace('__GL_HEAD__', `<h1 id="glTitle">${title}</h1><p id="glLead"${hideLead ? ' style="display:none"' : ''}>${jobs ? JOBS_LEAD : GOALS_LEAD}</p>`)
966
- .replace('__GL_NEW_HREF__', jobs ? '/jobs?new=1' : '/goals?new=1')
967
- .replace('__GL_NEW_HIDDEN__', view === 'goals' || view === 'jobs' || view === 'job' ? '' : ' hidden')
968
- .replace('__GL_NEW_LABEL__', jobs ? 'New job' : 'New goal');
797
+ .replace('__GL_HEAD__', `<h1 id="glTitle">${title}</h1><p id="glLead"${hideLead ? ' style="display:none"' : ''}>${GOALS_LEAD}</p>`)
798
+ .replace('__GL_NEW_HREF__', '/goals?new=1')
799
+ .replace('__GL_NEW_HIDDEN__', view === 'goals' ? '' : ' hidden')
800
+ .replace('__GL_NEW_LABEL__', 'New goal');
969
801
  }
970
- const goalsPages = { goals: goalsPageFor('goals'), goal: goalsPageFor('goal'), new: goalsPageFor('new'), jobs: goalsPageFor('jobs'), job: goalsPageFor('job'), 'new-job': goalsPageFor('new-job') };
802
+ const goalsPages = { goals: goalsPageFor('goals'), goal: goalsPageFor('goal'), new: goalsPageFor('new') };
971
803
  export function goalsPageAs(view) {
972
804
  return goalsPages[view];
973
805
  }