loopengine 0.3.68 → 0.3.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web/goals-admin.d.ts +4 -2
- package/dist/web/goals-admin.js +26 -25
- package/dist/web/goals-page.js +17 -20
- package/dist/web/workflow-admin.js +7 -3
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ModelCall } from '../core/run-agent.js';
|
|
2
2
|
import { type GoalBrief, type GoalContext, type GoalNeed, type LeverChoice } from '../core/system-agents/goal-planner.js';
|
|
3
3
|
import { type GoalFocus } from '../core/system-agents/goal-playbooks.js';
|
|
4
|
-
export type GoalJobState = 'suggested' | '
|
|
4
|
+
export type GoalJobState = 'suggested' | 'active' | 'done' | 'discarded';
|
|
5
5
|
/** What does a job: a workflow on an agent, or, for a once job, each try
|
|
6
6
|
* of its assignment (a run of its agent). */
|
|
7
7
|
export type JobDoer = {
|
|
@@ -79,7 +79,7 @@ export interface GoalJob {
|
|
|
79
79
|
measureLink: string;
|
|
80
80
|
state: GoalJobState;
|
|
81
81
|
/** Where a discarded one goes back to on Restore. */
|
|
82
|
-
restoreTo?: 'suggested'
|
|
82
|
+
restoreTo?: 'suggested';
|
|
83
83
|
/** What does it, once built: the workflow (skill id) on its agent. */
|
|
84
84
|
doers: JobDoer[];
|
|
85
85
|
/** When a once job was marked done. */
|
|
@@ -327,6 +327,8 @@ export declare function editAmount(before: string, after: string): EditAmount;
|
|
|
327
327
|
* reason), restored; built (a workflow does it) or done (a once job
|
|
328
328
|
* finished); edited (its request, at Build); then, from its workflow,
|
|
329
329
|
* kept_14d, used (weekly) and removed. */
|
|
330
|
+
/** "saved" is from before suggestions were built or assigned directly;
|
|
331
|
+
* no longer recorded. */
|
|
330
332
|
export type LeverEventType = 'suggested' | 'added' | 'saved' | 'discarded' | 'discard_reason' | 'restored' | 'built' | 'done' | 'edited' | 'kept_14d' | 'used' | 'removed';
|
|
331
333
|
export interface LeverEvent {
|
|
332
334
|
id: string;
|
package/dist/web/goals-admin.js
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
// A job is one piece of the goal, with its own measure: recurring (done
|
|
8
8
|
// by a workflow on an agent) or once (a one-off piece of work, assigned to
|
|
9
9
|
// an agent as one unattended run, or done with it in Chat). It's in one
|
|
10
|
-
// of
|
|
11
|
-
// suggested the planner proposed it (on create or Generate more)
|
|
12
|
-
//
|
|
10
|
+
// of four states:
|
|
11
|
+
// suggested the planner proposed it (on create or Generate more), or the
|
|
12
|
+
// person added it; it's built or assigned straight from here
|
|
13
13
|
// active a workflow does it (Build linked the real workflow back),
|
|
14
14
|
// or, for a once job, it's been assigned and not accepted yet
|
|
15
15
|
// done a once job whose result the person accepted, or marked done
|
|
@@ -103,7 +103,7 @@ export function migrateGoalFiles(deps) {
|
|
|
103
103
|
const raw = JSON.parse(readFileSync(join(dir, f), 'utf8'));
|
|
104
104
|
if (Array.isArray(raw.jobs) || !Array.isArray(raw.workflows))
|
|
105
105
|
continue;
|
|
106
|
-
write(deps, migrateGoal(raw));
|
|
106
|
+
write(deps, withoutSaved(migrateGoal(raw)));
|
|
107
107
|
changed++;
|
|
108
108
|
}
|
|
109
109
|
catch (err) {
|
|
@@ -112,11 +112,18 @@ export function migrateGoalFiles(deps) {
|
|
|
112
112
|
}
|
|
113
113
|
return changed;
|
|
114
114
|
}
|
|
115
|
+
/** Jobs once saved (a state since removed) are suggestions again, ready
|
|
116
|
+
* to build or assign; a discarded one restores to a suggestion. */
|
|
117
|
+
function withoutSaved(goal) {
|
|
118
|
+
if (!goal.jobs.some((j) => j.state === 'saved' || j.restoreTo === 'saved'))
|
|
119
|
+
return goal;
|
|
120
|
+
return { ...goal, jobs: goal.jobs.map((j) => ({ ...j, ...(j.state === 'saved' ? { state: 'suggested' } : {}), ...(j.restoreTo === 'saved' ? { restoreTo: 'suggested' } : {}) })) };
|
|
121
|
+
}
|
|
115
122
|
export function getGoal(deps, id) {
|
|
116
123
|
const file = goalFile(deps, id);
|
|
117
124
|
if (!existsSync(file))
|
|
118
125
|
throw new GoalError('No such goal');
|
|
119
|
-
const goal = migrateGoal(JSON.parse(readFileSync(file, 'utf8')));
|
|
126
|
+
const goal = withoutSaved(migrateGoal(JSON.parse(readFileSync(file, 'utf8'))));
|
|
120
127
|
if (goal.status === 'planning' && Date.now() - Date.parse(goal.updatedAt) > STALE_PLANNING_MS && !running.has(id)) {
|
|
121
128
|
return write(deps, { ...goal, status: 'failed', error: 'Planning was interrupted. Try Generate more.', updatedAt: now() });
|
|
122
129
|
}
|
|
@@ -300,19 +307,13 @@ function updateWorkflow(deps, goal, jobId, change) {
|
|
|
300
307
|
export function setWorkflowState(deps, id, workflowId, action, reason) {
|
|
301
308
|
const goal = getGoal(deps, id);
|
|
302
309
|
const w = findWorkflow(goal, workflowId);
|
|
303
|
-
if (action === 'save') {
|
|
304
|
-
if (w.state !== 'suggested')
|
|
305
|
-
throw new GoalError('Only a suggestion can be saved.');
|
|
306
|
-
recordLeverEvent(deps, goal, w, 'saved');
|
|
307
|
-
return updateWorkflow(deps, goal, workflowId, (x) => ({ ...x, state: 'saved' }));
|
|
308
|
-
}
|
|
309
310
|
if (action === 'discard') {
|
|
310
311
|
if (w.state === 'discarded')
|
|
311
312
|
return goal;
|
|
312
313
|
if (w.state === 'active' && w.kind !== 'once')
|
|
313
314
|
throw new GoalError('A workflow does this job: remove it from its agent instead.');
|
|
314
315
|
recordLeverEvent(deps, goal, w, 'discarded');
|
|
315
|
-
return updateWorkflow(deps, goal, workflowId, (x) => ({ ...x, state: 'discarded', restoreTo:
|
|
316
|
+
return updateWorkflow(deps, goal, workflowId, (x) => ({ ...x, state: 'discarded', restoreTo: 'suggested' }));
|
|
316
317
|
}
|
|
317
318
|
if (action === 'restore') {
|
|
318
319
|
if (w.state !== 'discarded')
|
|
@@ -325,15 +326,15 @@ export function setWorkflowState(deps, id, workflowId, action, reason) {
|
|
|
325
326
|
throw new GoalError('Only a one-off job is marked done.');
|
|
326
327
|
if (w.state === 'done')
|
|
327
328
|
return goal;
|
|
328
|
-
if (w.state !== '
|
|
329
|
-
throw new GoalError('
|
|
329
|
+
if (w.state !== 'suggested' && w.state !== 'active')
|
|
330
|
+
throw new GoalError('Restore it first.');
|
|
330
331
|
recordLeverEvent(deps, goal, w, 'done', { newAgent: Boolean(w.agentCreated) });
|
|
331
332
|
return updateWorkflow(deps, goal, workflowId, (x) => ({ ...x, state: 'done', doneAt: now() }));
|
|
332
333
|
}
|
|
333
334
|
if (action === 'undone') {
|
|
334
335
|
if (w.state !== 'done')
|
|
335
336
|
return goal;
|
|
336
|
-
return updateWorkflow(deps, goal, workflowId, ({ doneAt: _d, ...x }) => ({ ...x, state: '
|
|
337
|
+
return updateWorkflow(deps, goal, workflowId, ({ doneAt: _d, ...x }) => ({ ...x, state: x.doers.length ? 'active' : 'suggested' }));
|
|
337
338
|
}
|
|
338
339
|
if (action === 'reason') {
|
|
339
340
|
if (w.state !== 'discarded')
|
|
@@ -345,7 +346,7 @@ export function setWorkflowState(deps, id, workflowId, action, reason) {
|
|
|
345
346
|
recordLeverEvent(deps, goal, w, 'discard_reason', { reason: reason });
|
|
346
347
|
return updateWorkflow(deps, goal, workflowId, (x) => ({ ...x, discardReason: reason }));
|
|
347
348
|
}
|
|
348
|
-
throw new GoalError('action must be
|
|
349
|
+
throw new GoalError('action must be discard, restore, done, undone or reason');
|
|
349
350
|
}
|
|
350
351
|
/** Build: makes the suggested agent when there is none by that name,
|
|
351
352
|
* then returns where the work starts. A recurring job goes to Build a
|
|
@@ -359,8 +360,8 @@ export async function prepareBuild(deps, id, workflowId, opts = {}) {
|
|
|
359
360
|
throw new GoalError('This job is assigned already.');
|
|
360
361
|
if (w.state === 'active' && !opts.another)
|
|
361
362
|
throw new GoalError('A workflow already does this job: add another workflow to it instead.');
|
|
362
|
-
if (w.state !== '
|
|
363
|
-
throw new GoalError('
|
|
363
|
+
if (w.state !== 'suggested' && w.state !== 'active')
|
|
364
|
+
throw new GoalError('Restore it first.');
|
|
364
365
|
let createdAgent = false;
|
|
365
366
|
if (!deps.agentExists(w.agent.name)) {
|
|
366
367
|
await deps.createAgent(w.agent.name, w.agent.instructions || `You help with: ${w.title}.`);
|
|
@@ -431,7 +432,7 @@ export async function addJob(deps, id, input) {
|
|
|
431
432
|
}
|
|
432
433
|
const job = {
|
|
433
434
|
...toJob(shaped.job, goal.rounds || 1, deps),
|
|
434
|
-
state: '
|
|
435
|
+
state: 'suggested',
|
|
435
436
|
...(share ? {} : { keepPrivate: true }),
|
|
436
437
|
added: { idea, verdict: shaped.verdict, ...(shaped.note ? { note: shaped.note } : {}), ...(shaped.alternative ? { alternative: shaped.alternative } : {}) },
|
|
437
438
|
};
|
|
@@ -517,11 +518,11 @@ export function editJob(deps, id, jobId, body) {
|
|
|
517
518
|
const info = deps.workflowInfo?.(ref.agent, ref.workflowId);
|
|
518
519
|
if (!info)
|
|
519
520
|
throw new GoalError(`${ref.agent} has no workflow ${ref.workflowId}.`);
|
|
520
|
-
if (job.state !== '
|
|
521
|
-
throw new GoalError('
|
|
521
|
+
if (job.state !== 'suggested' && job.state !== 'active')
|
|
522
|
+
throw new GoalError('Restore it first.');
|
|
522
523
|
if (job.doers.some((d) => d.type === 'workflow' && sameRef(d, ref)))
|
|
523
524
|
return goal;
|
|
524
|
-
if (job.state === '
|
|
525
|
+
if (job.state === 'suggested')
|
|
525
526
|
recordLeverEvent(deps, goal, job, 'built', { newAgent: false });
|
|
526
527
|
return updateWorkflow(deps, goal, jobId, (x) => ({ ...x, state: 'active', doers: [...x.doers, { type: 'workflow', ...ref, title: info.title, at: now() }] }));
|
|
527
528
|
}
|
|
@@ -530,7 +531,7 @@ export function editJob(deps, id, jobId, body) {
|
|
|
530
531
|
return updateWorkflow(deps, goal, jobId, (x) => {
|
|
531
532
|
const doers = x.doers.filter((d) => !(d.type === 'workflow' && sameRef(d, ref)));
|
|
532
533
|
const chain = (x.chain ?? []).filter((st) => !sameRef(st.after, ref) && !sameRef(st.run, ref));
|
|
533
|
-
return { ...x, doers, ...(chain.length ? { chain } : { chain: undefined }), state: doers.length ? x.state : '
|
|
534
|
+
return { ...x, doers, ...(chain.length ? { chain } : { chain: undefined }), state: doers.length ? x.state : 'suggested' };
|
|
534
535
|
});
|
|
535
536
|
}
|
|
536
537
|
if (body.action === 'chain') {
|
|
@@ -592,8 +593,8 @@ export async function assignJob(deps, id, jobId, input = {}) {
|
|
|
592
593
|
const job = findWorkflow(goal, jobId);
|
|
593
594
|
if (job.kind !== 'once')
|
|
594
595
|
throw new GoalError('Only a one-off job is assigned; build a recurring job into a workflow.');
|
|
595
|
-
if (job.state !== '
|
|
596
|
-
throw new GoalError(job.state === 'done' ? 'This job is done: reopen it first.' : '
|
|
596
|
+
if (job.state !== 'suggested' && job.state !== 'active')
|
|
597
|
+
throw new GoalError(job.state === 'done' ? 'This job is done: reopen it first.' : 'Restore it first.');
|
|
597
598
|
const tries = job.doers.filter((d) => d.type === 'assignment');
|
|
598
599
|
const last = tries[tries.length - 1];
|
|
599
600
|
let previous;
|
package/dist/web/goals-page.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// (and the workspace's front page, /) starts one, and /goals?goal=<id>
|
|
3
3
|
// opens one. A goal breaks into jobs, each with its own measure: recurring
|
|
4
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
|
-
// (each with the agent it would go into),
|
|
7
|
-
// generate more, and build
|
|
8
|
-
// it doesn't exist (web/goals-admin.ts
|
|
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
|
|
9
|
+
// behind /goals/*). Same shell and
|
|
9
10
|
// styles as the other console pages; like them, its inline script avoids
|
|
10
11
|
// backslashes and template placeholders, since it lives inside a template
|
|
11
12
|
// literal.
|
|
@@ -141,7 +142,7 @@ ${consoleSidebarHtml}
|
|
|
141
142
|
<div class="le-head plain">
|
|
142
143
|
<div class="le-head-row">
|
|
143
144
|
<div class="le-title"><button type="button" class="le-menu-btn" data-le-menu aria-label="Open navigation">☰</button>
|
|
144
|
-
<div><h1 id="glTitle">Goals</h1><p id="glLead">Say what you want to achieve. LoopEngine breaks it into jobs that move it, each with the agent that would do it.
|
|
145
|
+
<div><h1 id="glTitle">Goals</h1><p id="glLead">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.</p></div>
|
|
145
146
|
</div>
|
|
146
147
|
<a class="gl-btn gl-new-btn" id="glNewBtn" href="/goals?new=1" hidden>New goal</a>
|
|
147
148
|
</div>
|
|
@@ -236,9 +237,8 @@ ${consoleShellScript}
|
|
|
236
237
|
var parts = [];
|
|
237
238
|
if (g.status === 'planning') parts.push('<span class="gl-state planning">Suggesting' + ELLIPSIS + '</span>');
|
|
238
239
|
if (g.status === 'failed') parts.push('<span class="gl-state failed">Failed</span>');
|
|
239
|
-
var suggested = count(g, 'suggested'),
|
|
240
|
+
var suggested = count(g, 'suggested'), active = count(g, 'active'), done = count(g, 'done');
|
|
240
241
|
if (suggested) parts.push(suggested + ' suggested');
|
|
241
|
-
if (saved) parts.push(saved + ' saved');
|
|
242
242
|
if (active) parts.push('<span class="gl-state built">' + active + ' running</span>');
|
|
243
243
|
if (done) parts.push(done + ' done');
|
|
244
244
|
if (!parts.length) parts.push('No jobs kept yet');
|
|
@@ -283,19 +283,16 @@ ${consoleShellScript}
|
|
|
283
283
|
var doer = (w.doers || [])[0];
|
|
284
284
|
var t = lastTry(w);
|
|
285
285
|
var btn = function (act, label, cls) { return '<button type="button" class="gl-btn ' + (cls || '') + '" data-act="' + act + '">' + label + '</button>'; };
|
|
286
|
-
var primary = w.state === 'suggested' ? btn('
|
|
287
|
-
: w.state === '
|
|
288
|
-
: w.state === 'saved' ? btn('build', 'Build it')
|
|
286
|
+
var primary = w.state === 'suggested' && once ? btn('assign', 'Assign')
|
|
287
|
+
: w.state === 'suggested' ? btn('build', 'Build it')
|
|
289
288
|
: w.state === 'active' && once && t && t.status === 'done' ? btn('accept', 'Accept')
|
|
290
289
|
: w.state === 'active' && once && t && (t.status === 'error' || t.status === 'gone') ? btn('again', 'Try again')
|
|
291
290
|
: w.state === 'discarded' ? btn('restore', 'Restore', 'plain') : '';
|
|
292
|
-
var more = w.state === 'suggested' ? btn('discard', 'Discard', 'plain')
|
|
293
|
-
: w.state === '
|
|
294
|
-
: w.state === 'saved' ? btn('discard', 'Discard', 'plain')
|
|
291
|
+
var more = w.state === 'suggested' && once ? btn('build', 'Open in Chat', 'plain') + btn('done', 'Mark done', 'plain') + btn('discard', 'Discard', 'plain')
|
|
292
|
+
: w.state === 'suggested' ? btn('discard', 'Discard', 'plain')
|
|
295
293
|
: w.state === 'active' && once ? (t && t.status === 'done' ? btn('again', 'Ask again', 'soft') : '') + btn('done', 'Mark done', 'plain') + btn('discard', 'Discard', 'plain')
|
|
296
294
|
: w.state === 'done' ? btn('undone', 'Reopen', 'plain') : '';
|
|
297
|
-
var pill = w.state === '
|
|
298
|
-
: 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>')
|
|
295
|
+
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>')
|
|
299
296
|
: w.state === 'active' ? '<span class="gl-state built">Running</span>'
|
|
300
297
|
: w.state === 'done' ? '<span class="gl-state built">Done</span>'
|
|
301
298
|
: w.state === 'discarded' ? '<span class="gl-state">Discarded</span>' : '';
|
|
@@ -447,8 +444,8 @@ ${consoleShellScript}
|
|
|
447
444
|
var jobs = g.jobs || [];
|
|
448
445
|
var by = function (s) { return jobs.filter(function (w) { return w.state === s; }); };
|
|
449
446
|
var suggested = by('suggested');
|
|
450
|
-
// Yours: running first, then
|
|
451
|
-
var kept = by('active').concat(by('
|
|
447
|
+
// Yours: running first, then done.
|
|
448
|
+
var kept = by('active').concat(by('done'));
|
|
452
449
|
var discarded = by('discarded');
|
|
453
450
|
var planning = g.status === 'planning';
|
|
454
451
|
var focus = g.focus || (g.brief && g.brief.focus) || '';
|
|
@@ -468,11 +465,11 @@ ${consoleShellScript}
|
|
|
468
465
|
'<button type="button" class="gl-link" data-undo="1">Undo</button></div>' : '') +
|
|
469
466
|
'<div class="gl-section"><h3>Suggested jobs <span class="gl-count">' + suggested.length + '</span></h3>' +
|
|
470
467
|
(suggested.length ? suggested.map(jobHtml).join('') : '<p class="gl-empty">' + (planning ? 'On their way' + ELLIPSIS : 'No suggestions waiting. Generate more for new ideas.') + '</p>') +
|
|
471
|
-
'<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
|
|
468
|
+
'<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>' +
|
|
469
|
+
addJobHtml(planning) +
|
|
472
470
|
'</div>' +
|
|
473
471
|
'<div class="gl-section"><h3>Your jobs <span class="gl-count">' + kept.length + '</span></h3>' +
|
|
474
|
-
(kept.length ? kept.map(jobHtml).join('') : '<p class="gl-empty">
|
|
475
|
-
addJobHtml(planning) +
|
|
472
|
+
(kept.length ? kept.map(jobHtml).join('') : '<p class="gl-empty">Nothing running yet. Build it turns a recurring suggestion into a workflow on its agent; Assign gives a one-off one to its agent.</p>') +
|
|
476
473
|
'</div>' +
|
|
477
474
|
(discarded.length ? '<div class="gl-section"><button type="button" class="gl-link" id="glShowDiscarded">' + (state.showDiscarded ? 'Hide' : 'Show') + ' discarded (' + discarded.length + ')</button>' +
|
|
478
475
|
(state.showDiscarded ? discarded.map(jobHtml).join('') : '') + '</div>' : '') +
|
|
@@ -370,9 +370,13 @@ export async function prepareMcpAbilities(plan, deps) {
|
|
|
370
370
|
continue;
|
|
371
371
|
plan.skill.body = plan.skill.body.replace(new RegExp(`(?<![A-Za-z0-9_])${remote.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![A-Za-z0-9_])`, 'g'), name);
|
|
372
372
|
}
|
|
373
|
-
// Added to the agent as an app, with just these tools
|
|
374
|
-
|
|
375
|
-
|
|
373
|
+
// Added to the agent as an app, with just these tools, next to any of
|
|
374
|
+
// the same app's tools other steps already turn on (a step on a tool of
|
|
375
|
+
// an app the agent has, resolved before): merged, never replaced.
|
|
376
|
+
if (tools.length) {
|
|
377
|
+
const before = plan.apps?.find((a) => a.id === planned.id)?.tools ?? [];
|
|
378
|
+
plan.apps = [...(plan.apps ?? []).filter((a) => a.id !== planned.id), { id: planned.id, title: planned.title, tools: [...new Set([...before, ...tools])] }];
|
|
379
|
+
}
|
|
376
380
|
}
|
|
377
381
|
delete plan.mcpServers;
|
|
378
382
|
return { failed };
|