synabun 2.4.4 → 2.4.5
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/CHANGELOG.md +17 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +5 -4
- package/docs/whatsapp.md +3 -3
- package/mcp-server/dist/services/neural-interface.d.ts +1 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +1 -0
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/tools/agents.d.ts +16 -3
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +74 -11
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/services/neural-interface.ts +2 -1
- package/mcp-server/src/tools/agents.ts +67 -11
- package/neural-interface/i18n/en.json +349 -9
- package/neural-interface/i18n/pt-BR.json +349 -9
- package/neural-interface/lib/agents-studio-api.js +7 -2
- package/neural-interface/lib/antigravity/home.js +43 -8
- package/neural-interface/lib/antigravity/tool-call.js +14 -0
- package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
- package/neural-interface/lib/assistant-persona.js +8 -3
- package/neural-interface/lib/assistant-route-gate.js +11 -2
- package/neural-interface/lib/assistant-runtime.js +16 -5
- package/neural-interface/lib/assistant-spilled-output.js +53 -0
- package/neural-interface/lib/browser-default.js +22 -2
- package/neural-interface/lib/browser-extension-bridge.js +50 -3
- package/neural-interface/lib/browser-extension-pin.json +7 -7
- package/neural-interface/lib/browser-extension-protocol.js +30 -1
- package/neural-interface/lib/browser-extension-setup.js +204 -36
- package/neural-interface/lib/remote-policy.js +24 -7
- package/neural-interface/lib/teams/README.md +22 -1
- package/neural-interface/lib/teams/api.js +79 -6
- package/neural-interface/lib/teams/index.js +2 -0
- package/neural-interface/lib/teams/recovery.js +68 -0
- package/neural-interface/lib/teams/scheduler.js +349 -29
- package/neural-interface/lib/teams/worktrees.js +123 -30
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +6 -2
- package/neural-interface/public/shared/agents/studio/ax-api.js +16 -0
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +318 -13
- package/neural-interface/public/shared/agents/studio/ax-teams.js +141 -9
- package/neural-interface/public/shared/browser-extension-updates.js +3 -1
- package/neural-interface/public/shared/extension-setup/es-page.js +23 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
- package/neural-interface/public/shared/extension-update-view.js +1 -1
- package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
- package/neural-interface/public/shared/settings/settings-browser-extension.js +575 -197
- package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
- package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
- package/neural-interface/public/shared/settings/settings-ia.js +2 -2
- package/neural-interface/public/shared/settings/settings-shell.js +5 -0
- package/neural-interface/public/shared/styles.css +196 -13
- package/neural-interface/public/shared/ui-settings.js +48 -11
- package/neural-interface/server.js +20 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,35 +1,77 @@
|
|
|
1
|
-
// The
|
|
2
|
-
// docs/browser-extension-bridge.md → One-button setup).
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// The setup of the everyday-browser extension (Settings → Browser → "Connect your browser";
|
|
2
|
+
// docs/browser-extension-bridge.md → One-button setup). SynaBun finds the browsers, prepares the extension folder and
|
|
3
|
+
// keeps a pairing session open; the owner does the steps no app may do for them (the extensions page, Developer mode,
|
|
4
|
+
// Load unpacked, Allow user scripts); the extension then pairs by itself with a one-time token on SynaBun's own
|
|
5
|
+
// loopback page (SETUP_PAGE_PATH), which its content script recognises.
|
|
6
|
+
//
|
|
7
|
+
// Two ways in. The Settings guide (start with `present: 'none'`) shows the steps in Settings itself: the start prepares
|
|
8
|
+
// the folder and opens the pairing session but opens and shows nothing; the guide then asks, one click each, for the
|
|
9
|
+
// browser's extensions page (openExtensions: the companion page first, once, so the extension finds it when it loads),
|
|
10
|
+
// the browser brought forward for a paste (focus: that same companion page once, then a page that never pairs), the
|
|
11
|
+
// pairing page again (reopen: Pair in <Browser>) and the folder (reveal). The status says `guided`, and the companion page then
|
|
12
|
+
// draws only its pairing status. The older way (start without `present`: the extension popup, older pages) opens the
|
|
13
|
+
// page with its own four steps in the browser. Neither shows the folder by itself: only the owner's click (reveal).
|
|
6
14
|
//
|
|
7
15
|
// The folder's files are the one package this release pins, downloaded from synabun.ai and verified
|
|
8
16
|
// (lib/browser-extension-package.js). A folder that is already there is used as it is, in the same request as before.
|
|
9
17
|
// One that is not there yet, or is older than the pin, is fetched first: the setup is then `downloading` (with the
|
|
10
|
-
// bytes so far), and the
|
|
18
|
+
// bytes so far), and the older way opens its page only once the verified files are in place. A download that
|
|
11
19
|
// fails ends the setup with its code (offline, unavailable, verification failed) and Start again tries once more;
|
|
12
20
|
// nothing is ever installed that did not verify.
|
|
13
21
|
//
|
|
14
22
|
// Every route that reaches this is the owner's (server.js mounts them behind the same guard as pairing and the mode:
|
|
15
|
-
// ownerRouteGuard, this boot's page secret, no automation caller
|
|
16
|
-
//
|
|
23
|
+
// ownerRouteGuard, this boot's page secret, no automation caller; the guide's open-extensions, focus and capabilities
|
|
24
|
+
// check also need Settings' own same-origin request with X-SynaBun-UI). Nothing here starts a program by itself: `exec`
|
|
25
|
+
// is injected (server.js: spawn with an argument array, no shell, detached) and gets a plan from lib/browser-default.js.
|
|
26
|
+
// A request names a browser by its id only; the program comes from the detected install, the address from the catalog.
|
|
17
27
|
//
|
|
18
28
|
// The token: made by ticket(), only while a setup is active and still waiting for the extension, at most
|
|
19
29
|
// MAX_TICKETS times per setup (each one replaces the last), each valid TICKET_MS (and never past the setup's end). The
|
|
20
30
|
// bridge accepts it once, in its pairing handshake, and forgets it (lib/browser-extension-bridge.js
|
|
21
31
|
// beginSetupPairing). It is never logged, never in a status and never in a URL.
|
|
22
|
-
import { launchPlan, revealPlan, SUPPORTED_BROWSER_IDS } from './browser-default.js';
|
|
32
|
+
import { BROWSERS, extensionsPagePlan, launchPlan, revealPlan, SUPPORTED_BROWSER_IDS } from './browser-default.js';
|
|
23
33
|
import { compareVersions, SETUP_PAGE_PATH } from './browser-extension-folder.js';
|
|
24
34
|
import { randomBytes } from 'node:crypto';
|
|
25
35
|
|
|
26
36
|
export const SETUP_STATES = Object.freeze(['idle', 'downloading', 'waiting-for-extension', 'pairing', 'connected', 'unsupported', 'error']);
|
|
27
37
|
/** The codes a download of the extension package can end a setup with (lib/browser-extension-package.js). */
|
|
28
38
|
export const DOWNLOAD_ERRORS = Object.freeze(['EXTENSION_DOWNLOAD_OFFLINE', 'EXTENSION_DOWNLOAD_UNAVAILABLE', 'EXTENSION_VERIFY_FAILED']);
|
|
39
|
+
/** What a start may be told to show: nothing (the Settings guide). Without it, the older way opens its page. */
|
|
40
|
+
export const PRESENT_MODES = Object.freeze(['none']);
|
|
29
41
|
export const SETUP_WINDOW_MS = 15 * 60 * 1000;
|
|
30
42
|
export const TICKET_MS = 2 * 60 * 1000;
|
|
31
43
|
export const MAX_TICKETS = 5;
|
|
44
|
+
/** How long a look at the installed browsers is reused: the guide polls, and each look starts plutil or reg. */
|
|
45
|
+
export const DETECT_CACHE_MS = 30 * 1000;
|
|
46
|
+
/**
|
|
47
|
+
* The wait between the companion page and the extensions page when both are opened by one click. Each launch only
|
|
48
|
+
* starts a program that hands the address to the browser and returns at once, so two started together may arrive in
|
|
49
|
+
* either order; the extensions page should be the tab the owner sees.
|
|
50
|
+
*/
|
|
51
|
+
export const COMPANION_GAP_MS = 800;
|
|
52
|
+
/** How long the capabilities check waits for the extension (lib/browser-extension-bridge.js probe). */
|
|
53
|
+
export const PROBE_TIMEOUT_MS = 4000;
|
|
54
|
+
/** The query of the setup page opened only to bring a browser forward (focus): that page never pairs. */
|
|
55
|
+
export const FOCUS_QUERY = 'focus=1';
|
|
32
56
|
const fail = (code, message = code) => { throw Object.assign(new Error(message), { code }); };
|
|
57
|
+
const PLATFORM_NAMES = Object.freeze({ darwin: 'mac', win32: 'windows' });
|
|
58
|
+
const UNKNOWN_BROWSER = Object.freeze({ id: 'unknown', name: 'Unknown browser', supported: false });
|
|
59
|
+
/**
|
|
60
|
+
* The browser a request names: a body of exactly `{ browser: <supported id> }`. Any other key, a value that is not
|
|
61
|
+
* one of SUPPORTED_BROWSER_IDS (an address, a path, a program, an argument) is INVALID_MESSAGE: nothing of the request
|
|
62
|
+
* ever becomes a program, an argument or an address; those come from the detected install and the catalog.
|
|
63
|
+
*/
|
|
64
|
+
function requestedBrowser(body) {
|
|
65
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) fail('INVALID_MESSAGE');
|
|
66
|
+
const keys = Object.keys(body);
|
|
67
|
+
if (keys.length !== 1 || keys[0] !== 'browser' || typeof body.browser !== 'string' || !SUPPORTED_BROWSER_IDS.includes(body.browser)) fail('INVALID_MESSAGE');
|
|
68
|
+
return body.browser;
|
|
69
|
+
}
|
|
70
|
+
/** A browser by its id, named from the catalog only (never a raw bundle id, ProgId or desktop file). */
|
|
71
|
+
const named = browser => {
|
|
72
|
+
const known = browser && typeof browser.id === 'string' && Object.hasOwn(BROWSERS, browser.id) ? BROWSERS[browser.id] : null;
|
|
73
|
+
return known ? { id: known.id, name: known.name } : { id: UNKNOWN_BROWSER.id, name: UNKNOWN_BROWSER.name };
|
|
74
|
+
};
|
|
33
75
|
|
|
34
76
|
/**
|
|
35
77
|
* Whether the browser should be told to reload the extension: it is connected, the folder holds what this release
|
|
@@ -61,15 +103,53 @@ export function extensionVersions({ connected, extensionVersion, folderVersion,
|
|
|
61
103
|
* `folderVersion()` the version the folder holds, `packageStatus()` → { pinnedVersion, needs, phase, received, total,
|
|
62
104
|
* code, reloadPending } (browser-extension-package.js status; `needs` says that `prepare` will download),
|
|
63
105
|
* `confirmReload()` the setup page saw the extension's content script on this port (browser-extension-package.js; it
|
|
64
|
-
* never clears a repair's Reload).
|
|
106
|
+
* never clears a repair's Reload). `detectMs`: how long a look at the browsers is reused (DETECT_CACHE_MS);
|
|
107
|
+
* `pause(ms)` waits between two launches of one click (tests pass one that does not wait).
|
|
65
108
|
*/
|
|
66
109
|
export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin, platform = process.platform, now = Date.now,
|
|
67
|
-
windowMs = SETUP_WINDOW_MS, ticketMs = TICKET_MS, maxTickets = MAX_TICKETS, folderVersion = () => null, packageStatus = () => ({}), confirmReload = () => false, updateStatus
|
|
110
|
+
windowMs = SETUP_WINDOW_MS, ticketMs = TICKET_MS, maxTickets = MAX_TICKETS, folderVersion = () => null, packageStatus = () => ({}), confirmReload = () => false, updateStatus,
|
|
111
|
+
detectMs = DETECT_CACHE_MS, companionGapMs = COMPANION_GAP_MS, probeTimeoutMs = PROBE_TIMEOUT_MS, pause = ms => new Promise(resolve => setTimeout(resolve, ms)) } = {}) {
|
|
68
112
|
let setup = null;
|
|
69
113
|
// The latest start, from its first step: a cancel or a later start ends it before it prepares or opens anything.
|
|
70
114
|
let attempt = null;
|
|
115
|
+
// The last look at the browsers ({ at, value }) and the one under way. The Settings guide asks for the list while it
|
|
116
|
+
// is open; a look starts plutil or reg, so one is reused for `detectMs` (a start, and ?refresh=1, always look again).
|
|
117
|
+
let detection = null, detecting = null;
|
|
118
|
+
// The browser whose setup made the bridge's current pairing ({ browser: { id, name }, pairedAt }), remembered when
|
|
119
|
+
// state() first sees that pairing and reported while the bridge still holds it. In memory only: after a restart a
|
|
120
|
+
// pairing has no setup to name, and the guide then asks the owner rather than calling an earlier browser ready.
|
|
121
|
+
let pairedThrough = null;
|
|
71
122
|
const pageUrl = () => `${appOrigin()}${SETUP_PAGE_PATH}`;
|
|
123
|
+
// The same page opened only to bring the browser forward (focus): it never asks for a token (es-page.js FOCUS_ONLY).
|
|
124
|
+
const focusUrl = () => `${pageUrl()}?${FOCUS_QUERY}`;
|
|
72
125
|
const describe = browser => browser ? { id: browser.id, name: browser.name, supported: browser.supported === true, extensionsUrl: browser.extensionsUrl || null } : null;
|
|
126
|
+
// The supported browsers a look found, once each; the default as it was found (it may be unsupported or unknown).
|
|
127
|
+
const normalize = found => {
|
|
128
|
+
const installed = [];
|
|
129
|
+
for (const browser of Array.isArray(found?.installedBrowsers) ? found.installedBrowsers : []) {
|
|
130
|
+
if (browser?.supported && SUPPORTED_BROWSER_IDS.includes(browser.id) && !installed.some(b => b.id === browser.id)) installed.push(browser);
|
|
131
|
+
}
|
|
132
|
+
return { browser: found?.browser && typeof found.browser === 'object' ? found.browser : null, installedBrowsers: installed };
|
|
133
|
+
};
|
|
134
|
+
// A look that fails is no browser and none installed, never an error: the guide then says what it could not find.
|
|
135
|
+
function look() {
|
|
136
|
+
const run = Promise.resolve().then(() => detect()).then(normalize, () => normalize(null));
|
|
137
|
+
detecting = run;
|
|
138
|
+
void run.then(value => { if (detecting === run) { detecting = null; detection = { at: now(), value }; } });
|
|
139
|
+
return run;
|
|
140
|
+
}
|
|
141
|
+
function browsers({ refresh = false } = {}) {
|
|
142
|
+
const at = now();
|
|
143
|
+
if (!refresh && detection && at >= detection.at && at - detection.at < detectMs) return Promise.resolve(detection.value);
|
|
144
|
+
if (!refresh && detecting) return detecting;
|
|
145
|
+
return look();
|
|
146
|
+
}
|
|
147
|
+
// An installed supported browser by its id, with its `launch` (never shown): only what a look found is started.
|
|
148
|
+
async function installedBrowser(id) {
|
|
149
|
+
const browser = (await browsers()).installedBrowsers.find(b => b.id === id);
|
|
150
|
+
if (!browser) fail('BROWSER_NOT_INSTALLED');
|
|
151
|
+
return browser;
|
|
152
|
+
}
|
|
73
153
|
function state() {
|
|
74
154
|
if (!setup) return 'idle';
|
|
75
155
|
if (setup.error) return 'error';
|
|
@@ -77,23 +157,43 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
77
157
|
const bridgeStatus = bridge.status();
|
|
78
158
|
// Paired by this setup: a pairing made after it began (its token, or the typed code as a fallback). Connected once
|
|
79
159
|
// the extension's first inventory arrived; "Pairing…" from the token's handshake until then.
|
|
80
|
-
if (bridgeStatus.paired && bridgeStatus.pairedAt !== setup.pairedBefore)
|
|
160
|
+
if (bridgeStatus.paired && bridgeStatus.pairedAt !== setup.pairedBefore) {
|
|
161
|
+
if (pairedThrough?.pairedAt !== bridgeStatus.pairedAt) pairedThrough = setup.browser?.supported ? { browser: named(setup.browser), pairedAt: bridgeStatus.pairedAt } : null;
|
|
162
|
+
return bridgeStatus.connected ? 'connected' : 'pairing';
|
|
163
|
+
}
|
|
81
164
|
if (bridge.setupPairing().attempted) return 'pairing';
|
|
82
165
|
if (now() >= setup.until) { expire(); return 'error'; }
|
|
83
166
|
if (!setup.browser?.supported) return 'unsupported';
|
|
84
167
|
return 'waiting-for-extension';
|
|
85
168
|
}
|
|
169
|
+
// The browser that made the bridge's current pairing through a setup, or null once that pairing is gone or replaced.
|
|
170
|
+
function pairedNow(bridgeStatus) {
|
|
171
|
+
if (pairedThrough && (!bridgeStatus.paired || bridgeStatus.pairedAt !== pairedThrough.pairedAt)) pairedThrough = null;
|
|
172
|
+
return pairedThrough ? { ...pairedThrough.browser } : null;
|
|
173
|
+
}
|
|
86
174
|
function expire() {
|
|
87
175
|
if (!setup || setup.error) return;
|
|
88
176
|
bridge.endSetupPairing(); setup.error = { code: 'SETUP_EXPIRED' };
|
|
89
177
|
}
|
|
90
|
-
async function open(browser) {
|
|
91
|
-
try { const plan = launchPlan(platform, browser,
|
|
178
|
+
async function open(browser, url = pageUrl()) {
|
|
179
|
+
try { const plan = launchPlan(platform, browser, url); await exec(plan.cmd, plan.args); return true; } catch { return false; }
|
|
92
180
|
}
|
|
181
|
+
// Only on the owner's click (POST …/setup/reveal): no start shows the folder by itself.
|
|
93
182
|
async function reveal() {
|
|
94
183
|
if (!setup?.folder) fail('SETUP_NOT_ACTIVE');
|
|
95
|
-
|
|
96
|
-
|
|
184
|
+
const mine = setup;
|
|
185
|
+
try { const plan = revealPlan(platform, mine.folder); await exec(plan.cmd, plan.args); mine.revealed = true; return { ok: true, folder: mine.folder }; }
|
|
186
|
+
catch { return { ok: false, code: 'REVEAL_FAILED', folder: mine.folder }; }
|
|
187
|
+
}
|
|
188
|
+
// The companion page, before the extensions page of the same click: once per setup, only in the setup's own browser
|
|
189
|
+
// and only while the setup still waits for the extension (or downloads it), so the extension finds the page and pairs
|
|
190
|
+
// by itself once it is loaded. True when it was opened now.
|
|
191
|
+
async function openCompanion(browser) {
|
|
192
|
+
const mine = setup;
|
|
193
|
+
if (!mine || mine.opened || mine.companionOpening || mine.browser?.id !== browser.id || !['downloading', 'waiting-for-extension'].includes(state())) return false;
|
|
194
|
+
mine.companionOpening = true;
|
|
195
|
+
try { const opened = await open(browser); if (opened) mine.opened = true; return opened; }
|
|
196
|
+
finally { mine.companionOpening = false; }
|
|
97
197
|
}
|
|
98
198
|
function view() {
|
|
99
199
|
const current = state(), bridgeStatus = bridge.status();
|
|
@@ -103,10 +203,12 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
103
203
|
return {
|
|
104
204
|
state: current,
|
|
105
205
|
...(updateStatus ? { update: updateStatus(bridgeStatus, pkg) } : {}),
|
|
106
|
-
...(setup ? { setupId: setup.id, browser: describe(setup.browser), defaultBrowser: describe(setup.defaultBrowser), installedBrowsers: setup.installed.map(describe),
|
|
206
|
+
...(setup ? { setupId: setup.id, guided: setup.guided === true, browser: describe(setup.browser), defaultBrowser: describe(setup.defaultBrowser), installedBrowsers: setup.installed.map(describe),
|
|
107
207
|
folder: setup.folder, extensionsUrl: setup.browser?.extensionsUrl || null, opened: setup.opened, revealed: setup.revealed, expiresAt: setup.until } : {}),
|
|
108
208
|
...(setup?.error ? { code: setup.error.code } : {}),
|
|
109
209
|
connected: bridgeStatus.connected, paired: bridgeStatus.paired, bridgePort: bridgeStatus.port,
|
|
210
|
+
// Which browser's setup made the current pairing: the guide calls a bridge "ready" for the browser it set up only.
|
|
211
|
+
pairedThrough: pairedNow(bridgeStatus),
|
|
110
212
|
extensionVersion: bridgeStatus.extensionVersion || null, folderVersion: version, pinnedVersion,
|
|
111
213
|
// The bytes so far while the pinned package is on its way (the setup's own download, or an update's).
|
|
112
214
|
...(pkg.phase === 'downloading' ? { download: { received: Number(pkg.received) || 0, total: Number(pkg.total) || 0 } } : {}),
|
|
@@ -119,10 +221,14 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
119
221
|
/**
|
|
120
222
|
* Starts (or restarts) a setup. `browserId`: one of the installed supported browsers, for "open in X instead";
|
|
121
223
|
* without it the default browser, which may be unsupported (then the page is not opened and the state is
|
|
122
|
-
* `unsupported` with the installed browsers to choose from).
|
|
224
|
+
* `unsupported` with the installed browsers to choose from). `present: 'none'` (the Settings guide): the folder
|
|
225
|
+
* and the pairing session only, nothing opened (`guided` in the status); without it the page opens in the browser
|
|
226
|
+
* once the folder is ready. Neither shows the folder: that is reveal(), on the owner's click.
|
|
123
227
|
*/
|
|
124
|
-
async start({ browserId } = {}) {
|
|
228
|
+
async start({ browserId, present } = {}) {
|
|
125
229
|
if (browserId !== undefined && browserId !== null && !SUPPORTED_BROWSER_IDS.includes(browserId)) fail('INVALID_MESSAGE');
|
|
230
|
+
if (present !== undefined && present !== null && !PRESENT_MODES.includes(present)) fail('INVALID_MESSAGE');
|
|
231
|
+
const guided = present === 'none';
|
|
126
232
|
if (setup) { bridge.endSetupPairing(); setup.stop?.abort(); }
|
|
127
233
|
// This start is the current one before its first wait: a cancel during the browser detection, or a later start
|
|
128
234
|
// whose detection ends first, leaves this one nothing to do when its own detection ends.
|
|
@@ -130,31 +236,29 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
130
236
|
const own = { stop: new AbortController() };
|
|
131
237
|
attempt = own;
|
|
132
238
|
const superseded = () => attempt !== own || own.stop.signal.aborted;
|
|
133
|
-
|
|
134
|
-
|
|
239
|
+
// Always a fresh look: the owner may have installed a browser since the guide last asked.
|
|
240
|
+
const detected = await look();
|
|
135
241
|
if (superseded()) return view();
|
|
136
|
-
const installed =
|
|
137
|
-
const defaultBrowser = detected
|
|
242
|
+
const installed = detected.installedBrowsers;
|
|
243
|
+
const defaultBrowser = detected.browser || { ...UNKNOWN_BROWSER, extensionsUrl: null };
|
|
138
244
|
let browser = defaultBrowser;
|
|
139
245
|
if (browserId) {
|
|
140
246
|
browser = installed.find(b => b.id === browserId);
|
|
141
247
|
if (!browser) fail('BROWSER_NOT_INSTALLED');
|
|
142
248
|
}
|
|
143
|
-
setup = { id: randomBytes(12).toString('hex'), startedAt: now(), until: now() + windowMs, browser, defaultBrowser, installed,
|
|
249
|
+
setup = { id: randomBytes(12).toString('hex'), startedAt: now(), until: now() + windowMs, browser, defaultBrowser, installed, guided,
|
|
144
250
|
folder: null, opened: false, revealed: false, tickets: 0, pairedBefore: bridge.status().pairedAt || 0, error: null };
|
|
145
251
|
const mine = setup;
|
|
146
252
|
mine.stop = own.stop;
|
|
147
253
|
// A browser that cannot run the extension gets no download: the page offers the installed ones, and choosing one
|
|
148
254
|
// starts the setup again.
|
|
149
255
|
if (!browser.supported && (packageStatus() || {}).needs) return view();
|
|
150
|
-
// Once the folder is ready
|
|
151
|
-
//
|
|
152
|
-
const
|
|
153
|
-
if (!browser.supported || setup !== mine || superseded()) return;
|
|
256
|
+
// Once the folder is ready, the older way opens the page in the browser (never for a start that was cancelled or
|
|
257
|
+
// replaced meanwhile). The guide opens nothing: each of its steps is the owner's click.
|
|
258
|
+
const presentPage = async () => {
|
|
259
|
+
if (guided || !browser.supported || setup !== mine || superseded()) return;
|
|
154
260
|
mine.opened = await open(browser);
|
|
155
|
-
if (setup
|
|
156
|
-
mine.revealed = (await reveal()).ok === true;
|
|
157
|
-
if (!mine.opened) mine.error = { code: 'OPEN_FAILED' };
|
|
261
|
+
if (setup === mine && !mine.opened) mine.error = { code: 'OPEN_FAILED' };
|
|
158
262
|
};
|
|
159
263
|
// Started in this step, so the answer below already carries a download's progress.
|
|
160
264
|
let preparing;
|
|
@@ -167,15 +271,77 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
167
271
|
const needed = packageStatus() || {};
|
|
168
272
|
if (needed.needs || needed.phase === 'downloading') {
|
|
169
273
|
mine.preparing = true;
|
|
170
|
-
mine.settled = ready.then(async () => { mine.preparing = false; if (setup === mine && !mine.error) await
|
|
274
|
+
mine.settled = ready.then(async () => { mine.preparing = false; if (setup === mine && !mine.error) await presentPage(); }).catch(() => { mine.preparing = false; });
|
|
171
275
|
return view();
|
|
172
276
|
}
|
|
173
277
|
await ready;
|
|
174
278
|
if (setup !== mine || mine.error) return view();
|
|
175
|
-
await
|
|
279
|
+
await presentPage();
|
|
176
280
|
return view();
|
|
177
281
|
},
|
|
178
282
|
status: view, state,
|
|
283
|
+
/**
|
|
284
|
+
* The browsers for the Settings guide (GET …/setup/browsers): { platform, defaultBrowser: { id, name, supported },
|
|
285
|
+
* installedBrowsers: [{ id, name, extensionsUrl }], suggested }. Names and addresses come from the catalog
|
|
286
|
+
* (browser-default.js BROWSERS); no program, bundle id, path or desktop file is ever in it. `suggested`: the default
|
|
287
|
+
* when it is supported and installed, else the first installed one, else null. `refresh`: look again now.
|
|
288
|
+
*/
|
|
289
|
+
async browsers({ refresh = false } = {}) {
|
|
290
|
+
const found = await browsers({ refresh });
|
|
291
|
+
const known = found.browser && typeof found.browser.id === 'string' && Object.hasOwn(BROWSERS, found.browser.id) ? BROWSERS[found.browser.id] : null;
|
|
292
|
+
const defaultBrowser = known ? { id: known.id, name: known.name, supported: known.supported } : { ...UNKNOWN_BROWSER };
|
|
293
|
+
const installedBrowsers = found.installedBrowsers.map(b => ({ id: b.id, name: BROWSERS[b.id].name, extensionsUrl: BROWSERS[b.id].extensionsUrl }));
|
|
294
|
+
const suggested = defaultBrowser.supported && installedBrowsers.some(b => b.id === defaultBrowser.id) ? defaultBrowser.id : installedBrowsers[0]?.id ?? null;
|
|
295
|
+
return { platform: PLATFORM_NAMES[platform] || 'linux', defaultBrowser, installedBrowsers, suggested };
|
|
296
|
+
},
|
|
297
|
+
/**
|
|
298
|
+
* Opens an installed browser's own extensions page (POST …/setup/open-extensions, body exactly `{ browser }`). The
|
|
299
|
+
* address is the catalog's for that browser and the program the one its detected install names
|
|
300
|
+
* (browser-default.js extensionsPagePlan). When a setup for that browser has not opened its companion page yet, that
|
|
301
|
+
* page opens first. Answers { ok, code?, browser: { id, name }, extensionsUrl, companion }: `companion` says the
|
|
302
|
+
* companion page was opened by this click. `ok: false, code: 'OPEN_FAILED'` when the program could not be started.
|
|
303
|
+
*/
|
|
304
|
+
async openExtensions(body) {
|
|
305
|
+
const browser = await installedBrowser(requestedBrowser(body));
|
|
306
|
+
const shown = named(browser), extensionsUrl = BROWSERS[browser.id].extensionsUrl;
|
|
307
|
+
const companion = await openCompanion(browser);
|
|
308
|
+
if (companion) await pause(companionGapMs);
|
|
309
|
+
// `ok` means the program that hands the address to the browser started, never that the page appeared: a launch
|
|
310
|
+
// cannot see the browser's window, and a browser may refuse an address of its own scheme given from outside. The
|
|
311
|
+
// guide keeps its "Page didn't open?" way (copy the address) for that.
|
|
312
|
+
try { const plan = extensionsPagePlan(platform, browser); await exec(plan.cmd, plan.args); return { ok: true, browser: shown, extensionsUrl, companion }; }
|
|
313
|
+
catch { return { ok: false, code: 'OPEN_FAILED', browser: shown, extensionsUrl, companion }; }
|
|
314
|
+
},
|
|
315
|
+
/**
|
|
316
|
+
* Brings an installed browser forward for "Copy address & open <Browser>" (POST …/setup/focus, body exactly
|
|
317
|
+
* `{ browser }`): the owner pastes the copied extensions address into the tab this opens, which replaces it. So that
|
|
318
|
+
* tab is the focus-only page (SETUP_PAGE_PATH?focus=1), which never asks for a token: the paste takes no pairing with
|
|
319
|
+
* it. As with openExtensions, an active setup of that browser that has not opened its companion page yet opens it
|
|
320
|
+
* first, once, behind the focus page; nothing else counts as the companion. Answers { ok, code?, browser: { id, name },
|
|
321
|
+
* extensionsUrl, companion } (`ok` says the launch started, not that the window came forward).
|
|
322
|
+
*/
|
|
323
|
+
async focus(body) {
|
|
324
|
+
const browser = await installedBrowser(requestedBrowser(body));
|
|
325
|
+
const shown = named(browser), extensionsUrl = BROWSERS[browser.id].extensionsUrl;
|
|
326
|
+
const companion = await openCompanion(browser);
|
|
327
|
+
if (companion) await pause(companionGapMs);
|
|
328
|
+
const opened = await open(browser, focusUrl());
|
|
329
|
+
return opened ? { ok: true, browser: shown, extensionsUrl, companion } : { ok: false, code: 'OPEN_FAILED', browser: shown, extensionsUrl, companion };
|
|
330
|
+
},
|
|
331
|
+
/**
|
|
332
|
+
* What the paired extension can do now (POST …/capabilities/check, body `{}`): the bridge's probe, which asks the
|
|
333
|
+
* connected extension and never throws ({ ok, code?, capabilities, legacy }). A bridge without a probe is an older
|
|
334
|
+
* one: { ok: true, capabilities: null, legacy: true }.
|
|
335
|
+
*/
|
|
336
|
+
async capabilities(body) {
|
|
337
|
+
if (body !== undefined && body !== null && (typeof body !== 'object' || Array.isArray(body) || Object.keys(body).length)) fail('INVALID_MESSAGE');
|
|
338
|
+
if (typeof bridge.probe !== 'function') return { ok: true, capabilities: null, legacy: true };
|
|
339
|
+
let result = null;
|
|
340
|
+
try { result = await bridge.probe({ timeoutMs: probeTimeoutMs }); } catch {}
|
|
341
|
+
if (!result || typeof result !== 'object') return { ok: false, code: 'CAPABILITIES_CHECK_FAILED', capabilities: null, legacy: false };
|
|
342
|
+
// The probe's own fields only, so nothing else the bridge may carry reaches the page.
|
|
343
|
+
return { ok: result.ok === true, ...(typeof result.code === 'string' ? { code: result.code } : {}), capabilities: result.capabilities ?? null, legacy: result.legacy === true };
|
|
344
|
+
},
|
|
179
345
|
/**
|
|
180
346
|
* The setup page saw the extension's content script on this server's port (POST …/setup/seen): the browser runs
|
|
181
347
|
* the folder's manifest for this port, so the Reload a port change asked for is done. A repair's Reload is not: the
|
|
@@ -203,7 +369,8 @@ export function createExtensionSetup({ bridge, detect, prepare, exec, appOrigin,
|
|
|
203
369
|
settled: () => setup?.settled || Promise.resolve(),
|
|
204
370
|
reveal,
|
|
205
371
|
/** Opens the setup page again (in the setup's browser). */
|
|
206
|
-
|
|
372
|
+
// (The pairing page, never the focus-only one: the guide's Pair in <Browser> asks for this. `opened` is this launch's.)
|
|
373
|
+
async reopen() { const mine = setup; if (!mine?.browser?.supported) fail('SETUP_NOT_ACTIVE'); const opened = await open(mine.browser); if (setup === mine && opened) mine.opened = true; return { ...view(), opened }; },
|
|
207
374
|
};
|
|
208
375
|
}
|
|
209
376
|
|
|
@@ -219,8 +386,9 @@ export const SETUP_ERROR_TEXT = Object.freeze({
|
|
|
219
386
|
EXTENSION_DOWNLOAD_OFFLINE: 'SynaBun could not reach synabun.ai to download the extension. Check the internet connection, then start "Connect your browser" again.',
|
|
220
387
|
EXTENSION_DOWNLOAD_UNAVAILABLE: 'synabun.ai did not have the extension this SynaBun version needs. Try again later, or update SynaBun.',
|
|
221
388
|
EXTENSION_VERIFY_FAILED: 'The downloaded extension was not the file this SynaBun version expects, so it was not installed. Try again; if it keeps failing, update SynaBun.',
|
|
222
|
-
OPEN_FAILED: 'SynaBun could not open the
|
|
223
|
-
REVEAL_FAILED: 'SynaBun could not show the folder. Copy its path from
|
|
389
|
+
OPEN_FAILED: 'SynaBun could not open the page in the browser. Copy its address from Settings → Browser and open it yourself.',
|
|
390
|
+
REVEAL_FAILED: 'SynaBun could not show the folder. Copy its path from Settings → Browser.',
|
|
391
|
+
CAPABILITIES_CHECK_FAILED: 'SynaBun could not ask the extension what it can do. Try again.',
|
|
224
392
|
INVALID_MESSAGE: 'Invalid setup request.',
|
|
225
393
|
});
|
|
226
394
|
export function setupError(error) {
|
|
@@ -10,9 +10,12 @@
|
|
|
10
10
|
// refuse, user allow rules included; routing always asks (one
|
|
11
11
|
// route card per task is the task's approval); workers get no
|
|
12
12
|
// computer, no "user-authorized-full" and a registered cwd.
|
|
13
|
-
// autonomous —
|
|
14
|
-
//
|
|
15
|
-
//
|
|
13
|
+
// autonomous — never asks: routing is 'never' whatever the session's or the
|
|
14
|
+
// global route mode (saved routes bind, else the brain picks;
|
|
15
|
+
// also on a turn with untrusted content, whose tools are asked
|
|
16
|
+
// at Ask), and on WhatsApp the brain runs bypassPermissions.
|
|
17
|
+
// On WhatsApp it stays until the owner lowers it in Settings;
|
|
18
|
+
// any other channel only until its autonomousUntil, then ask.
|
|
16
19
|
// Ask and Autonomous hold only on a Claude brain: its in-process PreToolUse
|
|
17
20
|
// hook sees every call with its arguments. A Codex or OpenCode brain runs
|
|
18
21
|
// ordinary commands inside its own sandbox / permissions without asking, so a
|
|
@@ -111,13 +114,18 @@ export function brainCapsLevel(policy, { provider = null, now = Date.now() } = {
|
|
|
111
114
|
* The approval mode and plan flag a brain may run with. read-only forces plan
|
|
112
115
|
* mode (`planApproved`: the desktop approved the plan, which may then run);
|
|
113
116
|
* ask forces the approval mode to 'default' (every provider asks there);
|
|
114
|
-
* autonomous keeps what was configured
|
|
117
|
+
* autonomous keeps what was configured, except on WhatsApp, where it is
|
|
118
|
+
* 'bypassPermissions' whatever the panel last used: Autonomous acts without
|
|
119
|
+
* asking, so the phone is never asked to approve a tool (the brain's remote
|
|
120
|
+
* hook still refuses what isDeniedRemoteTool lists, and computer use keeps
|
|
121
|
+
* its own rule). The plan flag is kept either way.
|
|
115
122
|
*/
|
|
116
123
|
export function clampBrainModes(policy, modes = {}, { untrusted = false, now = Date.now(), planApproved = false } = {}) {
|
|
117
124
|
const permissionMode = modes.permissionMode && modes.permissionMode !== 'plan' ? String(modes.permissionMode) : 'default';
|
|
118
125
|
const planMode = modes.planMode === true || modes.permissionMode === 'plan';
|
|
119
126
|
const level = effectiveLevel(policy, { untrusted, now });
|
|
120
|
-
if (!level
|
|
127
|
+
if (!level) return { permissionMode, planMode };
|
|
128
|
+
if (level === 'autonomous') return { permissionMode: policy.channel === 'whatsapp' ? 'bypassPermissions' : permissionMode, planMode };
|
|
121
129
|
if (level === 'ask') return { permissionMode: 'default', planMode };
|
|
122
130
|
return { permissionMode: 'default', planMode: planApproved ? planMode : true };
|
|
123
131
|
}
|
|
@@ -181,10 +189,19 @@ export function remoteComputerDenial(reason = null) {
|
|
|
181
189
|
return COMPUTER_OFF_TEXT[reason] || 'Computer use is not available from WhatsApp right now.';
|
|
182
190
|
}
|
|
183
191
|
|
|
184
|
-
/**
|
|
192
|
+
/**
|
|
193
|
+
* The route mode a remote session runs. Autonomous never asks where a task runs, whatever the
|
|
194
|
+
* session's or the global route mode says ('never': the saved route for the class binds, else the
|
|
195
|
+
* brain's own pick runs), so the phone is never shown a model card. A turn that carries content the
|
|
196
|
+
* owner did not write (a picture, a forwarded or quoted message) is capped at Ask for its tools,
|
|
197
|
+
* not for its route: the owner configured Autonomous. Below Autonomous every task is approved on
|
|
198
|
+
* its route card ('always-ask').
|
|
199
|
+
*/
|
|
185
200
|
export function clampRouteMode(policy, mode, opts = {}) {
|
|
186
201
|
const level = effectiveLevel(policy, opts);
|
|
187
|
-
if (!level
|
|
202
|
+
if (!level) return mode;
|
|
203
|
+
if (level === 'autonomous') return 'never';
|
|
204
|
+
if (opts.untrusted === true && effectiveLevel(policy, { ...opts, untrusted: false }) === 'autonomous') return 'never';
|
|
188
205
|
return 'always-ask';
|
|
189
206
|
}
|
|
190
207
|
|
|
@@ -256,6 +256,10 @@ Where it applies, `report.userShouldRun` is what the user can run themselves (`g
|
|
|
256
256
|
| `landing` | the target branch at the landing's commit: `merged`. Where it was: the team is as before. Anywhere else: reported |
|
|
257
257
|
| a worktree's folder gone | put back from its branch (what was uncommitted in the folder went with the folder) |
|
|
258
258
|
| a slice's branch and folder gone | the slice is `failed` |
|
|
259
|
+
| the integration branch and folder gone, every slice ended or gone, the integration head on the base branch already | the team is `merged` (merged outside `land`: `landed.external: true`, `landed.recovered: true`); nothing is made again |
|
|
260
|
+
| the integration branch and folder gone, every slice ended or gone, nothing joined (no slice `integrated`, the head still the base commit) | the team is `failed`; no empty integration branch is made |
|
|
261
|
+
|
|
262
|
+
A team closed that way gives its claims back, and `removed: true` is written when no branch or folder of it is left; a slice branch that is still there stays, for `remove` (after the landing) or a discard. The integration branch is still made again from its recorded head when any slice is at work or its branch is still there with its folder gone, when the head has commits the base branch does not have, or when the base branch is not there to compare with. Each closing is the action `team_closed` (`state`, `reason: 'merged_outside_landing' | 'nothing_integrated'`, `targetBranch`, `head`, `removed`).
|
|
259
263
|
|
|
260
264
|
It also takes the claims of every team under way again and registers every slice with the worker guard again (the guard's registry is in memory).
|
|
261
265
|
|
|
@@ -301,7 +305,7 @@ They ask git under the rules of a read and change nothing. The tool has no actio
|
|
|
301
305
|
`createTeamScheduler({ teams, coordination, dispatcher, density, router, session, git, dataDir, broadcast, limits })` (`scheduler.js`). `docs/agents.md` → Teams says what it does for the Assistant and the workers; this is what a caller of the library needs to know about it.
|
|
302
306
|
|
|
303
307
|
- **It is the only caller of the library in the server.** `server.js` shares it (`shareTeamScheduler`); the Assistant's API and the Agents Studio routes ask `sharedTeamScheduler()` when a request arrives. A test passes its own.
|
|
304
|
-
- **Its own record** is one JSON file per team in `<dataDir>/teams/<teamId>.json` (the session, the route, the dispatch settings, each slice's runs and retry counts, its status). Everything about git is read from the journal through the library, never kept twice.
|
|
308
|
+
- **Its own record** is one JSON file per team in `<dataDir>/teams/<teamId>.json` (the session, the route, the dispatch settings, each slice's runs and retry counts, its status). Everything about git is read from the journal through the library, never kept twice. `remove(teamId)` deletes that file (and `teams/sandbox/<teamId>.sb`) for a closed team once git and the disk show nothing of it and no worker lives; the journal entry stays (a closed team's journal state is terminal, so `recover()` skips it, and its id is never made again), and a removed record is never saved again (`docs/agents.md` → Teams, Removing a closed team).
|
|
305
309
|
- **A team's steps never overlap**: every step of one team runs after the one before it (`inTurn`), and none runs before the library's `recover()` has.
|
|
306
310
|
- **The run id comes first.** `dispatchSlice` makes the run id, calls `startSlice(teamId, sliceId, { runId })` (or `resolveInSlice`), and only then dispatches with that id (`dispatcher.dispatch(spec, { team, runId })`): the claims are in the run's name before the worker exists. The dispatcher takes `team` and `runId` from the scheduler alone; no request body reaches them.
|
|
307
311
|
- **What it decides that the library leaves open** (the list below this section, as it was written for this phase): workers run with capability `workspace`; `STRAY_CHANGES` is answered with `allowStray: true` (the files stay out, the event names them); a conflict goes to the slice's own worker through `resolveInSlice`; `land` is never called because a team became ready; the workers are stopped before `remove`; the tests run through `test-sandbox.js`; the setup step is `cloneNodeModules()`; a team id is `<title>-<6 hex>`.
|
|
@@ -380,3 +384,20 @@ lastOwnerTurnAt: (sessionId) => _assistantRuntime?.lastOwnerTurnAt?.(sessionId)
|
|
|
380
384
|
With that dependency present, absent, equal or earlier timestamps refuse cleanup. Without it,
|
|
381
385
|
confirmation timing is explicitly reported as unverified. Git failures during removal throw;
|
|
382
386
|
external concurrent filesystem changes cannot be made transactional across Git commands.
|
|
387
|
+
|
|
388
|
+
### A ready team merged outside `land`
|
|
389
|
+
|
|
390
|
+
Somebody may merge a ready team's integration branch into its base branch by hand, leaving its worktrees and
|
|
391
|
+
branches on disk. `onTarget(teamId)` (read only, no lock: a list asks it) answers `null` unless the journal says
|
|
392
|
+
`ready` and git says the recorded integration head, and the live integration branch, are ancestors of
|
|
393
|
+
`refs/heads/<baseBranch>`; then `{ branch, head, targetHead, live, moved, clean, dirty, unmerged, other }`, where
|
|
394
|
+
`clean` is every guarded check above passing against the base branch (`guardedChecks`, the same code the removal
|
|
395
|
+
runs), `dirty` the uncommitted files per worktree, `unmerged` the branches with commits the base branch lacks, and
|
|
396
|
+
`other` git's words for anything else. Live workers are the scheduler's to count (`liveRuns`), not the library's.
|
|
397
|
+
|
|
398
|
+
`remove(teamId, { guarded: true, mergedOutside: true })` reads the team again under the repository's lock, refuses
|
|
399
|
+
(`TEAM_NOT_READY`, `NOT_ON_TARGET`, then the guarded codes) with nothing changed, and otherwise journals the landing
|
|
400
|
+
somebody else made (`merged`, `landed.external: true`) before it removes anything, then removes exactly as a guarded
|
|
401
|
+
cleanup does. The scheduler's `cleanupMerged(teamId, { by: { kind: 'owner' }, userConfirmed: true })` adds the live
|
|
402
|
+
worker check, records the landing on the team, emits `team_cleaned` and removes the team's record. Nothing does this
|
|
403
|
+
at start-up: recovery closes such a team only when its integration branch and worktree are already gone.
|
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
// /api/assistant/team/* a worker's `team` tool: context, post, read, wait, ack, claims, request. Only a
|
|
12
12
|
// run that proves its pin (its terminal token) AND works a team slice now. The
|
|
13
13
|
// team is the run's own, read from the scheduler: no request names one.
|
|
14
|
-
// /api/agents-studio/v1/teams* Agents Studio (the page): the list, one team in full, and the owner's
|
|
15
|
-
// decisions
|
|
14
|
+
// /api/agents-studio/v1/teams* Agents Studio (the page): the list, one team in full, and the owner's
|
|
15
|
+
// decisions: land, discard (with `force`, also the work a discard kept; with
|
|
16
|
+
// `remove`, the record too once nothing is left), clean up a landed team's
|
|
17
|
+
// worktrees, clean up and remove a ready team whose work is on its base branch
|
|
18
|
+
// already (cleanup-merged), remove a closed team's record, clear finished.
|
|
16
19
|
//
|
|
17
20
|
// Every refusal of the library (lib/teams/README.md) and of the scheduler comes back as it is: `{ ok: false, code,
|
|
18
21
|
// message, … }`, with the HTTP status that fits.
|
|
@@ -20,6 +23,7 @@
|
|
|
20
23
|
import { AGENT_DENSITIES, AGENT_DENSITY_WORKERS } from '../agents/density.js';
|
|
21
24
|
import { LANDING_MODES } from './landing.js';
|
|
22
25
|
import { TEAM_MESSAGE_KINDS } from './brief.js';
|
|
26
|
+
import { CLOSED_TEAM_STATUSES } from './scheduler.js';
|
|
23
27
|
|
|
24
28
|
/** Codes that are about the request itself (400), about who asks (403), about something missing (404). The rest is a conflict (409). */
|
|
25
29
|
const STATUS_BY_CODE = Object.freeze({
|
|
@@ -210,11 +214,38 @@ export function registerAssistantTeamRoutes(router, { scheduler, orchestrationGu
|
|
|
210
214
|
}));
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
/**
|
|
217
|
+
/** `alreadyOnTarget` as a list row carries it: where the work is and whether the team could go now, or null. */
|
|
218
|
+
const onTargetRow = (value) => (value && typeof value === 'object' && typeof value.branch === 'string' && value.branch
|
|
219
|
+
? { branch: value.branch, head: typeof value.head === 'string' ? value.head : null, clean: value.clean === true }
|
|
220
|
+
: null);
|
|
221
|
+
const count = (value) => (Number.isInteger(value) && value >= 0 ? value : null);
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* A team as the Agents Studio list shows it: exactly these fields. `removable`: a closed team whose record can go
|
|
225
|
+
* now (nothing of it left on disk or in git, no live run); false for every other team. For a team that waits on the
|
|
226
|
+
* owner (needs attention, ready): `liveRuns` (workers still alive), `left` (its worktrees and branches on disk and in
|
|
227
|
+
* git) and `alreadyOnTarget` (a ready team whose work is on its base branch already: `{ branch, head, clean }`);
|
|
228
|
+
* null when not asked or not known.
|
|
229
|
+
*/
|
|
214
230
|
export const teamListRow = (team) => ({
|
|
215
231
|
id: team.id, project: team.project, title: team.title, status: team.status, density: team.density, slices: team.slices, createdAt: team.createdAt,
|
|
232
|
+
removable: team.removable === true,
|
|
233
|
+
alreadyOnTarget: onTargetRow(team.alreadyOnTarget),
|
|
234
|
+
liveRuns: count(team.liveRuns),
|
|
235
|
+
left: count(team.left),
|
|
216
236
|
});
|
|
217
237
|
|
|
238
|
+
/** Run `fn` over `items`, at most `limit` at a time, the answers in the items' order. */
|
|
239
|
+
async function eachLimited(items, limit, fn) {
|
|
240
|
+
const out = new Array(items.length);
|
|
241
|
+
let next = 0;
|
|
242
|
+
const lane = async () => { while (next < items.length) { const at = next++; out[at] = await fn(items[at], at); } };
|
|
243
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(limit, items.length)) }, lane));
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
/** How many teams the list asks git about at once. */
|
|
247
|
+
export const TEAM_LIST_CONCURRENCY = 4;
|
|
248
|
+
|
|
218
249
|
/**
|
|
219
250
|
* One team as Agents Studio reads it (GET /teams/:id): the plan, its slices, the claims, the integration branch and
|
|
220
251
|
* its last test result, the landing, and the last 100 team events and messages.
|
|
@@ -223,7 +254,15 @@ export function teamDetail(answer) {
|
|
|
223
254
|
const team = answer.team || {};
|
|
224
255
|
return {
|
|
225
256
|
ok: true,
|
|
226
|
-
team: {
|
|
257
|
+
team: {
|
|
258
|
+
...teamListRow({ ...team, removable: team.removal?.removable === true }), state: team.state ?? null, attention: team.attention ?? null, sessionId: team.sessionId ?? null, workflowId: team.workflowId ?? null,
|
|
259
|
+
baseCommit: team.baseCommit ?? null, baseBranch: team.baseBranch ?? null, cap: team.cap ?? null, updatedAt: team.updatedAt ?? null,
|
|
260
|
+
// A closed team: whether its record can go, and what is still on disk or in git when it cannot (null: open).
|
|
261
|
+
removal: team.removal ?? null,
|
|
262
|
+
// A ready team whose work is on its base branch already, in full: where, whether it is clean, and what is
|
|
263
|
+
// not (uncommitted files per worktree, branches with commits the base branch lacks, other blocks).
|
|
264
|
+
alreadyOnTarget: team.alreadyOnTarget ?? null,
|
|
265
|
+
},
|
|
227
266
|
plan: answer.plan,
|
|
228
267
|
slices: (answer.slices || []).map((slice) => ({
|
|
229
268
|
id: slice.id, title: slice.title, status: slice.status, phase: slice.phase, runId: slice.runId, run: slice.run,
|
|
@@ -274,7 +313,18 @@ export function registerTeamStudioRoutes({ route, reader, owner, json, scheduler
|
|
|
274
313
|
|
|
275
314
|
route('get', '/teams', reader, teamReader, run(async (req, res, teams) => {
|
|
276
315
|
const q = req.query || {};
|
|
277
|
-
|
|
316
|
+
const rows = teams.list({ sessionId: sessionOf(req), projectPath: typeof q.project === 'string' && q.project ? q.project : null, open: q.open === '1' || q.open === 'true' });
|
|
317
|
+
// A closed team, and one that waits on the owner, are asked of git and the disk, a few at a time (the page offers
|
|
318
|
+
// Remove, Clear finished and the cards' quick actions from it); a running team is not asked.
|
|
319
|
+
const out = await eachLimited(rows, TEAM_LIST_CONCURRENCY, async (row) => {
|
|
320
|
+
let facts = {};
|
|
321
|
+
try {
|
|
322
|
+
if (typeof teams.overview === 'function') facts = (await teams.overview(row.id)) || {};
|
|
323
|
+
else if (CLOSED_TEAM_STATUSES.includes(row.status) && typeof teams.removability === 'function') facts = { removable: (await teams.removability(row.id)).removable === true };
|
|
324
|
+
} catch { facts = {}; }
|
|
325
|
+
return teamListRow({ ...row, ...facts });
|
|
326
|
+
});
|
|
327
|
+
res.json({ ok: true, teams: out });
|
|
278
328
|
}));
|
|
279
329
|
route('get', '/teams/:id', reader, teamReader, idCheck, run(async (req, res, teams) => {
|
|
280
330
|
const session = sessionOf(req);
|
|
@@ -291,6 +341,29 @@ export function registerTeamStudioRoutes({ route, reader, owner, json, scheduler
|
|
|
291
341
|
}));
|
|
292
342
|
route('post', '/teams/:id/discard', json, owner, idCheck, run(async (req, res, teams) => {
|
|
293
343
|
const body = req.body || {};
|
|
294
|
-
|
|
344
|
+
// `remove: true` (Discard & remove): the record goes too, in the same step, once the discard left nothing.
|
|
345
|
+
send(res, await teams.discard(req.params.id, { by: { kind: 'owner' }, force: body.force === true, remove: body.remove === true, reason: typeof body.reason === 'string' ? body.reason : '' }));
|
|
346
|
+
}));
|
|
347
|
+
// A ready team whose work is on its base branch already: its worktrees, branches and record, in one step, once
|
|
348
|
+
// git says again that nothing would be lost (the owner's page, `userConfirmed: true`).
|
|
349
|
+
route('post', '/teams/:id/cleanup-merged', json, owner, idCheck, run(async (req, res, teams) => {
|
|
350
|
+
if (typeof teams.cleanupMerged !== 'function') return unavailable(res);
|
|
351
|
+
const body = req.body || {};
|
|
352
|
+
send(res, await teams.cleanupMerged(req.params.id, { by: { kind: 'owner' }, userConfirmed: body.userConfirmed === true || body.user_confirmed === true }));
|
|
353
|
+
}));
|
|
354
|
+
// The owner cleans up a landed team's worktrees and branches. The owner's page is the confirmation (with
|
|
355
|
+
// `userConfirmed: true`), so no Assistant turn is asked for; every other check of the scheduler's stays.
|
|
356
|
+
route('post', '/teams/:id/cleanup', json, owner, idCheck, run(async (req, res, teams) => {
|
|
357
|
+
const body = req.body || {};
|
|
358
|
+
send(res, await teams.cleanup(req.params.id, { by: { kind: 'owner' }, userConfirmed: body.userConfirmed === true || body.user_confirmed === true }));
|
|
359
|
+
}));
|
|
360
|
+
// Every closed team that can go; the rest are listed as skipped, with why.
|
|
361
|
+
route('post', '/teams/clear-finished', json, owner, run(async (req, res, teams) => {
|
|
362
|
+
const body = req.body || {};
|
|
363
|
+
send(res, await teams.clearFinished({ by: { kind: 'owner' }, projectPath: typeof body.project === 'string' && body.project ? body.project : null }));
|
|
364
|
+
}));
|
|
365
|
+
// A closed team's record, once nothing of it is left on disk or in git.
|
|
366
|
+
route('delete', '/teams/:id', json, owner, idCheck, run(async (req, res, teams) => {
|
|
367
|
+
send(res, await teams.remove(req.params.id, { by: { kind: 'owner' } }));
|
|
295
368
|
}));
|
|
296
369
|
}
|
|
@@ -86,6 +86,8 @@ export function createTeams({ store, git = createGitRunner(), runTests = createT
|
|
|
86
86
|
plan: async (teamId) => (await worktrees.get(teamId))?.plan || null,
|
|
87
87
|
list: worktrees.list,
|
|
88
88
|
inspect: worktrees.inspect,
|
|
89
|
+
/** A ready team whose work is on its base branch already (merged outside land): where, and whether it is clean. Read only. */
|
|
90
|
+
onTarget: worktrees.onTarget,
|
|
89
91
|
startSlice,
|
|
90
92
|
finishSlice: integration.finishSlice,
|
|
91
93
|
finishReadOnlySlice: async (teamId, sliceId, options) => {
|