loopengine 0.3.87 → 0.3.88

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.
@@ -0,0 +1,21 @@
1
+ import { type WorkspaceRole } from './workspace-roles.js';
2
+ export interface WorkspacePerson {
3
+ email: string;
4
+ role?: WorkspaceRole;
5
+ /** When they were last here (ISO). */
6
+ seen?: string;
7
+ /** The agents they see; absent for every agent. */
8
+ agents?: string[];
9
+ }
10
+ export declare function readPeople(projectDir: string): WorkspacePerson[];
11
+ /** Notes a signed-in person's visit: a new person, a changed role, or an
12
+ * hour since "last here" is written; anything else costs nothing. */
13
+ export declare function recordVisit(projectDir: string, rawEmail: string, role: WorkspaceRole, now?: Date): void;
14
+ /** Sets which agents `email` sees; undefined for every agent. Adds them
15
+ * if they haven't been here yet. */
16
+ export declare function setPersonAgents(projectDir: string, rawEmail: string, agents: string[] | undefined): WorkspacePerson;
17
+ /** Forgets `email` (they see every agent again, if they still have access). */
18
+ export declare function removePerson(projectDir: string, rawEmail: string): void;
19
+ /** The agents a caller may see, or undefined for every agent. Only an
20
+ * approver or viewer is ever limited. */
21
+ export declare function agentsFor(projectDir: string, role: WorkspaceRole, rawEmail: string | undefined): string[] | undefined;
@@ -0,0 +1,75 @@
1
+ // Which agents each person sees, for a hosted workspace with a team
2
+ // (core/workspace-roles.ts). The control plane says who may come in and
3
+ // with what role; this says where an approver or viewer may look: the
4
+ // Inbox shows them only those agents' cases, and they decide only on
5
+ // those. Owners, admins and editors always see every agent.
6
+ //
7
+ // Kept in .loopengine/people.json by email, with each person's role and
8
+ // when they were last here, so Settings → People can list everyone who
9
+ // has signed in. Someone can be added by email before their first visit.
10
+ // No entry, or no agent list, means every agent.
11
+ import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
12
+ import { dirname, join } from 'node:path';
13
+ import { inboxOnly } from './workspace-roles.js';
14
+ /** How often a visit updates "last here". */
15
+ const SEEN_EVERY_MS = 60 * 60 * 1000;
16
+ function peopleFile(projectDir) {
17
+ return join(projectDir, '.loopengine', 'people.json');
18
+ }
19
+ function normalEmail(raw) {
20
+ return raw.trim().toLowerCase();
21
+ }
22
+ export function readPeople(projectDir) {
23
+ try {
24
+ const parsed = JSON.parse(readFileSync(peopleFile(projectDir), 'utf8'));
25
+ return Array.isArray(parsed.people) ? parsed.people.filter((p) => p && typeof p.email === 'string') : [];
26
+ }
27
+ catch {
28
+ return [];
29
+ }
30
+ }
31
+ function writePeople(projectDir, people) {
32
+ const file = peopleFile(projectDir);
33
+ mkdirSync(dirname(file), { recursive: true });
34
+ const temp = `${file}.${process.pid}.tmp`;
35
+ writeFileSync(temp, JSON.stringify({ people: [...people].sort((a, b) => a.email.localeCompare(b.email)) }, null, 2) + '\n');
36
+ renameSync(temp, file);
37
+ }
38
+ /** Notes a signed-in person's visit: a new person, a changed role, or an
39
+ * hour since "last here" is written; anything else costs nothing. */
40
+ export function recordVisit(projectDir, rawEmail, role, now = new Date()) {
41
+ const email = normalEmail(rawEmail);
42
+ if (!email)
43
+ return;
44
+ const people = readPeople(projectDir);
45
+ const known = people.find((p) => p.email === email);
46
+ if (known && known.role === role && known.seen && now.getTime() - Date.parse(known.seen) < SEEN_EVERY_MS)
47
+ return;
48
+ const updated = { ...(known ?? { email }), role, seen: now.toISOString() };
49
+ writePeople(projectDir, [...people.filter((p) => p.email !== email), updated]);
50
+ }
51
+ /** Sets which agents `email` sees; undefined for every agent. Adds them
52
+ * if they haven't been here yet. */
53
+ export function setPersonAgents(projectDir, rawEmail, agents) {
54
+ const email = normalEmail(rawEmail);
55
+ const people = readPeople(projectDir);
56
+ const { agents: _old, ...rest } = people.find((p) => p.email === email) ?? { email };
57
+ const updated = agents ? { ...rest, agents: [...new Set(agents)].sort() } : rest;
58
+ writePeople(projectDir, [...people.filter((p) => p.email !== email), updated]);
59
+ return updated;
60
+ }
61
+ /** Forgets `email` (they see every agent again, if they still have access). */
62
+ export function removePerson(projectDir, rawEmail) {
63
+ const email = normalEmail(rawEmail);
64
+ writePeople(projectDir, readPeople(projectDir).filter((p) => p.email !== email));
65
+ }
66
+ /** The agents a caller may see, or undefined for every agent. Only an
67
+ * approver or viewer is ever limited. */
68
+ export function agentsFor(projectDir, role, rawEmail) {
69
+ if (!inboxOnly(role))
70
+ return undefined;
71
+ if (!rawEmail)
72
+ return undefined;
73
+ const email = normalEmail(rawEmail);
74
+ return readPeople(projectDir).find((p) => p.email === email)?.agents;
75
+ }
package/dist/index.d.ts CHANGED
@@ -134,5 +134,6 @@ export { runGoalPipeline, shapeJob, type GoalPlan, type GoalContext, type Shaped
134
134
  export { LEVERS, PLAYBOOK_VERSION, activePlaybook, setPlaybookProjectDir, type Lever } from './core/system-agents/goal-playbooks.js';
135
135
  export { startPlaybookSync, syncPlaybook, playbookSyncConfig } from './core/playbook-sync.js';
136
136
  export { workspaceRole, canDecide, inboxOnly, inboxOnlyAllows, roleLabel, type WorkspaceRole } from './core/workspace-roles.js';
137
+ export { readPeople, recordVisit, setPersonAgents, removePerson, agentsFor, type WorkspacePerson } from './core/workspace-people.js';
137
138
  export { inboxPageHtml, renderInboxOnlyPage } from './web/inbox-page.js';
138
139
  export { listInbox, getInboxCase, timelineOf, type InboxDeps, type InboxItem, type InboxCase, type InboxPending, type InboxStep } from './web/inbox-admin.js';
package/dist/index.js CHANGED
@@ -125,5 +125,6 @@ export { runGoalPipeline, shapeJob } from './core/system-agents/goal-planner.js'
125
125
  export { LEVERS, PLAYBOOK_VERSION, activePlaybook, setPlaybookProjectDir } from './core/system-agents/goal-playbooks.js';
126
126
  export { startPlaybookSync, syncPlaybook, playbookSyncConfig } from './core/playbook-sync.js';
127
127
  export { workspaceRole, canDecide, inboxOnly, inboxOnlyAllows, roleLabel } from './core/workspace-roles.js';
128
+ export { readPeople, recordVisit, setPersonAgents, removePerson, agentsFor } from './core/workspace-people.js';
128
129
  export { inboxPageHtml, renderInboxOnlyPage } from './web/inbox-page.js';
129
130
  export { listInbox, getInboxCase, timelineOf } from './web/inbox-admin.js';
@@ -88,7 +88,13 @@ export const consoleShellScript = `<script>
88
88
  // On the Inbox, the lists wait for the role: an approver or viewer sees
89
89
  // the Inbox only, and the rest of the sidebar is hidden. Other pages
90
90
  // are only open to the roles that see everything.
91
- var fullAccess = page === 'inbox' ? settings.then(function (s) {
91
+ // The server marks the page for an Inbox-only role before it's shown.
92
+ var markedInboxOnly = Boolean(app && app.classList.contains('le-inbox-only'));
93
+ if (markedInboxOnly) {
94
+ var inboxBrand = document.querySelector('.le-brand');
95
+ if (inboxBrand) inboxBrand.setAttribute('href', '/inbox');
96
+ }
97
+ var fullAccess = markedInboxOnly ? Promise.resolve(false) : page === 'inbox' ? settings.then(function (s) {
92
98
  var role = s && s.signIn && s.signIn.role;
93
99
  var only = role === 'approver' || role === 'viewer';
94
100
  if (only && app) {
@@ -1015,6 +1015,7 @@ ${consoleShellScript}
1015
1015
  rows.map(function (r) { return '<tr><td>' + r[0] + '</td><td>' + r[1] + '</td></tr>'; }).join('') +
1016
1016
  '</tbody></table></section>' +
1017
1017
  (d.timeZone ? '<section><h3>Time zone</h3><div class="source" id="timeZoneBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' : '') +
1018
+ (si.mode === 'hosted' ? '<section><h3>People</h3><div class="source" id="peopleBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' : '') +
1018
1019
  '<section><h3>Shared policies</h3><div class="source" id="policiesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1019
1020
  '<section><h3>Private ability sources</h3><p class="muted" style="margin:0 0 10px">Where your own abilities come from, listed under Private on the Abilities page next to LoopEngine&#39;s official ones.</p><div class="source" id="abilitySourcesBox"><p class="hint">Loading' + String.fromCharCode(8230) + '</p></div></section>' +
1020
1021
  '<section><h3>Updates</h3><div class="source" id="upgradeBox"><p class="hint">Checking for a newer LoopEngine' + String.fromCharCode(8230) + '</p></div></section>';
@@ -1202,6 +1203,126 @@ ${consoleShellScript}
1202
1203
  });
1203
1204
  }
1204
1205
 
1206
+ // ---- People: which agents each approver or viewer sees (hosted
1207
+ // workspaces; invites and roles are in the dashboard). ----
1208
+ var peopleData = null;
1209
+ var settingsDashboardUrl = '';
1210
+ var peopleEditing = '';
1211
+ function roleName(role) {
1212
+ return role ? role.charAt(0).toUpperCase() + role.slice(1) : 'Not here yet';
1213
+ }
1214
+ function limitedRole(role) {
1215
+ return role === 'approver' || role === 'viewer';
1216
+ }
1217
+ function agentChecks(selected, all) {
1218
+ if (!all.length) return '<p class="hint">No agents yet.</p>';
1219
+ return '<div style="display:flex;flex-wrap:wrap;gap:6px 14px">' + all.map(function (a) {
1220
+ return '<label style="display:inline-flex;gap:6px;align-items:center"><input type="checkbox" name="agent" value="' + escapeHtml(a) + '"' + (selected.indexOf(a) !== -1 ? ' checked' : '') + '> ' + escapeHtml(a) + '</label>';
1221
+ }).join('') + '</div>';
1222
+ }
1223
+ function agentsText(p) {
1224
+ return p.agents ? (p.agents.length ? p.agents.map(escapeHtml).join(', ') : 'No agents') : 'All agents';
1225
+ }
1226
+ function renderPeople() {
1227
+ var box = document.getElementById('peopleBox');
1228
+ if (!box || !peopleData) return;
1229
+ var d = peopleData;
1230
+ var intro = '<p style="margin:0 0 10px">Choose which agents each approver or viewer sees. The Inbox shows them only those agents' + String.fromCharCode(8217) + ' cases, and an approver can decide only on those. Owners, admins and editors always see every agent. Invite people and set their role in the ' +
1231
+ '<a href="#" id="peopleDashboard">dashboard</a>.</p>';
1232
+ var rows = d.people.map(function (p) {
1233
+ var editing = peopleEditing === p.email;
1234
+ var full = p.role && !limitedRole(p.role);
1235
+ var agentsCell = full
1236
+ ? '<span class="hint">All agents (' + escapeHtml(roleName(p.role)) + ')</span>'
1237
+ : editing
1238
+ ? '<form class="peopleForm" data-email="' + escapeHtml(p.email) + '" style="display:flex;flex-direction:column;gap:8px">' +
1239
+ '<label style="display:inline-flex;gap:6px;align-items:center"><input type="checkbox" name="all"' + (p.agents ? '' : ' checked') + '> All agents, including new ones</label>' +
1240
+ '<div class="peopleAgents"' + (p.agents ? '' : ' hidden') + '>' + agentChecks(p.agents || [], d.agents) + '</div>' +
1241
+ '<div style="display:flex;gap:6px"><button type="submit" class="primary">Save</button><button type="button" data-people-cancel="1">Cancel</button></div>' +
1242
+ '</form>'
1243
+ : agentsText(p);
1244
+ var actions = !d.canChange || full || editing ? ''
1245
+ : '<button type="button" data-people-edit="' + escapeHtml(p.email) + '">Change</button>' +
1246
+ (p.role ? '' : ' <button type="button" data-people-remove="' + escapeHtml(p.email) + '">Remove</button>');
1247
+ return '<tr><td>' + escapeHtml(p.email) + '</td><td>' + escapeHtml(roleName(p.role)) + (p.seen ? '<div class="hint">last here ' + escapeHtml(new Date(p.seen).toLocaleDateString()) + '</div>' : '') + '</td><td>' + agentsCell + '</td><td style="white-space:nowrap">' + actions + '</td></tr>';
1248
+ }).join('');
1249
+ var table = d.people.length
1250
+ ? '<table><thead><tr><th>Person</th><th>Role</th><th>Sees</th><th></th></tr></thead><tbody>' + rows + '</tbody></table>'
1251
+ : '<p class="hint">Nobody else has signed in yet. People show here after their first visit, or add someone by email below.</p>';
1252
+ var add = d.canChange
1253
+ ? '<form id="peopleAddForm" style="display:flex;flex-direction:column;gap:8px;margin-top:12px;max-width:720px">' +
1254
+ '<label for="peopleEmail" class="hint">Limit someone before their first visit</label>' +
1255
+ '<div style="display:flex;gap:6px;flex-wrap:wrap"><input id="peopleEmail" type="email" placeholder="jane@example.com" style="flex:1;min-width:200px" required></div>' +
1256
+ agentChecks([], d.agents) +
1257
+ '<div><button type="submit">Add</button></div>' +
1258
+ '</form>'
1259
+ : '<p class="hint">Only an owner or admin can change who sees which agents.</p>';
1260
+ box.innerHTML = intro + table + add + '<div id="peopleMsg" class="hint" style="margin-top:8px"></div>';
1261
+ var dash = document.getElementById('peopleDashboard');
1262
+ if (dash) {
1263
+ if (settingsDashboardUrl) dash.setAttribute('href', settingsDashboardUrl);
1264
+ else dash.outerHTML = 'dashboard';
1265
+ }
1266
+ }
1267
+ function sendPeople(method, body) {
1268
+ var msg = document.getElementById('peopleMsg');
1269
+ if (msg) msg.textContent = 'Saving' + String.fromCharCode(8230);
1270
+ return fetch('/config/people', { method: method, headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
1271
+ .then(function (r) { return r.json().then(function (b) { return { ok: r.ok, body: b }; }); })
1272
+ .then(function (r) {
1273
+ if (!r.ok) throw new Error(r.body.error || 'Could not save');
1274
+ peopleData = r.body;
1275
+ peopleEditing = '';
1276
+ renderPeople();
1277
+ var m = document.getElementById('peopleMsg');
1278
+ if (m) m.textContent = 'Saved. It applies on their next page load.';
1279
+ })
1280
+ .catch(function (err) {
1281
+ var m = document.getElementById('peopleMsg');
1282
+ if (m) m.innerHTML = '<span class="error">' + escapeHtml(err.message) + '</span>';
1283
+ });
1284
+ }
1285
+ function checkedAgents(form) {
1286
+ return Array.prototype.map.call(form.querySelectorAll('input[name="agent"]:checked'), function (i) { return i.value; });
1287
+ }
1288
+ document.getElementById('settingsContent').addEventListener('click', function (ev) {
1289
+ var t = ev.target;
1290
+ if (!t || !t.getAttribute) return;
1291
+ if (t.getAttribute('data-people-edit')) { peopleEditing = t.getAttribute('data-people-edit'); renderPeople(); }
1292
+ else if (t.getAttribute('data-people-cancel')) { peopleEditing = ''; renderPeople(); }
1293
+ else if (t.getAttribute('data-people-remove')) sendPeople('DELETE', { email: t.getAttribute('data-people-remove') });
1294
+ });
1295
+ document.getElementById('settingsContent').addEventListener('change', function (ev) {
1296
+ var t = ev.target;
1297
+ if (!t || t.name !== 'all') return;
1298
+ var form = t.closest('.peopleForm');
1299
+ var list = form && form.querySelector('.peopleAgents');
1300
+ if (list) list.hidden = t.checked;
1301
+ });
1302
+ document.getElementById('settingsContent').addEventListener('submit', function (ev) {
1303
+ var form = ev.target;
1304
+ if (form.classList && form.classList.contains('peopleForm')) {
1305
+ ev.preventDefault();
1306
+ sendPeople('PUT', { email: form.getAttribute('data-email'), agents: form.querySelector('input[name="all"]').checked ? null : checkedAgents(form) });
1307
+ } else if (form.id === 'peopleAddForm') {
1308
+ ev.preventDefault();
1309
+ sendPeople('PUT', { email: document.getElementById('peopleEmail').value, agents: checkedAgents(form) });
1310
+ }
1311
+ });
1312
+ function loadPeople() {
1313
+ if (!document.getElementById('peopleBox')) return;
1314
+ fetch('/config/people', { cache: 'no-store' })
1315
+ .then(function (r) {
1316
+ if (r.status === 404) throw new Error('this server' + String.fromCharCode(8217) + 's template is older; update it (Updates, below) to choose who sees which agents');
1317
+ return r.json();
1318
+ })
1319
+ .then(function (d) { peopleData = d; renderPeople(); })
1320
+ .catch(function (err) {
1321
+ var box = document.getElementById('peopleBox');
1322
+ if (box) box.innerHTML = '<p class="hint">People aren' + String.fromCharCode(8217) + 't available: ' + escapeHtml(err.message) + '.</p>';
1323
+ });
1324
+ }
1325
+
1205
1326
  function loadPolicies() {
1206
1327
  if (!document.getElementById('policiesBox')) return;
1207
1328
  fetch('/config/policies', { cache: 'no-store' })
@@ -1355,9 +1476,11 @@ ${consoleShellScript}
1355
1476
  fetch('/config/settings')
1356
1477
  .then(function (r) { return r.json(); })
1357
1478
  .then(function (d) {
1479
+ settingsDashboardUrl = d.signIn && d.signIn.dashboardUrl ? d.signIn.dashboardUrl : '';
1358
1480
  content.innerHTML = renderSettings(d);
1359
1481
  loadedSections.settings = true;
1360
1482
  loadTimeZone();
1483
+ loadPeople();
1361
1484
  loadPolicies();
1362
1485
  loadAbilitySources();
1363
1486
  loadUpgrade();
@@ -41,6 +41,10 @@ export declare function listInbox(deps: InboxDeps, filter?: {
41
41
  }): Promise<{
42
42
  items: InboxItem[];
43
43
  open: number;
44
+ workflows: {
45
+ id: string;
46
+ title: string;
47
+ }[];
44
48
  }>;
45
49
  /** A step in a case's timeline. */
46
50
  export type InboxStep = {
@@ -45,7 +45,11 @@ export async function listInbox(deps, filter = {}) {
45
45
  .filter((i) => !q || `${i.title} ${i.agent} ${i.workflowTitle} ${runParams.get(i.id) ?? ''} ${i.lastBy ?? ''}`.toLowerCase().includes(q))
46
46
  // Waiting first, newest first within each.
47
47
  .sort((a, b) => (b.waiting.length ? 1 : 0) - (a.waiting.length ? 1 : 0) || b.startedAt.localeCompare(a.startedAt));
48
- return { items: shown.slice(0, filter.limit ?? 200), open };
48
+ // Every workflow with a case, whatever the filter, for the workflow picker.
49
+ const workflows = [...new Map(items.filter((i) => i.workflowId).map((i) => [i.workflowId, i.workflowTitle])).entries()]
50
+ .map(([id, title]) => ({ id, title }))
51
+ .sort((a, b) => a.title.localeCompare(b.title));
52
+ return { items: shown.slice(0, filter.limit ?? 200), open, workflows };
49
53
  }
50
54
  /** What the agent did, in order: its words, the tools it used with what
51
55
  * came back, and the questions it asked with their answers. The run's
@@ -131,8 +131,8 @@ ${consoleShellScript}
131
131
 
132
132
  function renderList(data) {
133
133
  var items = data.items || [];
134
- items.forEach(function (i) { if (i.workflowId) workflows[i.workflowId] = i.workflowTitle; });
135
- var options = Object.keys(workflows).sort().map(function (id) { return '<option value="' + esc(id) + '"' + (id === state.workflow ? ' selected' : '') + '>' + esc(workflows[id]) + '</option>'; }).join('');
134
+ (data.workflows || []).forEach(function (w) { workflows[w.id] = w.title; });
135
+ var options = Object.keys(workflows).sort(function (a, b) { return workflows[a].localeCompare(workflows[b]); }).map(function (id) { return '<option value="' + esc(id) + '"' + (id === state.workflow ? ' selected' : '') + '>' + esc(workflows[id]) + '</option>'; }).join('');
136
136
  var rows = items.map(function (i) {
137
137
  return '<a class="ib-row" href="/inbox?case=' + encodeURIComponent(i.id) + '">' +
138
138
  '<span class="le-dot' + (i.waiting.length ? ' warn' : i.status === 'running' ? '' : ' idle') + '" aria-hidden="true"></span>' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loopengine",
3
- "version": "0.3.87",
3
+ "version": "0.3.88",
4
4
  "type": "module",
5
5
  "description": "Runtime for tool-using AI agents with a transparent ReAct loop.",
6
6
  "license": "MIT",
@@ -47,6 +47,8 @@
47
47
  "dist/core/trusted-proxy.d.ts",
48
48
  "dist/core/workspace-roles.js",
49
49
  "dist/core/workspace-roles.d.ts",
50
+ "dist/core/workspace-people.js",
51
+ "dist/core/workspace-people.d.ts",
50
52
  "dist/core/unattended.js",
51
53
  "dist/core/unattended.d.ts",
52
54
  "dist/core/usage.js",