toolroll 0.9.74 → 0.9.75
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 +31 -0
- package/dist/assignment.d.ts +3 -0
- package/dist/assignment.js +27 -8
- package/dist/browser/workspace.js +27 -27
- package/dist/browser-workspace.d.ts +1 -1
- package/dist/chat-acceptance.d.ts +4 -1
- package/dist/chat-acceptance.js +13 -3
- package/dist/cli.js +1 -1
- package/dist/coding-handoff.js +4 -3
- package/dist/coding-ui.js +2 -2
- package/dist/coding-workspace.js +16 -4
- package/dist/contracts/console-api.d.ts +5 -1
- package/dist/contracts/console-api.js +10 -0
- package/dist/control-ui.d.ts +3 -2
- package/dist/control-ui.js +7 -2
- package/dist/demo.js +5 -3
- package/dist/desktop-update.d.ts +3 -0
- package/dist/desktop-update.js +43 -9
- package/dist/first-run.d.ts +8 -5
- package/dist/first-run.js +39 -6
- package/dist/flow-card-task.js +3 -2
- package/dist/flow-unattended.d.ts +2 -0
- package/dist/flow-unattended.js +12 -1
- package/dist/integrations.d.ts +4 -3
- package/dist/integrations.js +5 -6
- package/dist/lead-contract.d.ts +1 -1
- package/dist/lead-contract.js +2 -2
- package/dist/lead-follow.js +3 -1
- package/dist/openrouter-models.d.ts +5 -2
- package/dist/openrouter-models.js +7 -4
- package/dist/operate.js +2 -0
- package/dist/project-learning.js +44 -6
- package/dist/project-tools.js +19 -1
- package/dist/pull-request-ui.d.ts +1 -1
- package/dist/pull-request-ui.js +5 -1
- package/dist/push.d.ts +2 -0
- package/dist/push.js +24 -19
- package/dist/read-only-request.d.ts +4 -0
- package/dist/read-only-request.js +15 -0
- package/dist/repository-context.js +6 -1
- package/dist/result-follow-ups.js +20 -1
- package/dist/result-review.js +5 -1
- package/dist/serve.js +162 -6
- package/dist/server/agents-live-filed.d.ts +17 -0
- package/dist/server/agents-live-filed.js +97 -0
- package/dist/server/agents-live-room.js +4 -1
- package/dist/server/chat.js +31 -23
- package/dist/server/http.d.ts +5 -0
- package/dist/server/last-checks.d.ts +17 -0
- package/dist/server/last-checks.js +22 -0
- package/dist/server/pages.js +18 -4
- package/dist/server/people-tokens.js +7 -4
- package/dist/server/render-pages.d.ts +2 -1
- package/dist/server/render-pages.js +28 -24
- package/dist/server/render-results.d.ts +11 -2
- package/dist/server/render-results.js +54 -12
- package/dist/server/render-settings.js +3 -3
- package/dist/server/render-tasks.js +7 -4
- package/dist/server/route-table.js +14 -1
- package/dist/server/runtime.d.ts +16 -1
- package/dist/server/settings.js +82 -29
- package/dist/server/task-views.js +0 -1
- package/dist/server/tasks.js +11 -2
- package/dist/storage-ui.d.ts +2 -0
- package/dist/storage-ui.js +1 -1
- package/dist/storage.js +2 -1
- package/dist/store.d.ts +3 -0
- package/dist/store.js +33 -9
- package/dist/subagent-work.js +3 -0
- package/dist/task-status.d.ts +28 -1
- package/dist/task-status.js +93 -11
- package/dist/teardown-git.d.ts +27 -1
- package/dist/teardown-git.js +185 -39
- package/dist/telegram-progress.js +4 -4
- package/dist/telegram-status.js +8 -3
- package/dist/tool-secret-store.js +8 -0
- package/dist/toolroll-update-ui.d.ts +2 -0
- package/dist/toolroll-update-ui.js +4 -3
- package/dist/toolroll-update.js +10 -9
- package/dist/work-index.js +29 -12
- package/dist/workspace-ui.d.ts +5 -0
- package/dist/workspace-ui.js +38 -10
- package/package.json +1 -1
package/dist/serve.js
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { secretFolder } from "./tool-secret-store.js";
|
|
2
|
+
import { acceptedIdentities, recoverLearning } from "./project-learning.js";
|
|
3
|
+
import { loadOrCreateVapidKeys } from "./push.js";
|
|
4
|
+
import { checkoutPlan } from "./checkout-cleanup.js";
|
|
5
|
+
import { latestReleaseFor } from "./server/render-settings.js";
|
|
6
|
+
import { LastChecks } from "./server/last-checks.js";
|
|
7
|
+
import { readProviderKey } from "./keys.js";
|
|
8
|
+
import { closeExpiredUnattendedGrants } from "./flow-unattended.js";
|
|
9
|
+
import { isKeyedProvider } from "./acp-agents.js";
|
|
10
|
+
import { PROVIDER_IDS } from "./provider.js";
|
|
1
11
|
import { taskMovedSince } from "./chat-ask.js";
|
|
2
12
|
import { linuxFenceAvailable, macosFenceAvailable } from "./agent-fence.js";
|
|
3
13
|
import { signInsUnavailableWords } from "./check-access.js";
|
|
@@ -12,6 +22,10 @@ const RAIL_TASKS = 6;
|
|
|
12
22
|
const PROXY_HEADER = /^(forwarded|via|x-forwarded-.+|x-real-ip|x-client-ip|x-original-.+|x-cluster-client-ip|true-client-ip|cf-connecting-ip|fastly-client-ip|x-proxyuser-ip)$/i;
|
|
13
23
|
/** Asks a project names for the chime (its count is complete beyond them). */
|
|
14
24
|
const ASKS_PER_PROJECT = 100;
|
|
25
|
+
/** How often the background checks look at what is due (docs/plans/get-side-effects.md), and how often this
|
|
26
|
+
* computer's agent sign-ins are asked again. */
|
|
27
|
+
const BACKGROUND_CHECKS_MS = 30_000;
|
|
28
|
+
const LOCAL_AGENTS_EVERY_MS = 2 * 60_000;
|
|
15
29
|
import { boundProjectSummary, browserCrewFromIndex, browserCrewOf, browserNavigationOf, browserProjectsOf, needsYouLabelOf } from './browser-workspace.js';
|
|
16
30
|
import { sharedActionPayload } from './chat-actions.js';
|
|
17
31
|
import { prepareCodingContext } from './coding-context.js';
|
|
@@ -24,6 +38,7 @@ import { configureLeadFollow, recordLeadFollowFailure, runLeadFollowPass } from
|
|
|
24
38
|
import { leadNameOf } from "./lead-identity.js";
|
|
25
39
|
import { createLiveBus, followWorkspace } from "./live-bus.js";
|
|
26
40
|
import { startMaintenance } from './maintenance.js';
|
|
41
|
+
import { asReadOnlyRequest } from './read-only-request.js';
|
|
27
42
|
import { connectionsOf, localConnectOf, oneClickOf } from "./mcp-connect.js";
|
|
28
43
|
import { MOBILE_VIEWPORT_SCRIPT } from "./mobile-viewport.js";
|
|
29
44
|
import { projectAuthority } from "./project-access.js";
|
|
@@ -99,7 +114,7 @@ import { hasForbiddenControls } from "./decision.js";
|
|
|
99
114
|
import { UPDATE_PAUSED, updateAdmissionPaused } from "./desktop-update-gate.js";
|
|
100
115
|
import { scanForSecrets } from "./evidence.js";
|
|
101
116
|
import { run as execRun } from "./exec.js";
|
|
102
|
-
import { firstRunSteps, signInCommandFor } from "./first-run.js";
|
|
117
|
+
import { findFirstTasks, firstRunSteps, signInCommandFor } from "./first-run.js";
|
|
103
118
|
import { installMethod } from "./install-method.js";
|
|
104
119
|
import { createIntegrationMonitor } from "./integrations.js";
|
|
105
120
|
import { logEvent } from "./log.js";
|
|
@@ -245,8 +260,26 @@ export function createDecisionServer(options) {
|
|
|
245
260
|
const providerHome = options.connectionHome ?? homedir();
|
|
246
261
|
const checkConnection = createConnectionChecker({ home: providerHome, clock, ...(options.connectionProbe === undefined ? {} : { probe: options.connectionProbe }) });
|
|
247
262
|
// Every sign-in check the console makes also answers a sign-in pause.
|
|
263
|
+
// Whether this computer can fence agents: asked once as the console starts (a sandbox running /usr/bin/true), so
|
|
264
|
+
// Settings → Project never starts a process (docs/plans/get-side-effects.md).
|
|
265
|
+
const fenceHere = options.fenceAvailable === undefined ? macosFenceAvailable() || linuxFenceAvailable() : false;
|
|
266
|
+
// Phone notifications' signing pair, made once as the console starts so /push/key only reads it.
|
|
267
|
+
if (options.telegramTokenFile !== undefined) {
|
|
268
|
+
try {
|
|
269
|
+
loadOrCreateVapidKeys(dirname(options.telegramTokenFile));
|
|
270
|
+
}
|
|
271
|
+
catch { /* /push/key says push is not set up */ }
|
|
272
|
+
}
|
|
273
|
+
// The last answer of every other check a page shows (docs/plans/get-side-effects.md).
|
|
274
|
+
const lastChecks = new LastChecks();
|
|
275
|
+
/** The newest release, asked of npm (Settings → Updates shows the last answer). */
|
|
276
|
+
const checkRelease = () => lastChecks.run("release", () => latestReleaseFor(options.updates?.latest));
|
|
277
|
+
// What each sign-in check said last: what a page shows (docs/plans/get-side-effects.md). A page never checks.
|
|
278
|
+
const knownConnections = new Map();
|
|
279
|
+
const connectionKnown = (provider) => knownConnections.get(provider) ?? null;
|
|
248
280
|
const connectionCheck = async (provider, fresh) => {
|
|
249
281
|
const value = await checkConnection(provider, fresh);
|
|
282
|
+
knownConnections.set(provider, value);
|
|
250
283
|
try {
|
|
251
284
|
noteSignInProbe(store, provider, value.state, clock());
|
|
252
285
|
}
|
|
@@ -382,6 +415,17 @@ export function createDecisionServer(options) {
|
|
|
382
415
|
ssoProvider = { issuer, provider: found.provider, at: Date.now() };
|
|
383
416
|
return found;
|
|
384
417
|
}
|
|
418
|
+
/** The identity provider as last discovered: what starting a sign-in uses (a GET, so it fetches nothing,
|
|
419
|
+
* docs/plans/get-side-effects.md). Discovered as the console starts, by the background checks every ten minutes, and
|
|
420
|
+
* when sign-in settings are saved or tested. */
|
|
421
|
+
function providerKnown(issuer) {
|
|
422
|
+
return ssoProvider !== null && ssoProvider.issuer === issuer ? ssoProvider.provider : null;
|
|
423
|
+
}
|
|
424
|
+
{
|
|
425
|
+
const settings = ssoSettings();
|
|
426
|
+
if (settings !== null)
|
|
427
|
+
void providerFor(settings.issuer).catch(() => undefined);
|
|
428
|
+
}
|
|
385
429
|
/** Password sign-in is only for instance operators when the provider says so (a way in if it's down). */
|
|
386
430
|
const passwordAllowed = (name) => { const settings = ssoSettings(); return settings === null || settings.passwords === "everyone" || store.isInstanceOperator(name); };
|
|
387
431
|
const minutesWords = (ms) => { const minutes = Math.max(1, Math.ceil(ms / 60_000)); return minutes >= 120 ? `${Math.round(minutes / 60)} hours` : `${minutes} minute${minutes === 1 ? "" : "s"}`; };
|
|
@@ -456,7 +500,7 @@ export function createDecisionServer(options) {
|
|
|
456
500
|
setting: store.projectCheckAccess(repo), changed: store.projectCheckAccessChange(repo),
|
|
457
501
|
canNarrow: who.via === "cookie" && who.role === "approver" && !store.isDemo() && store.accountCanAccess(who.name, repo),
|
|
458
502
|
canWiden: who.via === "cookie" && !store.isDemo() && store.isInstanceOperator(who.name),
|
|
459
|
-
unconfinedHere: !(options.fenceAvailable?.() ??
|
|
503
|
+
unconfinedHere: !(options.fenceAvailable?.() ?? fenceHere) && store.unfencedAgentsAllowed(),
|
|
460
504
|
signInsUnavailable: signInsUnavailableWords(options.platform ?? process.platform),
|
|
461
505
|
},
|
|
462
506
|
liveView: (() => {
|
|
@@ -613,7 +657,9 @@ export function createDecisionServer(options) {
|
|
|
613
657
|
const server = createServer((request, response) => {
|
|
614
658
|
instrumentRequest(store.telemetry, request, response);
|
|
615
659
|
// Every password checked while answering counts against where this request came from (sign-in-guard.ts).
|
|
616
|
-
|
|
660
|
+
// A GET or HEAD only reads (docs/plans/get-side-effects.md): store reads that would tidy up as they go don't.
|
|
661
|
+
const answer = () => handle(request, response);
|
|
662
|
+
void withPasswordSource(joinSourceOf(request), () => request.method === "GET" || request.method === "HEAD" ? asReadOnlyRequest(answer) : answer()).catch(error => {
|
|
617
663
|
// Every unhandled error is logged (v99): the path and the message, never the request's body or query.
|
|
618
664
|
logEvent("error", "serve.error", { method: request.method, path: redactedPath(new URL(request.url ?? "/", "http://placeholder").pathname), error: error instanceof Error ? error.message : String(error) });
|
|
619
665
|
if (envValue(process.env, "SERVE_DEBUG") === "1")
|
|
@@ -1073,9 +1119,9 @@ export function createDecisionServer(options) {
|
|
|
1073
1119
|
.finally(() => { localSignInChecking = null; });
|
|
1074
1120
|
return localSignInChecking;
|
|
1075
1121
|
}
|
|
1122
|
+
/** The last answer only (docs/plans/get-side-effects.md): this computer is asked again by the background checks or a
|
|
1123
|
+
* person's Check now, never because a page was opened. */
|
|
1076
1124
|
function localAgentSignedIn() {
|
|
1077
|
-
if (localSignInChecking === null && (localSignIn === null || Date.now() - localSignIn.at > 30_000))
|
|
1078
|
-
void checkLocalAgents();
|
|
1079
1125
|
return localSignIn?.signedIn ?? null;
|
|
1080
1126
|
}
|
|
1081
1127
|
/**
|
|
@@ -1305,6 +1351,11 @@ export function createDecisionServer(options) {
|
|
|
1305
1351
|
* whole catalog, not a hand-pinned shortlist). null = no key or the
|
|
1306
1352
|
* catalog is unreachable; callers fall back to the compiled table. */
|
|
1307
1353
|
let catalogCache = null;
|
|
1354
|
+
/** The catalog as last fetched, for a page to show (docs/plans/get-side-effects.md): a page never fetches it. The
|
|
1355
|
+
* background checks keep it current while an OpenRouter key is saved; saving a choice fetches it (chatCatalog). */
|
|
1356
|
+
function chatCatalogKnown() {
|
|
1357
|
+
return chatKeyFor("openrouter-api") === null ? null : catalogCache?.models ?? null;
|
|
1358
|
+
}
|
|
1308
1359
|
async function chatCatalog() {
|
|
1309
1360
|
const key = chatKeyFor("openrouter-api")?.key;
|
|
1310
1361
|
if (key === undefined)
|
|
@@ -1820,6 +1871,106 @@ export function createDecisionServer(options) {
|
|
|
1820
1871
|
onError: error => recordLeadFollowFailure(store, error, clock()),
|
|
1821
1872
|
});
|
|
1822
1873
|
});
|
|
1874
|
+
// Background checks (docs/plans/get-side-effects.md): what pages show about this computer's agent sign-ins and the
|
|
1875
|
+
// services Toolroll uses is asked here, on a timer, and a page reads the last answer. A page visit never starts a
|
|
1876
|
+
// process or a network call, and never acts on what a check finds: lifting a sign-in pause and the lead-by-default
|
|
1877
|
+
// rule run from this pass (or a person's Check now), not from a GET.
|
|
1878
|
+
let backgroundChecks = null;
|
|
1879
|
+
let agentsCheckedAt = 0;
|
|
1880
|
+
if (options.backgroundChecks === true)
|
|
1881
|
+
server.once('listening', () => {
|
|
1882
|
+
// This Toolroll's folder for secrets, checked once now, so a page can read which are set without preparing it.
|
|
1883
|
+
try {
|
|
1884
|
+
secretFolder();
|
|
1885
|
+
}
|
|
1886
|
+
catch { /* a page says secrets can't be read; the next action reports why */ }
|
|
1887
|
+
backgroundChecks = startMaintenance({ intervalMs: options.backgroundChecksMs ?? BACKGROUND_CHECKS_MS, shouldStop: () => leadClosing,
|
|
1888
|
+
run: async () => {
|
|
1889
|
+
const now = Date.now();
|
|
1890
|
+
const waits = [];
|
|
1891
|
+
if (now - agentsCheckedAt >= (options.backgroundChecksMs ?? LOCAL_AGENTS_EVERY_MS)) {
|
|
1892
|
+
agentsCheckedAt = now;
|
|
1893
|
+
waits.push(checkLocalAgents());
|
|
1894
|
+
// The other agents Settings lists: their last answer is what the page shows.
|
|
1895
|
+
for (const provider of PROVIDER_IDS.filter(isKeyedProvider).filter(one => one !== "claude" && one !== "codex"))
|
|
1896
|
+
waits.push(connectionCheck(provider).catch(() => undefined));
|
|
1897
|
+
}
|
|
1898
|
+
integrations.refreshIfDue();
|
|
1899
|
+
const sso = ssoSettings();
|
|
1900
|
+
if (sso !== null && (ssoProvider === null || ssoProvider.issuer !== sso.issuer || Date.now() - ssoProvider.at >= 10 * 60_000))
|
|
1901
|
+
waits.push(providerFor(sso.issuer));
|
|
1902
|
+
if (chatKeyFor("openrouter-api") !== null)
|
|
1903
|
+
waits.push(chatCatalog());
|
|
1904
|
+
const openrouter = readProviderKey("openrouter", providerHome);
|
|
1905
|
+
// The cache answers until its list is due again (ten minutes, or 30 s after a failure), then fetches.
|
|
1906
|
+
if (openrouter !== null)
|
|
1907
|
+
waits.push(modelCatalog(openrouter));
|
|
1908
|
+
// What used to be closed by whichever page read it first: an operating mode or a flow's "runs on its own"
|
|
1909
|
+
// grant past its expiry, a stalled update, old coordinator proposals. (Lead turns past their deadline are the
|
|
1910
|
+
// follow pass's, which settles them even while an update drains.)
|
|
1911
|
+
const at = clock();
|
|
1912
|
+
store.closeExpiredModes(at);
|
|
1913
|
+
closeExpiredUnattendedGrants(store, at);
|
|
1914
|
+
store.sweepCoordinatorProposals(at);
|
|
1915
|
+
// The demo's scripted story, if a beat timer missed (its pages only read it).
|
|
1916
|
+
try {
|
|
1917
|
+
options.demoLead?.advance(at);
|
|
1918
|
+
}
|
|
1919
|
+
catch { /* the next pass tries again */ }
|
|
1920
|
+
const databaseFile = store.databaseFile();
|
|
1921
|
+
if (databaseFile !== null && !updateChecksOff(process.env, options.configDir ?? dirname(databaseFile)).off) {
|
|
1922
|
+
const last = lastChecks.known("release");
|
|
1923
|
+
if (lastChecks.due("release", last !== null && "problem" in last.value ? 60_000 : 15 * 60_000))
|
|
1924
|
+
waits.push(checkRelease());
|
|
1925
|
+
}
|
|
1926
|
+
// Chat's first tasks (issues and TODOs) while the first run is open and nothing is filed yet.
|
|
1927
|
+
if (firstRunStepsNow(clock()) !== null && !store.hasAnyWork()) {
|
|
1928
|
+
for (const repo of managedRepos()) {
|
|
1929
|
+
const entry = firstTasks.get(repo);
|
|
1930
|
+
if (entry !== undefined && (entry.reading || entry.until > Date.now()))
|
|
1931
|
+
continue;
|
|
1932
|
+
const reading = { until: Date.now() + 10 * 60_000, found: entry?.found ?? null, reading: true };
|
|
1933
|
+
firstTasks.set(repo, reading);
|
|
1934
|
+
waits.push(findFirstTasks(repo, options.firstTaskRunner ?? execRun).then(found => { reading.found = found; }, () => { }).finally(() => { reading.reading = false; }));
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
// Learning recovered from reviewed runs (and a project's saved rows carried to its current identity), which
|
|
1938
|
+
// Settings → Learning and Knowledge used to do as they opened.
|
|
1939
|
+
if (lastChecks.due("learning", 10 * 60_000)) {
|
|
1940
|
+
waits.push(lastChecks.run("learning", async () => {
|
|
1941
|
+
for (const repo of managedRepos()) {
|
|
1942
|
+
try {
|
|
1943
|
+
acceptedIdentities(store, repo);
|
|
1944
|
+
}
|
|
1945
|
+
catch { /* the next pass tries again */ }
|
|
1946
|
+
try {
|
|
1947
|
+
recoverLearning(store, evidenceRoot, repo);
|
|
1948
|
+
}
|
|
1949
|
+
catch { /* the next pass tries again */ }
|
|
1950
|
+
}
|
|
1951
|
+
}));
|
|
1952
|
+
}
|
|
1953
|
+
// What Codex has configured, per project, for Settings → Tools to offer.
|
|
1954
|
+
for (const repo of managedRepos()) {
|
|
1955
|
+
if (lastChecks.due(`codex-tools:${repo}`, 10 * 60_000))
|
|
1956
|
+
waits.push(lastChecks.run(`codex-tools:${repo}`, () => codexServers(repo)));
|
|
1957
|
+
}
|
|
1958
|
+
if (databaseFile !== null && lastChecks.due("storage", 30 * 60_000)) {
|
|
1959
|
+
waits.push(lastChecks.run("storage", () => checkoutPlan(store, storagePool(databaseFile), clock(), { manual: true })));
|
|
1960
|
+
}
|
|
1961
|
+
// The same reading the chrome does, outside a page visit, so it releases a stalled `toolroll update` and a stalled
|
|
1962
|
+
// desktop update in every folder the chrome looks in.
|
|
1963
|
+
if (databaseFile !== null) {
|
|
1964
|
+
try {
|
|
1965
|
+
waitingUpdate(databaseFile, run => store.stopQuiescenceProblem(run) !== null, at);
|
|
1966
|
+
}
|
|
1967
|
+
catch { /* shown as last saved */ }
|
|
1968
|
+
}
|
|
1969
|
+
await Promise.all(waits);
|
|
1970
|
+
},
|
|
1971
|
+
onError: () => { }, });
|
|
1972
|
+
void backgroundChecks.runNow();
|
|
1973
|
+
});
|
|
1823
1974
|
// Keep native process custody until shutdown has verified agent/tool exit.
|
|
1824
1975
|
// Coding custody does not depend on subagents or the lead's follow pass, so
|
|
1825
1976
|
// it closes at once and never waits behind a model turn: a stop must release
|
|
@@ -1848,7 +1999,7 @@ export function createDecisionServer(options) {
|
|
|
1848
1999
|
liveHandlers.close();
|
|
1849
2000
|
detachReads();
|
|
1850
2001
|
liveFollower.close();
|
|
1851
|
-
void Promise.all([closeCoding(), terminalClosing.close?.().then(problem => { terminalClosing.problem = problem; }), bounded(team.close()), bounded(personalQueue.close()), bounded(leadMaintenance?.stop()), bounded(reads?.close())])
|
|
2002
|
+
void Promise.all([closeCoding(), terminalClosing.close?.().then(problem => { terminalClosing.problem = problem; }), bounded(team.close()), bounded(personalQueue.close()), bounded(leadMaintenance?.stop()), bounded(backgroundChecks?.stop()), bounded(reads?.close())])
|
|
1852
2003
|
// The server always closes; a terminal whose processes couldn't be proved stopped is the close's error.
|
|
1853
2004
|
.then(() => closeServer(error => callback?.(error ?? terminalClosing.problem ?? undefined))).catch(error => {
|
|
1854
2005
|
if (callback)
|
|
@@ -1924,6 +2075,7 @@ export function createDecisionServer(options) {
|
|
|
1924
2075
|
get liveRefreshSeconds() { return liveRefreshSeconds; },
|
|
1925
2076
|
get chatKeyFor() { return chatKeyFor; },
|
|
1926
2077
|
get chatCatalog() { return chatCatalog; },
|
|
2078
|
+
get chatCatalogKnown() { return chatCatalogKnown; },
|
|
1927
2079
|
get leadRecheckedAt() { return leadRecheckedAt; },
|
|
1928
2080
|
set leadRecheckedAt(value) { leadRecheckedAt = value; },
|
|
1929
2081
|
get checkLocalAgents() { return checkLocalAgents; },
|
|
@@ -1931,6 +2083,9 @@ export function createDecisionServer(options) {
|
|
|
1931
2083
|
set localSignIn(value) { localSignIn = value; },
|
|
1932
2084
|
get agentSignInCommand() { return agentSignInCommand; },
|
|
1933
2085
|
get connectionCheck() { return connectionCheck; },
|
|
2086
|
+
get connectionKnown() { return connectionKnown; },
|
|
2087
|
+
get lastChecks() { return lastChecks; },
|
|
2088
|
+
get checkRelease() { return checkRelease; },
|
|
1934
2089
|
get modelCatalog() { return modelCatalog; },
|
|
1935
2090
|
get modelSeams() { return modelSeams; },
|
|
1936
2091
|
get toolsViewOf() { return toolsViewOf; },
|
|
@@ -1960,6 +2115,7 @@ export function createDecisionServer(options) {
|
|
|
1960
2115
|
get ssoProvider() { return ssoProvider; },
|
|
1961
2116
|
set ssoProvider(value) { ssoProvider = value; },
|
|
1962
2117
|
get providerFor() { return providerFor; },
|
|
2118
|
+
get providerKnown() { return providerKnown; },
|
|
1963
2119
|
get connectVisits() { return connectVisits; },
|
|
1964
2120
|
get defaultProject() { return defaultProject; },
|
|
1965
2121
|
get googleVisits() { return googleVisits; },
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work a lead filed, nested under it on the Live grid (docs/plans/lead-dispatched-tiles.md): which of the viewer's
|
|
3
|
+
* tiles were filed through the viewer's OWN lead chat, and which chat. Proved from the store only, at request time: the
|
|
4
|
+
* task's family root was filed through the lead (`filed_via = 'mate'`) by the viewer as a person, and exactly one record
|
|
5
|
+
* links that root to one of the viewer's own personal lead threads — a confirmed task card the viewer confirmed (its
|
|
6
|
+
* door-written outcome, never the model's payload) or a sweep the viewer started from a card still kept. Attribution is
|
|
7
|
+
* to the chat that filed the family's ORIGINAL task: a revision asked for in another chat stays with the family. Anything
|
|
8
|
+
* short of that is no link:
|
|
9
|
+
* the tile stays a top-level tile, as it is today. A link only groups tiles the viewer already gets; it never adds one.
|
|
10
|
+
*/
|
|
11
|
+
import type { Store } from "../store.js";
|
|
12
|
+
export type FiledBy = {
|
|
13
|
+
thread: number;
|
|
14
|
+
chat: "lead" | "project" | "task";
|
|
15
|
+
};
|
|
16
|
+
/** For each run id given (the tiles already in this viewer's answer), the viewer's lead chat that filed its task. */
|
|
17
|
+
export declare function leadFiledLinks(store: Store, viewer: string, runIds: readonly number[]): Map<number, FiledBy>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const BUILT_IN = "built-in";
|
|
2
|
+
/** The family root of a built-in task, or null when its lineage can't be proved: the family's own proof (taskFamilyOf:
|
|
3
|
+
* every revision in the root's project, each bound by its brief to its parent's own run), and the task one of it. */
|
|
4
|
+
function rootOf(store, taskId) {
|
|
5
|
+
const family = store.taskFamilyOf(taskId, null, false);
|
|
6
|
+
return family === null || family.problem !== null || !family.versions.some(version => version.id === taskId) ? null : family.root.id;
|
|
7
|
+
}
|
|
8
|
+
const parse = (text) => {
|
|
9
|
+
if (typeof text !== "string")
|
|
10
|
+
return null;
|
|
11
|
+
try {
|
|
12
|
+
const value = JSON.parse(text);
|
|
13
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/** For each run id given (the tiles already in this viewer's answer), the viewer's lead chat that filed its task. */
|
|
20
|
+
export function leadFiledLinks(store, viewer, runIds) {
|
|
21
|
+
const links = new Map();
|
|
22
|
+
const db = store.handle;
|
|
23
|
+
// The viewer's own personal threads (never a team conversation's), by id.
|
|
24
|
+
const threads = new Map();
|
|
25
|
+
for (const row of db.prepare(`SELECT id, scope_kind FROM lead_thread WHERE approver = ? AND NOT EXISTS (SELECT 1 FROM team_conversation tc WHERE tc.thread = lead_thread.id)`).all(viewer)) {
|
|
26
|
+
const kind = row["scope_kind"];
|
|
27
|
+
threads.set(Number(row["id"]), kind === "project" ? "project" : kind === "task" ? "task" : "lead");
|
|
28
|
+
}
|
|
29
|
+
if (threads.size === 0)
|
|
30
|
+
return links;
|
|
31
|
+
// Each run's family root, proved once per task (attempts of one task share it), and only roots the viewer filed
|
|
32
|
+
// through the lead as a person go further.
|
|
33
|
+
const rootOfTask = new Map();
|
|
34
|
+
const runRoots = new Map();
|
|
35
|
+
const repos = new Map();
|
|
36
|
+
const refRow = db.prepare("SELECT repo, filed_via, filed_by, filed_by_kind FROM task_ref WHERE backend = ? AND external_id = ?");
|
|
37
|
+
for (const runId of runIds) {
|
|
38
|
+
const row = db.prepare("SELECT r.backend, r.external_id FROM run JOIN task_ref r ON r.id = run.task_ref WHERE run.id = ?").get(runId);
|
|
39
|
+
if (row === undefined || row["backend"] !== BUILT_IN)
|
|
40
|
+
continue;
|
|
41
|
+
const task = String(row["external_id"]);
|
|
42
|
+
if (!rootOfTask.has(task))
|
|
43
|
+
rootOfTask.set(task, rootOf(store, task));
|
|
44
|
+
const root = rootOfTask.get(task);
|
|
45
|
+
if (root === null || root === undefined)
|
|
46
|
+
continue;
|
|
47
|
+
if (!repos.has(root)) {
|
|
48
|
+
const ref = refRow.get(BUILT_IN, root);
|
|
49
|
+
// Filed through the lead, by the viewer, as a person.
|
|
50
|
+
const filed = ref !== undefined && ref["filed_via"] === "mate" && ref["filed_by_kind"] === "person" && ref["filed_by"] === viewer && typeof ref["repo"] === "string";
|
|
51
|
+
repos.set(root, filed ? String(ref["repo"]) : "");
|
|
52
|
+
}
|
|
53
|
+
if (repos.get(root) !== "")
|
|
54
|
+
runRoots.set(runId, root);
|
|
55
|
+
}
|
|
56
|
+
const roots = [...new Set(runRoots.values())];
|
|
57
|
+
if (roots.length === 0)
|
|
58
|
+
return links;
|
|
59
|
+
// Every confirmed task card in the viewer's own threads naming one of these roots: ONE read per request, through the
|
|
60
|
+
// viewer's threads (lead_thread by approver, lead_proposal by thread and state), never once per family.
|
|
61
|
+
const found = new Map(roots.map(root => [root, []]));
|
|
62
|
+
const spoiled = new Set();
|
|
63
|
+
const cards = db.prepare(`SELECT p.thread, p.resolved_by, p.payload_json, p.outcome_json, json_extract(p.outcome_json, '$.taskId') AS task FROM lead_proposal p
|
|
64
|
+
JOIN lead_thread t ON t.id = p.thread WHERE t.approver = ? AND p.kind = 'task' AND p.state = 'confirmed' AND json_valid(p.outcome_json)
|
|
65
|
+
AND json_extract(p.outcome_json, '$.taskId') IN (${roots.map(() => "?").join(",")})`).all(viewer, ...roots);
|
|
66
|
+
for (const row of cards) {
|
|
67
|
+
const root = String(row["task"]);
|
|
68
|
+
const outcome = parse(row["outcome_json"]), payload = parse(row["payload_json"]);
|
|
69
|
+
// The door's own outcome (the model writes only the payload), confirmed by the viewer, for this project.
|
|
70
|
+
if (outcome?.["ok"] !== true || outcome["kind"] !== "task" || outcome["taskId"] !== root || row["resolved_by"] !== viewer || payload?.["repo"] !== repos.get(root))
|
|
71
|
+
spoiled.add(root);
|
|
72
|
+
else
|
|
73
|
+
found.get(root)?.push(Number(row["thread"]));
|
|
74
|
+
}
|
|
75
|
+
// A sweep links while the card that started it is kept, as a task card does: ending a chat (or revocation) erases its
|
|
76
|
+
// cards, and with them every link it made — one retention rule for both.
|
|
77
|
+
const sweeps = db.prepare(`SELECT k.root_task, s.owner, s.thread, s.repo, p.thread AS card_thread, p.state AS card_state, p.resolved_by AS card_by
|
|
78
|
+
FROM lead_sweep_task k JOIN lead_sweep s ON s.id = k.sweep LEFT JOIN lead_proposal p ON p.id = s.proposal
|
|
79
|
+
WHERE k.root_task IN (${roots.map(() => "?").join(",")})`).all(...roots);
|
|
80
|
+
for (const row of sweeps) {
|
|
81
|
+
const root = String(row["root_task"]);
|
|
82
|
+
if (row["owner"] !== viewer || row["repo"] !== repos.get(root) || row["thread"] === null || row["card_thread"] !== row["thread"] || row["card_state"] !== "confirmed" || row["card_by"] !== viewer)
|
|
83
|
+
spoiled.add(root);
|
|
84
|
+
else
|
|
85
|
+
found.get(root)?.push(Number(row["thread"]));
|
|
86
|
+
}
|
|
87
|
+
for (const [runId, root] of runRoots) {
|
|
88
|
+
// Exactly one record, nothing amiss beside it, naming one of the viewer's own personal threads.
|
|
89
|
+
const named = found.get(root) ?? [];
|
|
90
|
+
if (spoiled.has(root) || named.length !== 1)
|
|
91
|
+
continue;
|
|
92
|
+
const chat = threads.get(named[0]);
|
|
93
|
+
if (chat !== undefined)
|
|
94
|
+
links.set(runId, { thread: named[0], chat });
|
|
95
|
+
}
|
|
96
|
+
return links;
|
|
97
|
+
}
|
|
@@ -11,6 +11,7 @@ import { closeSync } from "node:fs";
|
|
|
11
11
|
import { agentsLiveOf } from "../agents-live.js";
|
|
12
12
|
import { createLiveRooms } from "../live-bus.js";
|
|
13
13
|
import { openLiveTrusted } from "../live-open.js";
|
|
14
|
+
import { leadFiledLinks } from "./agents-live-filed.js";
|
|
14
15
|
import { requestContext } from "./request-context.js";
|
|
15
16
|
/** How often a viewer's runs and files are looked at again. */
|
|
16
17
|
export const LIVE_POLL_MS = 2_000;
|
|
@@ -79,7 +80,9 @@ export function createAgentsLiveRooms(input) {
|
|
|
79
80
|
return repo !== null && visible(repo) && store.accountCanAccess(account, repo);
|
|
80
81
|
};
|
|
81
82
|
const kept = new Set(tiles.filter(tile => still(tile.runId)).map(tile => tile.runId));
|
|
82
|
-
|
|
83
|
+
// Which of the viewer's own lead chats filed each run (agents-live-filed.ts): a link made or erased is a change too.
|
|
84
|
+
const filed = leadFiledLinks(store, account, [...kept]);
|
|
85
|
+
const seen = tiles.filter(tile => kept.has(tile.runId)).map(tile => [tile.runId, tile.state, tile.why, tile.endedAt, filed.get(tile.runId)?.thread ?? null]);
|
|
83
86
|
const shownMarks = marks.filter(([runId]) => kept.has(runId) && (!tiles.find(tile => tile.runId === runId)?.local || sees(runId)()));
|
|
84
87
|
return createHash("sha256").update(JSON.stringify([seen, shownMarks, input.leads?.(key) ?? null])).digest("base64url");
|
|
85
88
|
});
|
package/dist/server/chat.js
CHANGED
|
@@ -28,7 +28,7 @@ import { projectName } from "../project.js";
|
|
|
28
28
|
import { fileTaskProposal } from "../proposal.js";
|
|
29
29
|
import { providerName } from "../provider-auth.js";
|
|
30
30
|
import { validModelId } from "../provider.js";
|
|
31
|
-
import { loadOrCreateVapidKeys, validatePushEndpoint } from "../push.js";
|
|
31
|
+
import { loadOrCreateVapidKeys, loadVapidKeys, validatePushEndpoint } from "../push.js";
|
|
32
32
|
import { parseResultTab, RESULT_REVIEW_SCRIPT } from "../result-review.js";
|
|
33
33
|
import {} from "../store.js";
|
|
34
34
|
import { runActivityOf } from "../task-activity.js";
|
|
@@ -44,7 +44,7 @@ import {} from "./render-pages.js";
|
|
|
44
44
|
import { completionForm, hardBlockerOf, homePhaseWords, owedAcceptanceOf, resultPanelHtml } from "./render-results.js";
|
|
45
45
|
import { browserCaller, oneLineUa } from "./session.js";
|
|
46
46
|
export function createChatHandlers(runtime) {
|
|
47
|
-
const { firstRunStepsNow, managedRepos, leadWords, store, options, phoneSetup, visible, liveTurns, leadSaid, evidenceRoot, clock, sessions, CHAT_CANDIDATE_TTL_MS, chatFetcher, CHAT_CANDIDATES_PER_APPROVER, chatCeilingDigest, workAccess, familyOf, firstTasks, leadPrincipal, taskChatFocus, chatScopeOf, leadConversationRows, demoLeadHere, sendScreen, chromeFor, teamBrowserReply, team, teamChatProvider, runVisible, runIsLive, resultDetailOf, pullRequestTargetOf, chatEnablement, startLeadConversation, projectFamilyPeek, needsYouBadge, liveRefreshSeconds, chatKeyFor, chatCatalog, providerHome, mintApprovalNonce, checkLocalAgents, agentSignInCommand, bustBadge, authenticateApprover, revisionDestination, armTaskResume, consumeApprovalNonce } = runtime;
|
|
47
|
+
const { firstRunStepsNow, managedRepos, leadWords, store, options, phoneSetup, visible, liveTurns, leadSaid, evidenceRoot, clock, sessions, CHAT_CANDIDATE_TTL_MS, chatFetcher, CHAT_CANDIDATES_PER_APPROVER, chatCeilingDigest, workAccess, familyOf, firstTasks, leadPrincipal, taskChatFocus, chatScopeOf, leadConversationRows, demoLeadHere, sendScreen, chromeFor, teamBrowserReply, team, teamChatProvider, runVisible, runIsLive, resultDetailOf, pullRequestTargetOf, chatEnablement, startLeadConversation, projectFamilyPeek, needsYouBadge, liveRefreshSeconds, chatKeyFor, chatCatalog, chatCatalogKnown, providerHome, mintApprovalNonce, checkLocalAgents, agentSignInCommand, bustBadge, authenticateApprover, revisionDestination, armTaskResume, consumeApprovalNonce } = runtime;
|
|
48
48
|
// The read-only refresh (package 2): the same JSON status as before —
|
|
49
49
|
// session binding, the send receipt, the live turn — plus a version
|
|
50
50
|
// of the DISPLAYED facts and, only when the caller's version differs,
|
|
@@ -65,7 +65,6 @@ export function createChatHandlers(runtime) {
|
|
|
65
65
|
return respond(response, 200, "application/json", JSON.stringify({ session: null }));
|
|
66
66
|
}
|
|
67
67
|
const sessionId = session?.id ?? NOT_STARTED_SESSION;
|
|
68
|
-
store.sweepStaleLeadTurns(now);
|
|
69
68
|
const request = url.searchParams.get("request") ?? "";
|
|
70
69
|
// Received: the engine took it, or the lead queue holds it (a queued acknowledgement lost on the way still frees the draft).
|
|
71
70
|
const received = session !== null && /^[a-f0-9]{32}$/.test(request) && store.leadRequestReceived(session.id, request);
|
|
@@ -151,9 +150,8 @@ export function createChatHandlers(runtime) {
|
|
|
151
150
|
chrome: chromeFor(null, 'chat', undefined, 'all'), workspace: { team: reply.snapshot, notices: [DEPRECATED_PAGE.team, ...(said ? [said] : [])] },
|
|
152
151
|
}));
|
|
153
152
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
store.sweepCoordinatorProposals(now);
|
|
153
|
+
// Settling a turn past its deadline (its spend) and expiring old proposals are the background passes' work, never a
|
|
154
|
+
// page visit's (docs/plans/get-side-effects.md); the lead's follow pass sweeps every few seconds.
|
|
157
155
|
sweepChatDrafts(Date.now());
|
|
158
156
|
const requestedTask = url.searchParams.get("task");
|
|
159
157
|
const focusTask = taskChatFocus(requestedTask, now, who, { mintNonce: !requestContext.getStore()?.workspaceRead });
|
|
@@ -341,7 +339,7 @@ export function createChatHandlers(runtime) {
|
|
|
341
339
|
tail: found === null || found.source === "environment" ? null : redactToken(found.key),
|
|
342
340
|
};
|
|
343
341
|
}),
|
|
344
|
-
openrouterModels: (
|
|
342
|
+
openrouterModels: chatCatalogKnown()?.map(one => one.id) ?? null,
|
|
345
343
|
liveModels: [...modelOptions(store, "claude", now, providerHome), ...modelOptions(store, "codex", now, providerHome)],
|
|
346
344
|
csrf: who.session.csrf,
|
|
347
345
|
problem: url.searchParams.get("said") ??
|
|
@@ -425,22 +423,39 @@ export function createChatHandlers(runtime) {
|
|
|
425
423
|
const { who, response } = ctx;
|
|
426
424
|
if (who.via !== "cookie")
|
|
427
425
|
return respond(response, 403, "application/json", JSON.stringify({ error: "session" }));
|
|
428
|
-
|
|
426
|
+
// The pair is made as the console starts (docs/plans/get-side-effects.md); this only reads it.
|
|
427
|
+
const keys = options.telegramTokenFile === undefined ? null : loadVapidKeys(dirname(options.telegramTokenFile));
|
|
429
428
|
response.setHeader("cache-control", "no-store");
|
|
429
|
+
if (keys === null)
|
|
430
|
+
return respond(response, 503, "application/json", JSON.stringify({ error: "push is not set up on this console" }));
|
|
430
431
|
return respond(response, 200, "application/json", JSON.stringify({ key: keys.publicKey }));
|
|
431
432
|
}
|
|
432
|
-
//
|
|
433
|
-
//
|
|
433
|
+
// What this computer's agent CLIs said last, and whether the lead is on. A read: the answer comes from the background
|
|
434
|
+
// checks or a Check now (POST /lead/check), never from this request (docs/plans/get-side-effects.md).
|
|
435
|
+
const leadState = () => JSON.stringify({ lead: store.getChatConfig() === null ? "off" : "on", agent: runtime.localSignIn?.signedIn ?? null,
|
|
436
|
+
checkedAt: runtime.localSignIn === null ? null : new Date(runtime.localSignIn.at).toISOString(), command: agentSignInCommand() });
|
|
434
437
|
async function leadStatus(ctx) {
|
|
435
438
|
const { who, response } = ctx;
|
|
436
439
|
if (who.via !== "cookie")
|
|
437
440
|
return respond(response, 403, "application/json", JSON.stringify({ error: "sign in" }));
|
|
441
|
+
response.setHeader("cache-control", "no-store");
|
|
442
|
+
return respond(response, 200, "application/json", leadState());
|
|
443
|
+
}
|
|
444
|
+
// While no agent is signed in, Chat asks this computer again on its own (onboarding), and Settings → Lead has Check
|
|
445
|
+
// now: a fresh, non-spending sign-in check at most every few seconds, and the lead turns on as soon as one is found
|
|
446
|
+
// (the lead-by-default rule). A POST with the person's form token, so no prefetch or link preview can set it off.
|
|
447
|
+
async function leadCheck(ctx) {
|
|
448
|
+
const { response, posted } = ctx;
|
|
449
|
+
const body = readForm(posted, CONSOLE_FORMS.leadCheck);
|
|
438
450
|
if (Date.now() - runtime.leadRecheckedAt > 4_000) {
|
|
439
451
|
runtime.leadRecheckedAt = Date.now();
|
|
440
452
|
await Promise.race([checkLocalAgents(true), new Promise(done => setTimeout(done, 8_000).unref?.())]);
|
|
441
453
|
}
|
|
454
|
+
const back = body.get("return");
|
|
455
|
+
if (back !== null)
|
|
456
|
+
return redirect(response, safeReturn(back));
|
|
442
457
|
response.setHeader("cache-control", "no-store");
|
|
443
|
-
return respond(response, 200, "application/json",
|
|
458
|
+
return respond(response, 200, "application/json", leadState());
|
|
444
459
|
}
|
|
445
460
|
async function taskStatus(ctx) {
|
|
446
461
|
const { url, who, response, now } = ctx;
|
|
@@ -1157,7 +1172,7 @@ export function createChatHandlers(runtime) {
|
|
|
1157
1172
|
intro: HOW_IT_WORKS,
|
|
1158
1173
|
lead: lead === null ? null : { words: `The lead uses ${lead}`, href: "/settings/lead" },
|
|
1159
1174
|
// With no lead yet and no agent signed in, the page asks this computer again on its own.
|
|
1160
|
-
recheck: store.getChatConfig() === null && agent !== undefined && !agent.done ? "/lead/
|
|
1175
|
+
recheck: store.getChatConfig() === null && agent !== undefined && !agent.done ? "/lead/check" : null,
|
|
1161
1176
|
};
|
|
1162
1177
|
}
|
|
1163
1178
|
/** After the first Ready result, once (onboarding): the phone, by a chat app or the console over Tailscale. */
|
|
@@ -1469,18 +1484,10 @@ export function createChatHandlers(runtime) {
|
|
|
1469
1484
|
planUse: (windows?.tiles ?? []).map(one => ({ name: one.name, window: one.window, percent: one.percent, detail: one.detail, tone: one.tone })),
|
|
1470
1485
|
};
|
|
1471
1486
|
}
|
|
1487
|
+
/** The first tasks last found for a project (docs/plans/get-side-effects.md): the background checks ask gh and
|
|
1488
|
+
* git grep while the first run is open; a page shows what they found, or the generic three. */
|
|
1472
1489
|
function firstTasksFor(repo) {
|
|
1473
|
-
|
|
1474
|
-
let entry = firstTasks.get(repo);
|
|
1475
|
-
if (entry === undefined || (entry.until <= at && !entry.reading)) {
|
|
1476
|
-
const reading = { until: at + 10 * 60_000, found: entry?.found ?? null, reading: true };
|
|
1477
|
-
firstTasks.set(repo, reading);
|
|
1478
|
-
entry = reading;
|
|
1479
|
-
void findFirstTasks(repo, options.firstTaskRunner ?? execRun)
|
|
1480
|
-
.then(found => { reading.found = found; }, () => { })
|
|
1481
|
-
.finally(() => { reading.reading = false; });
|
|
1482
|
-
}
|
|
1483
|
-
return entry.found ?? firstTaskSuggestions({ issues: [], todos: [] });
|
|
1490
|
+
return firstTasks.get(repo)?.found ?? firstTaskSuggestions({ issues: [], todos: [] });
|
|
1484
1491
|
}
|
|
1485
1492
|
function approverCandidateCount(approver) {
|
|
1486
1493
|
let count = 0;
|
|
@@ -1518,6 +1525,7 @@ export function createChatHandlers(runtime) {
|
|
|
1518
1525
|
"chat.action": sharedActionReview,
|
|
1519
1526
|
"push.key": pushKey,
|
|
1520
1527
|
"lead.status": leadStatus,
|
|
1528
|
+
"lead.check": leadCheck,
|
|
1521
1529
|
"chat.task-status": taskStatus,
|
|
1522
1530
|
"chat.demo.ask": demoAsk,
|
|
1523
1531
|
"chat.demo.approve": demoAct("approve"),
|
package/dist/server/http.d.ts
CHANGED
|
@@ -165,6 +165,11 @@ export type ServeOptions = {
|
|
|
165
165
|
* the exact part of the ceiling, so an addition or removal shows without a restart. */
|
|
166
166
|
admittedRepos?: () => readonly string[];
|
|
167
167
|
connectionProbe?: typeof execRun;
|
|
168
|
+
/** The console's background checks (docs/plans/get-side-effects.md): sign-in checks, integration checks, model
|
|
169
|
+
* lists and the tidy-ups pages used to do. On for `up` and `serve`; a test turns them on, and `backgroundChecksMs` sets
|
|
170
|
+
* how often they run and ask this computer's agents again. */
|
|
171
|
+
backgroundChecks?: boolean;
|
|
172
|
+
backgroundChecksMs?: number;
|
|
168
173
|
connectionHome?: string;
|
|
169
174
|
/** Test seam for Chat's first tasks: the `gh` and `git grep` reads. */
|
|
170
175
|
firstTaskRunner?: typeof execRun;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The last answer of each check a page shows (docs/plans/get-side-effects.md). A page reads `known`; the background
|
|
3
|
+
* checks and a person's Check now (a POST) call `run`. One per console, held in memory: a restart asks again.
|
|
4
|
+
*/
|
|
5
|
+
export type LastCheck<T> = {
|
|
6
|
+
at: number;
|
|
7
|
+
value: T;
|
|
8
|
+
};
|
|
9
|
+
export declare class LastChecks {
|
|
10
|
+
private readonly answers;
|
|
11
|
+
private readonly running;
|
|
12
|
+
known<T>(key: string): LastCheck<T> | null;
|
|
13
|
+
/** Whether the last answer is older than `everyMs` (or missing). */
|
|
14
|
+
due(key: string, everyMs: number, now?: number): boolean;
|
|
15
|
+
/** Run the check (one at a time per key) and keep its answer. */
|
|
16
|
+
run<T>(key: string, check: () => Promise<T>): Promise<T>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export class LastChecks {
|
|
2
|
+
answers = new Map();
|
|
3
|
+
running = new Map();
|
|
4
|
+
known(key) {
|
|
5
|
+
return this.answers.get(key) ?? null;
|
|
6
|
+
}
|
|
7
|
+
/** Whether the last answer is older than `everyMs` (or missing). */
|
|
8
|
+
due(key, everyMs, now = Date.now()) {
|
|
9
|
+
const last = this.answers.get(key);
|
|
10
|
+
return last === undefined || now - last.at >= everyMs;
|
|
11
|
+
}
|
|
12
|
+
/** Run the check (one at a time per key) and keep its answer. */
|
|
13
|
+
run(key, check) {
|
|
14
|
+
const pending = this.running.get(key);
|
|
15
|
+
if (pending !== undefined)
|
|
16
|
+
return pending;
|
|
17
|
+
const started = check().then(value => { this.answers.set(key, { at: Date.now(), value }); return value; })
|
|
18
|
+
.finally(() => { this.running.delete(key); });
|
|
19
|
+
this.running.set(key, started);
|
|
20
|
+
return started;
|
|
21
|
+
}
|
|
22
|
+
}
|