toolroll 0.9.109 → 0.9.110
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 +35 -0
- package/dist/agent-detect.js +244 -0
- package/dist/agent-fence.js +12 -1
- package/dist/agentconfig.js +2 -2
- package/dist/approval-summary.js +344 -0
- package/dist/attest.js +2 -2
- package/dist/browser/workspace.css +2 -2
- package/dist/browser/workspace.js +27 -27
- package/dist/builder.js +36 -2
- package/dist/chat-actions.js +24 -17
- package/dist/chat-core.js +3 -1
- package/dist/chat-decide.js +101 -46
- package/dist/chat-delivery-state.js +2 -0
- package/dist/chat-delivery.js +3 -2
- package/dist/chat-live.js +2 -1
- package/dist/chat-task-actions.js +6 -0
- package/dist/check-report.js +1 -1
- package/dist/cli.js +2 -0
- package/dist/console-instance.js +10 -1
- package/dist/contracts/console-api.js +10 -5
- package/dist/contracts/engine-api.js +271 -0
- package/dist/coordinator.js +2 -2
- package/dist/discord-api.js +4 -3
- package/dist/discord-chat.js +3 -1
- package/dist/easy-start-args.js +7 -3
- package/dist/easy-start.js +25 -0
- package/dist/egress.js +72 -10
- package/dist/engine-handoff.js +34 -0
- package/dist/engine-reads.js +261 -0
- package/dist/eval-world.js +3 -2
- package/dist/evidence.js +2 -0
- package/dist/fast-start.js +55 -14
- package/dist/fast-terms.js +2 -2
- package/dist/first-run.js +10 -2
- package/dist/flexible-agents.js +234 -0
- package/dist/flexible-answers-schema.js +61 -0
- package/dist/flexible-answers.js +889 -0
- package/dist/flexible-custody.js +494 -0
- package/dist/flexible-import.js +782 -0
- package/dist/flexible-launch-schema.js +72 -0
- package/dist/flexible-launch.js +331 -0
- package/dist/flexible-launcher.js +88 -0
- package/dist/flexible-levels.js +34 -0
- package/dist/flexible-merge-guard.js +47 -0
- package/dist/flexible-refs.js +47 -0
- package/dist/flexible-relay-cancel.js +19 -0
- package/dist/flexible-relay-schema.js +55 -0
- package/dist/flexible-relay-upstreams.js +36 -0
- package/dist/flexible-relay.js +1032 -0
- package/dist/flexible-session.js +732 -0
- package/dist/flexible-ship-schema.js +81 -0
- package/dist/flexible-ship.js +694 -0
- package/dist/flexible-start.js +80 -0
- package/dist/flexible-thread.js +175 -25
- package/dist/flexible-turns-schema.js +69 -0
- package/dist/flexible-turns.js +490 -0
- package/dist/flexible.js +10 -1
- package/dist/flow-actions.js +6 -4
- package/dist/flow-steps.js +1 -1
- package/dist/flows-cli.js +2 -1
- package/dist/git-views.js +6 -3
- package/dist/install-mode.js +225 -0
- package/dist/lead-doors.js +7 -1
- package/dist/limits-ui.js +7 -0
- package/dist/live-reply.js +6 -0
- package/dist/live-terminal.js +425 -29
- package/dist/local-owner.js +6 -0
- package/dist/model-choices.js +12 -6
- package/dist/notification-delivery.js +11 -0
- package/dist/operate.js +74 -30
- package/dist/outbound-privacy.js +204 -0
- package/dist/passwordless.js +2 -1
- package/dist/project-delete.js +14 -0
- package/dist/provider-connection.js +5 -3
- package/dist/publish.js +5 -0
- package/dist/pull-request-flow.js +26 -7
- package/dist/push.js +5 -1
- package/dist/release-card.js +11 -3
- package/dist/release.js +10 -1
- package/dist/route-store.js +2 -2
- package/dist/sandbox-launch.js +32 -8
- package/dist/sandbox-runtime.js +16 -7
- package/dist/sandbox-tools.js +176 -0
- package/dist/scope.js +12 -36
- package/dist/scout-net.js +7 -2
- package/dist/serve.js +58 -11
- package/dist/server/chrome.js +3 -1
- package/dist/server/console.css +33 -6
- package/dist/server/engine-api.js +378 -0
- package/dist/server/flows.js +2 -2
- package/dist/server/http.js +7 -0
- package/dist/server/link-redemption.js +52 -0
- package/dist/server/mutation-key.js +21 -7
- package/dist/server/pages.js +69 -40
- package/dist/server/people-tokens.js +17 -41
- package/dist/server/render-chat.js +1 -0
- package/dist/server/render-new-task.js +3 -3
- package/dist/server/render-results.js +4 -4
- package/dist/server/render-tasks.js +129 -138
- package/dist/server/route-table.js +30 -1
- package/dist/server/settings-section-table.js +3 -0
- package/dist/server/settings-sections.js +33 -0
- package/dist/server/settings.js +84 -10
- package/dist/server/task-views.js +8 -2
- package/dist/server/tasks.js +25 -8
- package/dist/server/terminals.js +181 -28
- package/dist/server/welcome.js +35 -10
- package/dist/settings-groups-ui.js +2 -2
- package/dist/settings-proofs.js +13 -9
- package/dist/slack-api.js +4 -3
- package/dist/slack-chat.js +5 -3
- package/dist/spend.js +46 -12
- package/dist/status-probe.js +343 -0
- package/dist/store.js +102 -5
- package/dist/teams-api.js +4 -3
- package/dist/teams-chat.js +4 -2
- package/dist/telegram-lead.js +2 -1
- package/dist/telegram-live.js +2 -1
- package/dist/telegram-team.js +2 -1
- package/dist/telegram.js +17 -5
- package/dist/trusted-path.js +162 -0
- package/dist/tui/darwin-arm64/toolroll-tui +0 -0
- package/dist/tui/darwin-x64/toolroll-tui +0 -0
- package/dist/tui/linux-arm64/toolroll-tui +0 -0
- package/dist/tui/linux-x64/toolroll-tui +0 -0
- package/dist/tui-launch.js +282 -0
- package/dist/tui-source.js +5 -3
- package/dist/tui.js +1 -1
- package/dist/webhooks.js +8 -4
- package/dist/welcome-facts.js +22 -15
- package/dist/workspace-ui.js +5 -0
- package/package.json +1 -1
- package/scripts/crash-canary.mjs +1 -1
- package/scripts/pilot.mjs +1 -1
- package/scripts/provider-canary.mjs +5 -3
package/dist/model-choices.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { isAcpProvider } from "./acp-agents.js";
|
|
3
|
-
import { currentLocalOwner, localModeOn, localOwnerInFlight, localOwnerStandsNow } from "./local-owner.js";
|
|
3
|
+
import { currentLocalOwner, localActNow, localModeOn, localOwnerInFlight, localOwnerStandsNow } from "./local-owner.js";
|
|
4
4
|
import { INSTALLATION_SCOPE, resolvePhaseAgent, resolveRouteCandidates } from "./agentconfig.js";
|
|
5
5
|
import { seenModels } from "./model-catalog.js";
|
|
6
|
-
import {
|
|
6
|
+
import { sessionStandsIn, soloNow } from "./install-mode.js";
|
|
7
7
|
import { exactModelId, recommendRoute, routeProblems } from "./phase-routing.js";
|
|
8
8
|
import { liveEarnedRules } from "./route-store.js";
|
|
9
9
|
import { isProviderId, validateSpec } from "./provider.js";
|
|
@@ -252,7 +252,10 @@ function applyLocked(store, input, authority, now) {
|
|
|
252
252
|
{
|
|
253
253
|
{
|
|
254
254
|
const account = store.accountOf(authority.actor);
|
|
255
|
-
const
|
|
255
|
+
const local = authority.method === "local-owner" ? localActNow(store, "change-models") : null;
|
|
256
|
+
const standsNow = authority.method === "local-owner"
|
|
257
|
+
? local !== null && local.account === authority.actor && soloNow(store)
|
|
258
|
+
: PERSON_PROOFS.has(authority.method) && ((authority.method !== "session" && authority.method !== "cli-login") || sessionStandsIn(store));
|
|
256
259
|
if (account === null || account.revokedAt !== null || account.generation !== authority.generation || !store.isInstanceOperator(authority.actor) || !authority.live() || !standsNow) {
|
|
257
260
|
throw new Refused({ ok: false, reason: "authority", problem: "Only an instance operator, signed in now, can change models." });
|
|
258
261
|
}
|
|
@@ -369,6 +372,7 @@ export function agentPresetChange(agent) {
|
|
|
369
372
|
export function defaultAgentOf(provider) {
|
|
370
373
|
return provider === "claude-subscription" ? "claude" : provider === "codex-subscription" ? "codex" : null;
|
|
371
374
|
}
|
|
375
|
+
export const FIRST_TASK_AGENT_FACT = "first-task-agent";
|
|
372
376
|
export function fillDefaultRouting(store, agent, actor, door, now) {
|
|
373
377
|
const refused = (reason, problem) => ({ filled: false, reason, problem });
|
|
374
378
|
return store.transact(() => {
|
|
@@ -378,13 +382,13 @@ export function fillDefaultRouting(store, agent, actor, door, now) {
|
|
|
378
382
|
return refused("authority", "Only this computer's owner, choosing an agent now, starts its models.");
|
|
379
383
|
}
|
|
380
384
|
}
|
|
381
|
-
else if (!localModeOn(store)) {
|
|
385
|
+
else if (door.kind === "first-start" && !localModeOn(store)) {
|
|
382
386
|
return refused("authority", "Only a laptop install's first start chooses its models by itself.");
|
|
383
387
|
}
|
|
384
388
|
const anyRow = store.handle.prepare("SELECT 1 FROM phase_config UNION ALL SELECT 1 FROM phase_tier_config UNION ALL SELECT 1 FROM phase_tier_alternate LIMIT 1").get();
|
|
385
389
|
if (anyRow !== undefined)
|
|
386
390
|
return refused("already-set", "Models are already chosen here.");
|
|
387
|
-
if (door.kind
|
|
391
|
+
if (door.kind !== "local-owner" && store.handle.prepare("SELECT 1 FROM models_generation LIMIT 1").get() !== undefined) {
|
|
388
392
|
return refused("already-set", "Models were chosen here before.");
|
|
389
393
|
}
|
|
390
394
|
store.handle.exec("SAVEPOINT default_routing");
|
|
@@ -398,9 +402,11 @@ export function fillDefaultRouting(store, agent, actor, door, now) {
|
|
|
398
402
|
else
|
|
399
403
|
store.setPhaseTierConfig(INSTALLATION_SCOPE, slot.phase, slot.tier, to.provider, to.model, actor, now);
|
|
400
404
|
store.recordAction({ at: now.toISOString(), actor, repo: null, taskId: null, runId: null, action: ACTION_OF(slot), outcome: "changed", source: "policy",
|
|
401
|
-
detail: `not set → ${pairWords(to)} (${AGENT_PRESETS[agent].label}, the default for the agent chosen)` });
|
|
405
|
+
detail: `not set → ${pairWords(to)} (${AGENT_PRESETS[agent].label}, ${door.kind === "detected" ? "the default for the agent found signed in on this computer" : "the default for the agent chosen"})` });
|
|
402
406
|
rows++;
|
|
403
407
|
}
|
|
408
|
+
if (door.kind === "detected")
|
|
409
|
+
store.recordInstallationFact(FIRST_TASK_AGENT_FACT, agent, now);
|
|
404
410
|
const checked = checkScope(store, null);
|
|
405
411
|
if (checked.kind !== "ok") {
|
|
406
412
|
store.handle.exec("ROLLBACK TO default_routing");
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
+
import { envTwins } from "./names.js";
|
|
3
|
+
import { outboundPrivate, safeWords } from "./outbound-privacy.js";
|
|
4
|
+
export function notificationCommandEnv(row) {
|
|
5
|
+
const withheld = outboundPrivate([row.subject, row.body]);
|
|
6
|
+
return {
|
|
7
|
+
...envTwins("KIND", row.kind),
|
|
8
|
+
...envTwins("SUBJECT", withheld ? safeWords({ project: row.project }) : row.subject),
|
|
9
|
+
...envTwins("BODY", withheld ? "" : row.body),
|
|
10
|
+
...envTwins("DEDUPE_KEY", row.dedupeKey),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
2
13
|
export function notificationDestination(kind, target) {
|
|
3
14
|
return `${kind}:${createHash("sha256").update(target).digest("hex")}`;
|
|
4
15
|
}
|
package/dist/operate.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { FLEXIBLE_CANDIDATE_FIXED, FLEXIBLE_FILED_PREFIX, flexibleMergeRefusal } from "./flexible-merge-guard.js";
|
|
2
|
+
import { flexibleArmedPass } from "./flexible-ship.js";
|
|
1
3
|
import { runCardCommand } from "./card-cli.js";
|
|
2
4
|
import { mintSecret } from "./secret-mint.js";
|
|
3
5
|
import { ACP_AGENTS, ACP_PROVIDER_IDS, isAcpProvider, isKeyedProvider } from "./acp-agents.js";
|
|
4
6
|
import { inspectAcpAgent } from "./acp-inspect.js";
|
|
5
7
|
import { runAcpChecks } from "./acp-check.js";
|
|
6
8
|
import { verifyLaunch } from "./acp-attest.js";
|
|
7
|
-
import { notificationClaimHeld, claimNotifications, finalizeNotification, notificationDestination } from "./notification-delivery.js";
|
|
9
|
+
import { notificationClaimHeld, claimNotifications, finalizeNotification, notificationCommandEnv, notificationDestination } from "./notification-delivery.js";
|
|
8
10
|
import { adapterPolicy } from "./server/route-policy.js";
|
|
9
11
|
import { UNSENT_REPLY_MS } from "./telegram-settings.js";
|
|
10
12
|
import { checkPublicCommand } from "./public-check.js";
|
|
@@ -87,6 +89,7 @@ import { scheduledTidy } from "./memory-tidy.js";
|
|
|
87
89
|
import { CI_READ_EVERY_MS, ciCursorKey, ciRepositoriesOf, observeCiAttempts } from "./flaky-ci.js";
|
|
88
90
|
import { runKnowledgeApply, runKnowledgeCommand } from "./knowledge-cli.js";
|
|
89
91
|
import { FLOWS_VALUE_FLAGS, runFlowsCommand } from "./flows-cli.js";
|
|
92
|
+
import { approvalSummaryFor, approvalSummaryOf, describeScope, summaryContextOf } from "./approval-summary.js";
|
|
90
93
|
import { runAssignmentCommand } from "./assignment-adapters.js";
|
|
91
94
|
import { applyProjectProfile, runProjectCommand } from "./project-cli.js";
|
|
92
95
|
import { passwordFreeOwner, passwordFreeShell, passwordFreeShellWords, proveTaskBuildsStopped, pullRequestLines, runLocalCompletion, runLocalRevision, runTaskMergeCommand, runTaskOutcomeCommand } from "./task-outcome-cli.js";
|
|
@@ -109,7 +112,7 @@ import { addRepos, removeRepos, updateRepos, loadRepos, loadProjectRegistry, upd
|
|
|
109
112
|
import { deleteProject, holdingsWords, projectHoldings, projectRunning } from "./project-delete.js";
|
|
110
113
|
import { pushPass } from "./push.js";
|
|
111
114
|
import { chmodSync, closeSync, constants as fsConstants, existsSync, fstatSync, fsyncSync, mkdirSync, openSync, readFileSync, readSync, realpathSync, renameSync, unlinkSync, writeSync, writeFileSync } from "node:fs";
|
|
112
|
-
import { BRANCH_PREFIX,
|
|
115
|
+
import { BRANCH_PREFIX, envValue, existingOrFirst, taskBranches } from "./names.js";
|
|
113
116
|
import { claimActor, currentActor, withActor } from "./actor.js";
|
|
114
117
|
import { parseLeadToken } from "./api-tokens.js";
|
|
115
118
|
import { MAX_NETWORK_HOSTS, normalizeHost } from "./egress.js";
|
|
@@ -200,7 +203,7 @@ import { serveMcp } from "./mcp.js";
|
|
|
200
203
|
import { createInterface } from "node:readline";
|
|
201
204
|
import { hashPassword } from "./scope.js";
|
|
202
205
|
import { noticeDueOnce, CONTAINMENT_NOTICE_FACT, passwordResetRefusal, resetAccountPassword } from "./store.js";
|
|
203
|
-
import { propose, approve, addApprover, authenticateAccount, authenticateApprover as passwordApprover,
|
|
206
|
+
import { propose, approve, addApprover, authenticateAccount, authenticateApprover as passwordApprover, approvalOf, hashToken as hashApproverToken, modeFilingCoverage, acceptanceLinesToInput, parseAcceptanceCriteria, splitAcceptanceRubric, rubricIsPlaceholder, isCommitSha, credentialProof, rememberedLogin, personApprovalOf } from "./scope.js";
|
|
204
207
|
import { CHAT_APPROVE_ALL, presetTerms, modeTermsJson, modeDigestOf, modeTermsFromJson, modeWords, MODE_MAX_DAYS } from "./modes.js";
|
|
205
208
|
import { WorktreePool } from "./worktree.js";
|
|
206
209
|
import { baseStandingWords, freshBaseFor, taskBaseOf } from "./task-base.js";
|
|
@@ -232,7 +235,7 @@ import { fileGithubItem, readGithubItem } from "./github-import.js";
|
|
|
232
235
|
import { runRelease } from "./release.js";
|
|
233
236
|
import { releaseAdapters } from "./release-adapters.js";
|
|
234
237
|
import { routeChangeOf, routeLegacyPlans } from "./route-change.js";
|
|
235
|
-
import {
|
|
238
|
+
import { sessionStandsIn } from "./install-mode.js";
|
|
236
239
|
import { parseDemoUrl, projectDemoUrl, saveProjectDemo } from "./project-demo.js";
|
|
237
240
|
import { effectiveConcurrency, maySlotTake, parseProjectConcurrency, PROJECT_CONCURRENCY_DEFAULT, ProjectPasses, projectConcurrency, saveProjectConcurrency, savedProjectConcurrency } from "./project-concurrency.js";
|
|
238
241
|
import { activeWebhookTargets, webhookPass, LEGACY_WEBHOOK_WARNING, loadWebhookTargets, effectivePrimary, isMessagingChannel, loadConsoleUrl, phoneOrigin, readUpConsoleUrl, saveConsoleUrl, savePrimary, UP_CONSOLE_FILE } from "./webhooks.js";
|
|
@@ -447,7 +450,7 @@ External trackers — build what a tracker nominates, under local approvals
|
|
|
447
450
|
toolroll task scope <id> --goal <what success is>
|
|
448
451
|
[--not <text>] [--touches a,b] [--budget-usd <n>]
|
|
449
452
|
toolroll task approve <id> the yes — interactive, or
|
|
450
|
-
--yes --digest <d> --as <you> --token <t>
|
|
453
|
+
--yes --digest <d> --terms <key> --as <you> --token <t>
|
|
451
454
|
toolroll task requeue <id> --as <you> --token <t>
|
|
452
455
|
exit a stall: incidents resolved,
|
|
453
456
|
strikes cleared, queued again
|
|
@@ -708,7 +711,7 @@ export const SECRET_VALUE_FLAGS = new Set(["token", "password"]);
|
|
|
708
711
|
export const OPERATE_VALUE_FLAGS = new Set([
|
|
709
712
|
"key", "db", "runner", "ttl", "state", "flow", "on", "reason", "until", "id", "backend", "build", "from",
|
|
710
713
|
"allow", "selector", "paths", "credentials", "repo", "token", "capacity", "agents",
|
|
711
|
-
"goal", "not", "touches", "acceptance", "candidate", "by", "digest", "as", "branch", "pool", "base", "model", "turns",
|
|
714
|
+
"goal", "not", "touches", "acceptance", "candidate", "by", "digest", "terms", "as", "branch", "pool", "base", "model", "turns",
|
|
712
715
|
"max", "cap", "probe", "kind", "expires", "cmd", "since", "repair-model",
|
|
713
716
|
"choose", "choice", "claim", "revision", "note", "max-open-decisions", "name", "days", "publication", "auto-approve", "review-auto", "port", "host", "allow-host",
|
|
714
717
|
"for", "tick-every", "bridge-every", "reconcile-every", "incarnation",
|
|
@@ -3448,7 +3451,7 @@ async function startConsole(options) {
|
|
|
3448
3451
|
stopMonitoring,
|
|
3449
3452
|
startBudgetAlerts(context.store),
|
|
3450
3453
|
startTokenNotices(context.store),
|
|
3451
|
-
startSignInProbes(context.store, createConnectionChecker()),
|
|
3454
|
+
startSignInProbes(context.store, createConnectionChecker({ store: context.store })),
|
|
3452
3455
|
startBackups(context.store, context.databaseFile),
|
|
3453
3456
|
startCodexLimits(context.store),
|
|
3454
3457
|
startUpdateChecks(context.store, dirname(context.databaseFile), PACKAGE_VERSION, installMethod(context.installBin).updateCommand, context.releaseIo ?? {}),
|
|
@@ -3858,10 +3861,20 @@ async function agentsCommand(positional, flags, context) {
|
|
|
3858
3861
|
const latest = store.acpChecksFor(id, 1)[0] ?? null;
|
|
3859
3862
|
return { provider: id, name: ACP_AGENTS[id].name, installed: seen.found ? seen.realpath : null, checked, latestCheck: latest === null ? null : { id: latest.id, state: latest.state, model: latest.model, result: latest.result } };
|
|
3860
3863
|
});
|
|
3864
|
+
const { detectAgents, detectionReport } = await import("./agent-detect.js");
|
|
3865
|
+
const { agentsReadOf } = await import("./engine-reads.js");
|
|
3866
|
+
const { acpCheckedHere, firstTaskRouted } = await import("./welcome-facts.js");
|
|
3867
|
+
const detection = await detectAgents({ routed: firstTaskRouted(store), acpChecked: acpCheckedHere(store), store,
|
|
3868
|
+
...(context.easySeams?.check === undefined ? {} : { check: context.easySeams.check }) });
|
|
3869
|
+
const { version: _version, ...detected } = agentsReadOf(detection);
|
|
3861
3870
|
if (json) {
|
|
3862
|
-
write(envelopeJson({ ok: true, command: "agents", agents: rows }));
|
|
3871
|
+
write(envelopeJson({ ok: true, command: "agents", detected: { ...detected, tookMs: detection.tookMs }, agents: rows }));
|
|
3863
3872
|
return EXIT.ok;
|
|
3864
3873
|
}
|
|
3874
|
+
for (const line of detectionReport(detection))
|
|
3875
|
+
write(line);
|
|
3876
|
+
write("");
|
|
3877
|
+
write("Checks (agents that run over ACP)");
|
|
3865
3878
|
for (const row of rows) {
|
|
3866
3879
|
write(` ${row.name.padEnd(10)} ${row.installed === null ? "not installed" : row.installed}`);
|
|
3867
3880
|
for (const one of row.checked)
|
|
@@ -5474,6 +5487,18 @@ async function runWatchLoop(args) {
|
|
|
5474
5487
|
reconciliationReady = true;
|
|
5475
5488
|
if (recovered)
|
|
5476
5489
|
wakes.poke();
|
|
5490
|
+
if (!stopping()) {
|
|
5491
|
+
try {
|
|
5492
|
+
const shipped = await flexibleArmedPass(store, { root: context.evidenceRoot, ...(context.publishExec === undefined ? {} : { exec: context.publishExec }) });
|
|
5493
|
+
if (shipped.ok && shipped.merged > 0)
|
|
5494
|
+
progress(`watch: merged ${shipped.merged} Flexible result(s) whose checks passed`);
|
|
5495
|
+
if (shipped.ok && shipped.cancelled > 0)
|
|
5496
|
+
progress(`watch: stopped ${shipped.cancelled} Flexible merge(s) whose terms no longer held`);
|
|
5497
|
+
}
|
|
5498
|
+
catch (error) {
|
|
5499
|
+
progress(`watch: the Flexible ship pass failed — ${describe(error)}; retrying on its next interval`);
|
|
5500
|
+
}
|
|
5501
|
+
}
|
|
5477
5502
|
if (!stopping() && store.openedPublications().length > 0) {
|
|
5478
5503
|
try {
|
|
5479
5504
|
const checks = await observeChecks(store, {
|
|
@@ -6052,7 +6077,7 @@ async function onboardCommand(flags, context) {
|
|
|
6052
6077
|
const loginFile = savedLoginFile(dirname(context.databaseFile));
|
|
6053
6078
|
const gitRun = context.gitRunner ?? ((file, args, opts) => run(file, [...args], { ...(opts?.cwd === undefined ? {} : { cwd: opts.cwd }), timeoutMs: 10_000 }));
|
|
6054
6079
|
const registryPath = registryPathOf(context);
|
|
6055
|
-
const checker = createConnectionChecker({ home, env });
|
|
6080
|
+
const checker = createConnectionChecker({ home, env, store: context.store });
|
|
6056
6081
|
const code = await runOnboard({
|
|
6057
6082
|
write,
|
|
6058
6083
|
json,
|
|
@@ -6874,7 +6899,7 @@ async function publishCommand(positional, flags, context) {
|
|
|
6874
6899
|
return EXIT.refused;
|
|
6875
6900
|
}
|
|
6876
6901
|
const acting = await askCredentials(flags, context);
|
|
6877
|
-
const verified = acting === null ? null :
|
|
6902
|
+
const verified = acting === null ? null : credentialApprover(store, acting.name, acting.token, repo);
|
|
6878
6903
|
if (acting === null || !verified?.ok)
|
|
6879
6904
|
return refuseApprover(context, "publish setup", verified, "turning on pull requests takes --as <you> --token <your password>", acting?.name);
|
|
6880
6905
|
savePublishing(store, plan, acting.name, settings, clock());
|
|
@@ -6923,7 +6948,7 @@ async function publishCommand(positional, flags, context) {
|
|
|
6923
6948
|
return EXIT.refused;
|
|
6924
6949
|
}
|
|
6925
6950
|
const acting = await askCredentials(flags, context);
|
|
6926
|
-
const verified = acting === null ? null :
|
|
6951
|
+
const verified = acting === null ? null : credentialApprover(store, acting.name, acting.token);
|
|
6927
6952
|
if (acting === null || !verified?.ok)
|
|
6928
6953
|
return refuseApprover(context, "publish grant", verified, "granting takes --as <you> --token <your password> — pushing your repos is a person's yes", acting?.name);
|
|
6929
6954
|
const { name: asWho, token } = acting;
|
|
@@ -6973,6 +6998,9 @@ async function publishCommand(positional, flags, context) {
|
|
|
6973
6998
|
const publication = store.openedPublications().find(one => one.prNumber === pr);
|
|
6974
6999
|
if (publication === undefined)
|
|
6975
7000
|
return fail(write, json, `publish ${action}`, "unknown", `no open publication holds PR #${pr}`, EXIT.refused);
|
|
7001
|
+
const flexibleHold = flexibleMergeRefusal(store, store.refForId(publication.taskRef)?.externalId ?? null, action === "merge" ? "publish-merge" : "publish-refire");
|
|
7002
|
+
if (flexibleHold !== null)
|
|
7003
|
+
return fail(write, json, `publish ${action}`, "flexible", flexibleHold, EXIT.refused);
|
|
6976
7004
|
const intent = store.mergeIntentFor(publication.id);
|
|
6977
7005
|
if (intent === null)
|
|
6978
7006
|
return fail(write, json, `publish ${action}`, "no-intent", `PR #${pr} has no merge intent yet — the sweep writes one when a merge-capable grant covers it`, EXIT.refused);
|
|
@@ -7144,12 +7172,7 @@ async function outboxCommand(positional, flags, context) {
|
|
|
7144
7172
|
}
|
|
7145
7173
|
const sent = await run("sh", ["-lc", command], {
|
|
7146
7174
|
timeoutMs: 30_000,
|
|
7147
|
-
env:
|
|
7148
|
-
...envTwins("KIND", one.kind),
|
|
7149
|
-
...envTwins("SUBJECT", one.subject),
|
|
7150
|
-
...envTwins("BODY", one.body),
|
|
7151
|
-
...envTwins("DEDUPE_KEY", one.dedupeKey),
|
|
7152
|
-
},
|
|
7175
|
+
env: notificationCommandEnv(one),
|
|
7153
7176
|
});
|
|
7154
7177
|
if (sent.code === 0) {
|
|
7155
7178
|
const receipt = sent.stdout.split("\n")[0]?.trim() ?? "";
|
|
@@ -7390,7 +7413,7 @@ async function integrationIoFor(context) {
|
|
|
7390
7413
|
env: process.env,
|
|
7391
7414
|
repos,
|
|
7392
7415
|
gh: (file, args, options) => run(file, [...args], options),
|
|
7393
|
-
checkConnection: createConnectionChecker(),
|
|
7416
|
+
checkConnection: createConnectionChecker({ store: context.store }),
|
|
7394
7417
|
clock: context.clock,
|
|
7395
7418
|
...seams,
|
|
7396
7419
|
};
|
|
@@ -8018,6 +8041,7 @@ function showTask(positional, context) {
|
|
|
8018
8041
|
pullRequest: newestPullRequestOf(store, store.taskFamilyOf(id, null, true)?.versions.map(one => one.id) ?? [id]),
|
|
8019
8042
|
steering: store.listSteerNotes(ref.id).map(one => ({ id: one.id, author: one.author, createdAt: one.createdAt, note: one.note,
|
|
8020
8043
|
standing: steerStandingOf(one, steeringLive), words: steerStandingWords(one, steeringLive, utcMinute) })),
|
|
8044
|
+
approvalTerms: scope === null ? null : approvalSummaryOf(scope, summaryContextOf(store, id, scope, now)).key,
|
|
8021
8045
|
};
|
|
8022
8046
|
return succeed(write, json, "task show", detail, () => [
|
|
8023
8047
|
`${task.id} ${task.state}${ref.deliverable === "report" ? " (scout — delivers a report)" : ""}`,
|
|
@@ -8065,7 +8089,7 @@ function showTask(positional, context) {
|
|
|
8065
8089
|
...(detail.automaticReview === null ? reviewStatusLines(detail.review, latestFinished?.id ?? null) : buildReviewLines(detail.automaticReview)),
|
|
8066
8090
|
...(scope === null
|
|
8067
8091
|
? [" no plan yet — nothing is built until one is written and approved"]
|
|
8068
|
-
: describeScope(scope, readiness, taskEvidenceWords(store, task.id, now))),
|
|
8092
|
+
: describeScope(scope, readiness, taskEvidenceWords(store, task.id, now), summaryContextOf(store, task.id, scope, now))),
|
|
8069
8093
|
...planContractLines(store, context.evidenceRoot, id),
|
|
8070
8094
|
...taskRouteStandingLines(id, routed, detail.dispatch?.summary === NO_AGENT_TITLE),
|
|
8071
8095
|
...detail.runs
|
|
@@ -8607,6 +8631,8 @@ async function scopeTask(positional, flags, context) {
|
|
|
8607
8631
|
return fail(write, json, "task scope", "usage", "`toolroll task scope <id> --goal <what success is> --acceptance <rubric> [--not <text>] [--touches a,b] [--candidate <commit>] [--budget-usd <n>]`", EXIT.usage);
|
|
8608
8632
|
if (store.getTask(id) === null)
|
|
8609
8633
|
return fail(write, json, "task scope", "unknown-task", `no task \`${id}\``, EXIT.refused);
|
|
8634
|
+
if (store.filedViaOf(id)?.startsWith(FLEXIBLE_FILED_PREFIX) === true)
|
|
8635
|
+
return fail(write, json, "task scope", "flexible", FLEXIBLE_CANDIDATE_FIXED, EXIT.refused);
|
|
8610
8636
|
const acceptanceGiven = text(flags, "acceptance");
|
|
8611
8637
|
if (acceptanceGiven === undefined) {
|
|
8612
8638
|
return fail(write, json, "task scope", "acceptance-required", "a scope needs at least one signed acceptance criterion — `--acceptance \"<statement>|<evidence,kinds>\"`, `;`-separated for more than one; evidence kinds are check, screenshot, changed-path, manual-review", EXIT.usage);
|
|
@@ -8728,13 +8754,13 @@ async function scopeTask(positional, flags, context) {
|
|
|
8728
8754
|
if (filed.modeRefusedCoordinator === true) {
|
|
8729
8755
|
return succeed(write, json, "task scope", { scope, approvedUnderMode: false, quarantined: true }, () => [
|
|
8730
8756
|
`Scope written for ${id} — but coordinator-filed: mode coverage cannot admit it; sign the scope.`,
|
|
8731
|
-
...describeScope(scope),
|
|
8757
|
+
...describeScope(scope, undefined, null, summaryContextOf(store, id, scope, now)),
|
|
8732
8758
|
]);
|
|
8733
8759
|
}
|
|
8734
8760
|
if (filed.sealedUnderMode) {
|
|
8735
8761
|
return succeed(write, json, "task scope", { scope, approvedUnderMode: true }, () => [
|
|
8736
8762
|
`Scope written AND approved for ${id} — your operating mode covered it; it dispatches on the next pass.`,
|
|
8737
|
-
...describeScope(scope),
|
|
8763
|
+
...describeScope(scope, undefined, null, summaryContextOf(store, id, scope, now)),
|
|
8738
8764
|
]);
|
|
8739
8765
|
}
|
|
8740
8766
|
const replanned = (store.lookupRef(id)?.planningGeneration ?? 0) > generationBefore;
|
|
@@ -8743,7 +8769,7 @@ async function scopeTask(positional, flags, context) {
|
|
|
8743
8769
|
replanned
|
|
8744
8770
|
? `Scope written for ${id}. The scope changed, so planning starts again; nothing builds until somebody approves the new plan.`
|
|
8745
8771
|
: `Scope written for ${id}. Nothing will build it until somebody approves it.`,
|
|
8746
|
-
...describeScope(scope),
|
|
8772
|
+
...describeScope(scope, undefined, null, summaryContextOf(store, id, scope, now)),
|
|
8747
8773
|
"",
|
|
8748
8774
|
` toolroll task approve ${id} --yes`,
|
|
8749
8775
|
]);
|
|
@@ -8864,6 +8890,8 @@ async function approveTask(positional, flags, context) {
|
|
|
8864
8890
|
if (store.lookupRef(id)?.plan === "requested")
|
|
8865
8891
|
return fail(write, json, "task approve", "planning", `${id} is waiting on a planner — approval is blocked until the drafted plan lands`, EXIT.refused);
|
|
8866
8892
|
let saw = text(flags, "digest");
|
|
8893
|
+
const summary = approvalSummaryOf(scope, summaryContextOf(store, id, scope, now));
|
|
8894
|
+
let shownTerms = text(flags, "terms");
|
|
8867
8895
|
let { name: asWho, token } = credentialsFrom(flags, context);
|
|
8868
8896
|
let confirmedAloud = false;
|
|
8869
8897
|
if ((!flags.has("yes") || saw === undefined || asWho === undefined || token === undefined) &&
|
|
@@ -8875,7 +8903,7 @@ async function approveTask(positional, flags, context) {
|
|
|
8875
8903
|
write(changed);
|
|
8876
8904
|
write("");
|
|
8877
8905
|
}
|
|
8878
|
-
for (const line of describeScope(scope))
|
|
8906
|
+
for (const line of describeScope(scope, undefined, null, summaryContextOf(store, id, scope, now)))
|
|
8879
8907
|
write(line);
|
|
8880
8908
|
for (const line of planContractLines(store, context.evidenceRoot, id))
|
|
8881
8909
|
write(line);
|
|
@@ -8886,6 +8914,7 @@ async function approveTask(positional, flags, context) {
|
|
|
8886
8914
|
return EXIT.refused;
|
|
8887
8915
|
}
|
|
8888
8916
|
saw ??= scope.digest;
|
|
8917
|
+
shownTerms ??= summary.key;
|
|
8889
8918
|
const acting = await askCredentials(flags, context);
|
|
8890
8919
|
if (acting === null)
|
|
8891
8920
|
return fail(write, json, "task approve", "usage", "approval needs who is agreeing", EXIT.usage);
|
|
@@ -8897,7 +8926,7 @@ async function approveTask(positional, flags, context) {
|
|
|
8897
8926
|
saw !== undefined && asWho !== undefined && token !== undefined;
|
|
8898
8927
|
if (!armed) {
|
|
8899
8928
|
if (json) {
|
|
8900
|
-
write(envelopeJson({ ok: false, command: "task approve", reason: "unconfirmed", scope }));
|
|
8929
|
+
write(envelopeJson({ ok: false, command: "task approve", reason: "unconfirmed", scope, terms: summary.key }));
|
|
8901
8930
|
return EXIT.refused;
|
|
8902
8931
|
}
|
|
8903
8932
|
write(`Would approve this, and let a builder work on ${id}:`);
|
|
@@ -8907,18 +8936,33 @@ async function approveTask(positional, flags, context) {
|
|
|
8907
8936
|
write(changed);
|
|
8908
8937
|
write("");
|
|
8909
8938
|
}
|
|
8910
|
-
for (const line of describeScope(scope))
|
|
8939
|
+
for (const line of describeScope(scope, undefined, null, summaryContextOf(store, id, scope, now)))
|
|
8911
8940
|
write(line);
|
|
8912
8941
|
for (const line of planContractLines(store, context.evidenceRoot, id))
|
|
8913
8942
|
write(line);
|
|
8914
8943
|
write("");
|
|
8915
8944
|
write("Nothing has been approved. Agree to this exact scope with:");
|
|
8916
|
-
write(` toolroll task approve ${id} --yes --digest ${scope.digest} --as <you> --token <your password>`);
|
|
8945
|
+
write(` toolroll task approve ${id} --yes --digest ${scope.digest} --terms ${summary.key} --as <you> --token <your password>`);
|
|
8917
8946
|
return EXIT.refused;
|
|
8918
8947
|
}
|
|
8919
8948
|
if (saw === undefined || asWho === undefined || token === undefined)
|
|
8920
|
-
return fail(write, json, "task approve", "usage", "approving non-interactively takes --yes --digest <d> --as <you> --token <t>", EXIT.usage);
|
|
8921
|
-
|
|
8949
|
+
return fail(write, json, "task approve", "usage", "approving non-interactively takes --yes --digest <d> --terms <key> --as <you> --token <t>", EXIT.usage);
|
|
8950
|
+
if (shownTerms === undefined) {
|
|
8951
|
+
if (json) {
|
|
8952
|
+
write(envelopeJson({ ok: false, command: "task approve", reason: "unconfirmed", message: "Name the terms you read: --terms <key>. Nothing was approved.", scope, terms: summary.key }));
|
|
8953
|
+
return EXIT.refused;
|
|
8954
|
+
}
|
|
8955
|
+
write(`Name the terms you read. Nothing was approved. ${id} would be approved on exactly this:`);
|
|
8956
|
+
write("");
|
|
8957
|
+
for (const line of describeScope(scope, undefined, null, summaryContextOf(store, id, scope, now)))
|
|
8958
|
+
write(line);
|
|
8959
|
+
write("");
|
|
8960
|
+
write(` toolroll task approve ${id} --yes --digest ${scope.digest} --terms ${summary.key} --as <you> --token <your password>`);
|
|
8961
|
+
return EXIT.refused;
|
|
8962
|
+
}
|
|
8963
|
+
const terms = shownTerms;
|
|
8964
|
+
const approved = store.transact(() => terms !== undefined && approvalSummaryFor(store, id, now)?.key !== terms ? { ok: false, reason: "changed" }
|
|
8965
|
+
: approve(store, id, asWho, now, saw, token, mutationFrom(flags, now)));
|
|
8922
8966
|
if (!approved.ok) {
|
|
8923
8967
|
if (approved.reason === "policy")
|
|
8924
8968
|
return fail(write, json, "task approve", "policy", `${id}: ${approved.message}`, EXIT.refused);
|
|
@@ -8926,7 +8970,7 @@ async function approveTask(positional, flags, context) {
|
|
|
8926
8970
|
}
|
|
8927
8971
|
return succeed(write, json, "task approve", { scope: approved.scope }, () => [
|
|
8928
8972
|
`Approved. A builder may now work on ${id}, within this scope:`,
|
|
8929
|
-
...describeScope(approved.scope),
|
|
8973
|
+
...describeScope(approved.scope, undefined, null, summaryContextOf(store, id, approved.scope, now)),
|
|
8930
8974
|
]);
|
|
8931
8975
|
}
|
|
8932
8976
|
function describeApproveFailure(reason, id) {
|
|
@@ -11822,7 +11866,7 @@ async function newTaskCommand(positional, flags, context) {
|
|
|
11822
11866
|
if (local === null && (json || !personAtTerminal(context)))
|
|
11823
11867
|
return fail(write, json, command, "person-only", "`task new` asks a person at a terminal. Use `task add` from a script or an agent.", EXIT.refused);
|
|
11824
11868
|
const { name, token } = credentialsFrom(flags, context);
|
|
11825
|
-
const passwordFree = token !== undefined && (local !== null ||
|
|
11869
|
+
const passwordFree = token !== undefined && (local !== null || sessionStandsIn(store));
|
|
11826
11870
|
const facts = { passwordless: local === null && passwordFree, localOwner: local !== null, freshAt: null, returnTo: "/" };
|
|
11827
11871
|
const buildNow = (preview, digest) => fastStartBuild(store, { preview, digest, actor: name ?? "", via: local === null ? "cli" : "terminal-ui", password: facts,
|
|
11828
11872
|
approveNow: (taskId, sawDigest, fast) => approve(store, taskId, name ?? "", clock(), sawDigest, token ?? "", {}, fast) }, clock());
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { scanForSecrets } from "./evidence.js";
|
|
2
|
+
const HOME_FOLDER = /(?:^|[\s"'`(<[=:,])(?:\/Users\/|\/home\/|\/root\/|~\/)/;
|
|
3
|
+
const DRIVE_OR_SHARE = /(?<![A-Za-z0-9+.-])[A-Za-z]:[\\/]|\\\\|\bfile:\/\//i;
|
|
4
|
+
export function privateWords(text) {
|
|
5
|
+
return scanForSecrets(text).length > 0 || /\b\d{5,}:[A-Za-z0-9_-]{20,}\b/.test(text) || HOME_FOLDER.test(text) || DRIVE_OR_SHARE.test(text);
|
|
6
|
+
}
|
|
7
|
+
export const outboundPrivate = (fields) => fields.some(privateWords);
|
|
8
|
+
export function textsOf(value, depth = 0) {
|
|
9
|
+
if (typeof value === "string")
|
|
10
|
+
return [value];
|
|
11
|
+
if (depth > 12 || value === null || typeof value !== "object")
|
|
12
|
+
return [];
|
|
13
|
+
return (Array.isArray(value) ? value : Object.values(value)).flatMap(one => textsOf(one, depth + 1));
|
|
14
|
+
}
|
|
15
|
+
const unescaped = (text) => text.replace(/\\([\\`*_{}[\]()#+\-.!|~>])/g, "$1");
|
|
16
|
+
export const privateValue = (value) => textsOf(value).some(text => privateWords(text) || privateWords(unescaped(text)));
|
|
17
|
+
export function projectName(repo) {
|
|
18
|
+
if (repo === null || repo === undefined)
|
|
19
|
+
return null;
|
|
20
|
+
const name = (repo.split(/[\\/]/).filter(Boolean).pop() ?? "").replace(/[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2060-\u206f]/g, "").trim().slice(0, 48);
|
|
21
|
+
return name === "" || privateWords(name) || privateWords(` ${name}`) ? null : name;
|
|
22
|
+
}
|
|
23
|
+
export function taskSubject(store, task) {
|
|
24
|
+
if (task === null || task === undefined || task === "")
|
|
25
|
+
return { project: null };
|
|
26
|
+
return { project: store.lookupRef(task)?.repo ?? null, withheld: privateWords(store.getTask(task)?.title ?? "") };
|
|
27
|
+
}
|
|
28
|
+
export function safeWords(subject) {
|
|
29
|
+
const name = projectName(subject?.project);
|
|
30
|
+
return name === null ? "An update is ready. Open it in Toolroll." : `An update is ready in ${name}. Open it in Toolroll.`;
|
|
31
|
+
}
|
|
32
|
+
export function checkedChunks(whole, chunks, subject) {
|
|
33
|
+
return privateValue(whole) ? [safeWords(subject)] : [...chunks];
|
|
34
|
+
}
|
|
35
|
+
export const OPEN_IN_TOOLROLL = "Open in Toolroll";
|
|
36
|
+
export const WITHHELD = "Its words name a key or a folder on this computer, so it stays in Toolroll.";
|
|
37
|
+
export function safeLink(value) {
|
|
38
|
+
if (typeof value !== "string" || value.length > 2_000)
|
|
39
|
+
return null;
|
|
40
|
+
let url;
|
|
41
|
+
try {
|
|
42
|
+
url = new URL(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if ((url.protocol !== "https:" && url.protocol !== "http:") || url.username !== "" || url.password !== "")
|
|
48
|
+
return null;
|
|
49
|
+
let decoded;
|
|
50
|
+
try {
|
|
51
|
+
decoded = decodeURIComponent(`${url.pathname}${url.search}${url.hash}`);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (privateWords(value) || privateWords(` ${decoded}`))
|
|
57
|
+
return null;
|
|
58
|
+
return /[|<>\s]/.test(url.href) ? null : url.href;
|
|
59
|
+
}
|
|
60
|
+
export function firstLink(value, depth = 0) {
|
|
61
|
+
if (depth > 12 || value === null || typeof value !== "object")
|
|
62
|
+
return null;
|
|
63
|
+
for (const [key, one] of Object.entries(value)) {
|
|
64
|
+
if (key === "url" && safeLink(one) !== null)
|
|
65
|
+
return safeLink(one);
|
|
66
|
+
const found = firstLink(one, depth + 1);
|
|
67
|
+
if (found !== null)
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const pick = (from, keys) => Object.fromEntries(keys.filter(key => from[key] !== undefined).map(key => [key, from[key]]));
|
|
73
|
+
const goesSafe = (subject, message, ...values) => (message && subject?.withheld === true) || values.some(privateValue);
|
|
74
|
+
const checked = (made) => made === null || privateValue(made) ? null : made;
|
|
75
|
+
export function guardTelegram(transport, subject) {
|
|
76
|
+
return async (method, params, signal, upload, more) => {
|
|
77
|
+
const files = [upload, ...(more ?? [])].filter((one) => one !== undefined);
|
|
78
|
+
const privateFile = files.some(one => one.contentType === "text/plain" && privateWords(one.bytes.toString("utf8")));
|
|
79
|
+
if (!privateFile && !goesSafe(subject, TELEGRAM_MESSAGES.has(method), params))
|
|
80
|
+
return transport(method, params, signal, upload, more);
|
|
81
|
+
const safe = privateFile ? null : checked(safeTelegramCall(method, params, safeWords(subject)));
|
|
82
|
+
if (safe === null)
|
|
83
|
+
return { ok: false, description: WITHHELD };
|
|
84
|
+
return transport(method, safe, signal, upload, more);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const TELEGRAM_MESSAGES = new Set(["sendMessage", "editMessageText", "sendMessageDraft", "sendPhoto", "sendDocument", "editMessageCaption", "sendMediaGroup"]);
|
|
88
|
+
function safeTelegramCall(method, params, words) {
|
|
89
|
+
const link = firstLink(params["reply_markup"]);
|
|
90
|
+
const keyboard = link === null ? {} : { reply_markup: { inline_keyboard: [[{ text: OPEN_IN_TOOLROLL, url: link }]] } };
|
|
91
|
+
const where = pick(params, ["chat_id", "message_id", "inline_message_id", "message_thread_id", "reply_parameters", "draft_id", "disable_notification"]);
|
|
92
|
+
switch (method) {
|
|
93
|
+
case "sendMessage":
|
|
94
|
+
case "editMessageText":
|
|
95
|
+
case "sendMessageDraft":
|
|
96
|
+
return { ...where, text: words, link_preview_options: { is_disabled: true }, ...(method === "sendMessageDraft" ? {} : keyboard) };
|
|
97
|
+
case "sendPhoto":
|
|
98
|
+
case "sendDocument":
|
|
99
|
+
case "editMessageCaption":
|
|
100
|
+
return { ...pick(params, ["photo", "document"]), ...where, caption: words, ...keyboard };
|
|
101
|
+
case "sendMediaGroup": {
|
|
102
|
+
const media = Array.isArray(params["media"]) ? params["media"] : [];
|
|
103
|
+
return { ...where, media: media.map((one, index) => {
|
|
104
|
+
const item = one !== null && typeof one === "object" ? one : {};
|
|
105
|
+
return { ...pick(item, ["type", "media"]), ...(index === 0 ? { caption: words } : {}) };
|
|
106
|
+
}) };
|
|
107
|
+
}
|
|
108
|
+
case "answerCallbackQuery":
|
|
109
|
+
return { ...pick(params, ["callback_query_id"]), text: "Open it in Toolroll." };
|
|
110
|
+
default:
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function guardSlack(api, refuse, subject) {
|
|
115
|
+
return (async (method, args) => {
|
|
116
|
+
if (args === undefined || !goesSafe(subject, SLACK_MESSAGES.has(method), args))
|
|
117
|
+
return api(method, args);
|
|
118
|
+
const safe = checked(safeSlackCall(method, args, safeWords(subject)));
|
|
119
|
+
if (safe === null)
|
|
120
|
+
throw refuse();
|
|
121
|
+
return api(method, safe);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const SLACK_MESSAGES = new Set(["chat.postMessage", "chat.update", "chat.postEphemeral", "files.completeUploadExternal"]);
|
|
125
|
+
function safeSlackCall(method, args, words) {
|
|
126
|
+
const escaped = words.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
127
|
+
switch (method) {
|
|
128
|
+
case "chat.postMessage":
|
|
129
|
+
case "chat.update":
|
|
130
|
+
case "chat.postEphemeral": {
|
|
131
|
+
const link = firstLink(args["blocks"]) ?? firstLink(args["attachments"]);
|
|
132
|
+
const text = link === null ? escaped : `${escaped} <${link}|${OPEN_IN_TOOLROLL}>`;
|
|
133
|
+
return { ...pick(args, ["channel", "ts", "thread_ts", "user"]), text, blocks: [{ type: "section", text: { type: "mrkdwn", text, verbatim: true } }],
|
|
134
|
+
mrkdwn: true, parse: "none", link_names: false, unfurl_links: false, unfurl_media: false };
|
|
135
|
+
}
|
|
136
|
+
case "files.completeUploadExternal": {
|
|
137
|
+
const files = Array.isArray(args["files"]) ? args["files"] : [];
|
|
138
|
+
return { ...pick(args, ["channel_id", "thread_ts"]), initial_comment: words,
|
|
139
|
+
files: files.map(one => ({ id: one !== null && typeof one === "object" ? one["id"] : undefined, title: words })) };
|
|
140
|
+
}
|
|
141
|
+
default:
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function guardDiscord(api, refuse, subject) {
|
|
146
|
+
return (async (method, path, body, file) => {
|
|
147
|
+
if (!goesSafe(subject, body !== undefined && discordMessagePath(method, path) !== null, body, file?.name ?? ""))
|
|
148
|
+
return api(method, path, body, file);
|
|
149
|
+
const safe = file !== undefined && privateWords(file.name) ? null : checked(safeDiscordCall(method, path, body ?? {}, safeWords(subject)));
|
|
150
|
+
if (safe === null)
|
|
151
|
+
throw refuse();
|
|
152
|
+
return api(method, path, safe, file);
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function discordMessage(body, words) {
|
|
156
|
+
const link = firstLink(body["components"]) ?? firstLink(body["embeds"]);
|
|
157
|
+
const attachments = Array.isArray(body["attachments"]) ? body["attachments"].map(one => one !== null && typeof one === "object" ? pick(one, ["id", "filename"]) : {}) : undefined;
|
|
158
|
+
return { content: words.replace(/[\\*_~`|>#[\]()-]/g, "\\$&"), embeds: [],
|
|
159
|
+
components: link === null ? [] : [{ type: 1, components: [{ type: 2, style: 5, label: OPEN_IN_TOOLROLL, url: link }] }],
|
|
160
|
+
allowed_mentions: { parse: [], replied_user: false }, ...pick(body, ["message_reference", "flags"]), ...(attachments === undefined ? {} : { attachments }) };
|
|
161
|
+
}
|
|
162
|
+
function discordMessagePath(method, path) {
|
|
163
|
+
if ((method === "POST" || method === "PATCH") && /^\/channels\/[0-9]+\/messages(?:\/[0-9]+)?$/.test(path))
|
|
164
|
+
return "message";
|
|
165
|
+
if (method === "POST" && /^\/interactions\/[0-9]+\/[A-Za-z0-9._-]+\/callback$/.test(path))
|
|
166
|
+
return "interaction";
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
function safeDiscordCall(method, path, body, words) {
|
|
170
|
+
const kind = discordMessagePath(method, path);
|
|
171
|
+
if (kind === "message")
|
|
172
|
+
return discordMessage(body, words);
|
|
173
|
+
if (kind === "interaction") {
|
|
174
|
+
const data = body["data"] !== null && typeof body["data"] === "object" ? body["data"] : {};
|
|
175
|
+
return { type: body["type"], data: discordMessage(data, words) };
|
|
176
|
+
}
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
export function guardTeams(api, refuse, subject) {
|
|
180
|
+
return (async (method, serviceUrl, path, body) => {
|
|
181
|
+
if (!goesSafe(subject, teamsMessage(method, path, body), body))
|
|
182
|
+
return api(method, serviceUrl, path, body);
|
|
183
|
+
const safe = checked(teamsMessage(method, path, body) ? safeTeamsActivity(body, safeWords(subject)) : null);
|
|
184
|
+
if (safe === null)
|
|
185
|
+
throw refuse();
|
|
186
|
+
return api(method, serviceUrl, path, safe);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const teamsMessage = (method, path, body) => method !== "GET" && /\/activities(?:\/[^/]+)?$/.test(path) && body?.["type"] === "message";
|
|
190
|
+
function safeTeamsActivity(body, words) {
|
|
191
|
+
const link = firstLink(body["attachments"]);
|
|
192
|
+
const where = pick(body, ["replyToId"]);
|
|
193
|
+
if (link === null)
|
|
194
|
+
return { type: "message", ...where, text: words, textFormat: "plain" };
|
|
195
|
+
return { type: "message", ...where, attachments: [{ contentType: "application/vnd.microsoft.card.adaptive",
|
|
196
|
+
content: { type: "AdaptiveCard", version: "1.4", $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
|
|
197
|
+
body: [{ type: "TextBlock", text: words, wrap: true }], actions: [{ type: "Action.OpenUrl", title: OPEN_IN_TOOLROLL, url: link }] } }] };
|
|
198
|
+
}
|
|
199
|
+
export function safeMail(mail, subject) {
|
|
200
|
+
if (!outboundPrivate([mail.subject, mail.text]))
|
|
201
|
+
return mail;
|
|
202
|
+
const name = projectName(subject?.project);
|
|
203
|
+
return { ...mail, subject: name === null ? "An update from Toolroll" : `An update from Toolroll in ${name}`, text: safeWords(subject) };
|
|
204
|
+
}
|
package/dist/passwordless.js
CHANGED
|
@@ -13,7 +13,8 @@ export function passwordlessSetting(store) {
|
|
|
13
13
|
}
|
|
14
14
|
export const passwordlessOn = (store) => passwordlessSetting(store).on;
|
|
15
15
|
export function setPasswordless(store, on, by, now) {
|
|
16
|
-
|
|
16
|
+
const setting = passwordlessSetting(store);
|
|
17
|
+
if (setting.on === on && (on || setting.at !== null))
|
|
17
18
|
return { changed: false };
|
|
18
19
|
store.recordAction({ at: now.toISOString(), actor: by, repo: null, taskId: null, runId: null, action: PASSWORDLESS_ACTION, outcome: on ? "on" : "off", source: "policy",
|
|
19
20
|
detail: on ? "Passwordless on: signing in is the only password" : "Passwordless off: step-ups ask for the password again" });
|