@songsid/agend 2.3.5-alpha.5 → 2.3.5-alpha.6
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/THIRD_PARTY_NOTICES.md +0 -1
- package/dist/accounts-profiles.d.ts +96 -0
- package/dist/accounts-profiles.js +178 -0
- package/dist/accounts-profiles.js.map +1 -0
- package/dist/accounts-signout.d.ts +59 -0
- package/dist/accounts-signout.js +184 -0
- package/dist/accounts-signout.js.map +1 -0
- package/dist/accounts-view.d.ts +54 -0
- package/dist/accounts-view.js +55 -11
- package/dist/accounts-view.js.map +1 -1
- package/dist/agent-workspace.d.ts +11 -0
- package/dist/agent-workspace.js +28 -0
- package/dist/agent-workspace.js.map +1 -1
- package/dist/auth-api.js +27 -5
- package/dist/auth-api.js.map +1 -1
- package/dist/authority/session-authorizations.d.ts +2 -0
- package/dist/authority/session-authorizations.js +7 -1
- package/dist/authority/session-authorizations.js.map +1 -1
- package/dist/backend/codex.js +1 -0
- package/dist/backend/codex.js.map +1 -1
- package/dist/backend/types.d.ts +2 -0
- package/dist/backend/types.js.map +1 -1
- package/dist/build-provenance.json +1 -1
- package/dist/bundled-tmux-guard.d.ts +19 -0
- package/dist/bundled-tmux-guard.js +83 -0
- package/dist/bundled-tmux-guard.js.map +1 -0
- package/dist/classic-bindings.d.ts +13 -0
- package/dist/classic-bindings.js +28 -2
- package/dist/classic-bindings.js.map +1 -1
- package/dist/classic-channel-manager.d.ts +2 -0
- package/dist/classic-channel-manager.js +5 -1
- package/dist/classic-channel-manager.js.map +1 -1
- package/dist/cli.js +116 -11
- package/dist/cli.js.map +1 -1
- package/dist/config-validator.js +11 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/config.js +3 -1
- package/dist/config.js.map +1 -1
- package/dist/daemon.d.ts +27 -2
- package/dist/daemon.js +107 -6
- package/dist/daemon.js.map +1 -1
- package/dist/doctor.js +3 -4
- package/dist/doctor.js.map +1 -1
- package/dist/e2e-isolation.js +5 -2
- package/dist/e2e-isolation.js.map +1 -1
- package/dist/fleet-control-audit.d.ts +1 -1
- package/dist/fleet-manager.d.ts +129 -0
- package/dist/fleet-manager.js +725 -53
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +10 -0
- package/dist/hub/compose/server.js +1 -0
- package/dist/hub/compose/server.js.map +1 -1
- package/dist/hub/directory/directory.d.ts +1 -1
- package/dist/hub/directory/directory.js +115 -3
- package/dist/hub/directory/directory.js.map +1 -1
- package/dist/hub/directory/groups.d.ts +29 -0
- package/dist/hub/directory/groups.js +29 -0
- package/dist/hub/directory/groups.js.map +1 -0
- package/dist/hub/directory/index.d.ts +1 -0
- package/dist/hub/directory/types.d.ts +4 -0
- package/dist/hub/directory/types.js.map +1 -1
- package/dist/hub/group-policy/model.d.ts +56 -0
- package/dist/hub/group-policy/model.js +46 -0
- package/dist/hub/group-policy/model.js.map +1 -0
- package/dist/hub/group-policy/resources.d.ts +52 -0
- package/dist/hub/group-policy/resources.js +166 -0
- package/dist/hub/group-policy/resources.js.map +1 -0
- package/dist/hub/group-policy/store.d.ts +52 -0
- package/dist/hub/group-policy/store.js +149 -0
- package/dist/hub/group-policy/store.js.map +1 -0
- package/dist/hub/http/compose.js +4 -3
- package/dist/hub/http/compose.js.map +1 -1
- package/dist/hub/pairing.d.ts +3 -1
- package/dist/hub/pairing.js +6 -3
- package/dist/hub/pairing.js.map +1 -1
- package/dist/hub/server.d.ts +2 -0
- package/dist/hub/server.js +12 -2
- package/dist/hub/server.js.map +1 -1
- package/dist/instance-config-impact.js +4 -3
- package/dist/instance-config-impact.js.map +1 -1
- package/dist/instance-lifecycle.d.ts +17 -0
- package/dist/instance-lifecycle.js +38 -1
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +21 -0
- package/dist/locale.js.map +1 -1
- package/dist/login-controller.d.ts +5 -0
- package/dist/login-controller.js +11 -0
- package/dist/login-controller.js.map +1 -1
- package/dist/login-window-lock.d.ts +2 -1
- package/dist/login-window-lock.js.map +1 -1
- package/dist/ls-rows.d.ts +1 -1
- package/dist/ls-rows.js +1 -1
- package/dist/ls-rows.js.map +1 -1
- package/dist/machine-accounts.d.ts +110 -0
- package/dist/machine-accounts.js +229 -0
- package/dist/machine-accounts.js.map +1 -0
- package/dist/machine-signins.d.ts +89 -0
- package/dist/machine-signins.js +182 -0
- package/dist/machine-signins.js.map +1 -0
- package/dist/muse-usage-relay.d.ts +2 -0
- package/dist/muse-usage-relay.js +5 -3
- package/dist/muse-usage-relay.js.map +1 -1
- package/dist/needs-you-hub.d.ts +3 -0
- package/dist/needs-you-hub.js +13 -3
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +35 -2
- package/dist/needs-you.js +19 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/quickstart.js +7 -18
- package/dist/quickstart.js.map +1 -1
- package/dist/quiet-run.d.ts +31 -0
- package/dist/quiet-run.js +50 -0
- package/dist/quiet-run.js.map +1 -0
- package/dist/quota-notice-config.d.ts +22 -0
- package/dist/quota-notice-config.js +41 -0
- package/dist/quota-notice-config.js.map +1 -0
- package/dist/runtime-api.d.ts +13 -0
- package/dist/runtime-api.js +125 -1
- package/dist/runtime-api.js.map +1 -1
- package/dist/runtime-build-info.d.ts +2 -1
- package/dist/runtime-build-info.js +7 -3
- package/dist/runtime-build-info.js.map +1 -1
- package/dist/runtime-cli-install.d.ts +153 -0
- package/dist/runtime-cli-install.js +675 -0
- package/dist/runtime-cli-install.js.map +1 -0
- package/dist/runtime-cli.js +157 -12
- package/dist/runtime-cli.js.map +1 -1
- package/dist/runtime-client.d.ts +64 -2
- package/dist/runtime-client.js +277 -20
- package/dist/runtime-client.js.map +1 -1
- package/dist/runtime-coordinator.d.ts +10 -1
- package/dist/runtime-coordinator.js +93 -2
- package/dist/runtime-coordinator.js.map +1 -1
- package/dist/runtime-credential-profiles.d.ts +11 -2
- package/dist/runtime-credential-profiles.js +28 -4
- package/dist/runtime-credential-profiles.js.map +1 -1
- package/dist/runtime-install.js +9 -6
- package/dist/runtime-install.js.map +1 -1
- package/dist/runtime-pane-link.js +2 -1
- package/dist/runtime-pane-link.js.map +1 -1
- package/dist/runtime-pane-service.js +2 -2
- package/dist/runtime-pane-service.js.map +1 -1
- package/dist/runtime-pane-store.d.ts +10 -0
- package/dist/runtime-pane-store.js +13 -1
- package/dist/runtime-pane-store.js.map +1 -1
- package/dist/runtime-profile-ownership.d.ts +66 -0
- package/dist/runtime-profile-ownership.js +391 -0
- package/dist/runtime-profile-ownership.js.map +1 -0
- package/dist/runtime-protocol.d.ts +88 -2
- package/dist/runtime-protocol.js +40 -0
- package/dist/runtime-protocol.js.map +1 -1
- package/dist/runtime-remote-accounts.d.ts +197 -0
- package/dist/runtime-remote-accounts.js +663 -0
- package/dist/runtime-remote-accounts.js.map +1 -0
- package/dist/runtime-remote-setup.d.ts +105 -0
- package/dist/runtime-remote-setup.js +529 -0
- package/dist/runtime-remote-setup.js.map +1 -0
- package/dist/runtime-signin-transport.d.ts +39 -0
- package/dist/runtime-signin-transport.js +110 -0
- package/dist/runtime-signin-transport.js.map +1 -0
- package/dist/runtime-signin.d.ts +132 -0
- package/dist/runtime-signin.js +289 -0
- package/dist/runtime-signin.js.map +1 -0
- package/dist/runtime-update-attention.d.ts +4 -0
- package/dist/runtime-update-attention.js +11 -0
- package/dist/runtime-update-attention.js.map +1 -0
- package/dist/runtime-update-controller.d.ts +75 -0
- package/dist/runtime-update-controller.js +691 -0
- package/dist/runtime-update-controller.js.map +1 -0
- package/dist/runtime-update-ipc.d.ts +42 -0
- package/dist/runtime-update-ipc.js +144 -0
- package/dist/runtime-update-ipc.js.map +1 -0
- package/dist/runtime-update-journal.d.ts +5 -0
- package/dist/runtime-update-journal.js +7 -0
- package/dist/runtime-update-journal.js.map +1 -1
- package/dist/runtime-update-lock.js +17 -2
- package/dist/runtime-update-lock.js.map +1 -1
- package/dist/runtime-update-status.d.ts +30 -0
- package/dist/runtime-update-status.js +31 -0
- package/dist/runtime-update-status.js.map +1 -0
- package/dist/settings-api.js +3 -0
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-change.js +8 -0
- package/dist/settings-change.js.map +1 -1
- package/dist/settings-instance-patch.js +1 -1
- package/dist/settings-instance-patch.js.map +1 -1
- package/dist/setup-wizard.js +3 -5
- package/dist/setup-wizard.js.map +1 -1
- package/dist/signin-keepalive.d.ts +203 -0
- package/dist/signin-keepalive.js +652 -0
- package/dist/signin-keepalive.js.map +1 -0
- package/dist/structured-signin-transport.js +4 -0
- package/dist/structured-signin-transport.js.map +1 -1
- package/dist/structured-signin.d.ts +7 -0
- package/dist/structured-signin.js +1 -1
- package/dist/structured-signin.js.map +1 -1
- package/dist/tmux-binary.d.ts +23 -23
- package/dist/tmux-binary.js +35 -46
- package/dist/tmux-binary.js.map +1 -1
- package/dist/tmux-exec-helper.js +3 -3
- package/dist/tmux-exec-helper.js.map +1 -1
- package/dist/tmux-legacy.d.ts +94 -0
- package/dist/tmux-legacy.js +309 -0
- package/dist/tmux-legacy.js.map +1 -0
- package/dist/tmux-manager.d.ts +7 -1
- package/dist/tmux-manager.js +21 -11
- package/dist/tmux-manager.js.map +1 -1
- package/dist/tmux-rollback.d.ts +31 -0
- package/dist/tmux-rollback.js +72 -0
- package/dist/tmux-rollback.js.map +1 -0
- package/dist/tmux-server.d.ts +102 -0
- package/dist/tmux-server.js +248 -0
- package/dist/tmux-server.js.map +1 -0
- package/dist/transcript-monitor.js +43 -5
- package/dist/transcript-monitor.js.map +1 -1
- package/dist/transcript-records.d.ts +2 -1
- package/dist/transcript-records.js +3 -0
- package/dist/transcript-records.js.map +1 -1
- package/dist/transcript-sources.js +3 -0
- package/dist/transcript-sources.js.map +1 -1
- package/dist/types.d.ts +3 -0
- package/dist/ui/accounts-keepalive.js +112 -0
- package/dist/ui/accounts-manage.js +237 -0
- package/dist/ui/accounts-view.js +175 -31
- package/dist/ui/agent-runtime-settings.js +2 -1
- package/dist/ui/app.html +8 -1
- package/dist/ui/hub-attachments.js +90 -0
- package/dist/ui/hub-chat-store.js +9 -4
- package/dist/ui/hub-client.js +20 -1
- package/dist/ui/hub-preview.js +101 -0
- package/dist/ui/machine-signin.js +56 -0
- package/dist/ui/panel-fleet.js +1 -1
- package/dist/ui/panel-hub.js +126 -31
- package/dist/ui/panel-needs.js +14 -8
- package/dist/ui/panel-notices.js +4 -3
- package/dist/ui/panel-runtimes.js +19 -6
- package/dist/ui/panel-settings.js +12 -6
- package/dist/ui/panel-windows-agent.js +2 -1
- package/dist/ui/preview-pages.js +3 -41
- package/dist/ui/preview-panel-actions.js +3 -161
- package/dist/ui/preview-panel.js +10 -557
- package/dist/ui/preview-versions.js +3 -155
- package/dist/ui/runtime-cli-install.js +114 -0
- package/dist/ui/runtime-update-commands.d.ts +2 -0
- package/dist/ui/runtime-update-commands.js +11 -0
- package/dist/ui/runtime-update-status.js +53 -0
- package/dist/ui/search-dialog.js +3 -2
- package/dist/ui/settings-guests.js +3 -2
- package/dist/ui/settings-hub-browser-certificate.js +2 -0
- package/dist/ui/settings-hub-membership.js +12 -6
- package/dist/ui/settings-hub-retention.js +2 -0
- package/dist/ui/settings-hub.js +11 -3
- package/dist/ui/settings-quota-notice.js +100 -0
- package/dist/ui/settings-registry.js +1 -0
- package/dist/ui/settings-strings.js +2 -2
- package/dist/ui/settings-web-authority.js +2 -1
- package/dist/ui/shared/accounts-keepalive.css +7 -0
- package/dist/ui/shared/accounts.css +13 -0
- package/dist/ui/shared/app-route.js +1 -1
- package/dist/ui/shared/app-shell.js +9 -3
- package/dist/ui/shared/app-store.js +2 -2
- package/dist/ui/shared/app.css +13 -0
- package/dist/ui/shared/app.js +2 -1
- package/dist/ui/shared/hub-chat.css +1 -0
- package/dist/ui/shared/hub-owner.css +1 -1
- package/dist/ui/shared/loading.css +37 -0
- package/dist/ui/shared/preview-pages.js +41 -0
- package/dist/ui/shared/preview-panel-actions.js +168 -0
- package/dist/ui/shared/preview-panel.js +565 -0
- package/dist/ui/shared/preview-versions.js +155 -0
- package/dist/ui/shared/runtime-install.css +4 -0
- package/dist/ui/shared/signin.js +68 -6
- package/dist/ui/shared/ui-states.js +14 -3
- package/dist/ui/shared/workspace-follow.css +19 -0
- package/dist/ui/signin.html +7 -3
- package/dist/ui/structured-signin.js +31 -7
- package/dist/ui/workspace-follow-strings.js +28 -0
- package/dist/ui/workspace-panel.js +225 -36
- package/dist/update-install.d.ts +7 -0
- package/dist/update-install.js +23 -0
- package/dist/update-install.js.map +1 -1
- package/dist/usage/providers.d.ts +5 -0
- package/dist/usage/providers.js +5 -0
- package/dist/usage/providers.js.map +1 -1
- package/dist/usage/quota-notices.d.ts +38 -0
- package/dist/usage/quota-notices.js +160 -0
- package/dist/usage/quota-notices.js.map +1 -0
- package/dist/usage/usage-api.d.ts +1 -0
- package/dist/usage/usage-api.js +16 -0
- package/dist/usage/usage-api.js.map +1 -1
- package/dist/web-api.d.ts +33 -0
- package/dist/web-api.js +342 -8
- package/dist/web-api.js.map +1 -1
- package/dist/web-login.d.ts +35 -1
- package/dist/web-login.js +51 -5
- package/dist/web-login.js.map +1 -1
- package/dist/web-session.d.ts +11 -0
- package/dist/web-session.js +38 -1
- package/dist/web-session.js.map +1 -1
- package/dist/web-shell-routes.d.ts +1 -1
- package/dist/web-shell-routes.js +1 -1
- package/dist/web-shell-routes.js.map +1 -1
- package/dist/web-signin-link.d.ts +42 -0
- package/dist/web-signin-link.js +110 -0
- package/dist/web-signin-link.js.map +1 -0
- package/dist/windows-cli-api.d.ts +6 -0
- package/dist/windows-cli-api.js +11 -0
- package/dist/windows-cli-api.js.map +1 -1
- package/dist/windows-cli-worker.d.ts +3 -1
- package/dist/windows-cli-worker.js +18 -3
- package/dist/windows-cli-worker.js.map +1 -1
- package/dist/workspace-follow-parse.d.ts +36 -0
- package/dist/workspace-follow-parse.js +208 -0
- package/dist/workspace-follow-parse.js.map +1 -0
- package/dist/workspace-follow-records.d.ts +17 -0
- package/dist/workspace-follow-records.js +88 -0
- package/dist/workspace-follow-records.js.map +1 -0
- package/dist/workspace-follow.d.ts +41 -0
- package/dist/workspace-follow.js +143 -0
- package/dist/workspace-follow.js.map +1 -0
- package/dist/wsl-detect.d.ts +1 -0
- package/dist/wsl-detect.js +20 -0
- package/dist/wsl-detect.js.map +1 -0
- package/launcher/tmux-bundle.cjs +26 -10
- package/package.json +6 -2
- package/templates/runtime-install/install.ps1 +154 -13
|
@@ -0,0 +1,529 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3190 Part 3a: what a fleet admin may do to this Windows computer from the dashboard, and the record of it.
|
|
3
|
+
*
|
|
4
|
+
* Two switches, both OFF by default, set only on this computer (`agend-runtime remote-setup accounts|install on|off [--for 2h]`) and kept in
|
|
5
|
+
* this pairing's own folder. The server cannot change them: nothing in the protocol writes this file. A request that needs a switch is refused
|
|
6
|
+
* while it is off, with the command to run here. The switch may turn itself off after a time (`--for`); an expired switch is off.
|
|
7
|
+
*
|
|
8
|
+
* Every remote operation is recorded in `audit.jsonl` in the same folder: who (as the server names them), when, which operation, which
|
|
9
|
+
* profile, the outcome. The record is a CLOSED shape built field by field from checked values, so a URL, a sign-in code, CLI output, a folder
|
|
10
|
+
* listing or an e-mail address cannot get into it by accident.
|
|
11
|
+
*
|
|
12
|
+
* Built-ins only: part of the Runtime bundle.
|
|
13
|
+
*/
|
|
14
|
+
import { randomBytes } from "node:crypto";
|
|
15
|
+
import { closeSync, constants, existsSync, fstatSync, ftruncateSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, renameSync, unlinkSync, writeSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { atomicWriteFileSync } from "./atomic-write.js";
|
|
18
|
+
/** Capabilities a Runtime reports. A capability says the Runtime can do it; the switches say whether it may, right now. */
|
|
19
|
+
export const REMOTE_SIGNIN_CAPABILITY = "remote-signin";
|
|
20
|
+
export const CLI_INSTALL_CAPABILITY = "cli-install";
|
|
21
|
+
export const REMOTE_SWITCHES = ["accounts", "install"];
|
|
22
|
+
export const REMOTE_SETUP_FILE = "remote-setup.json";
|
|
23
|
+
export const AUDIT_FILE = "audit.jsonl";
|
|
24
|
+
/** A switch left on is a standing offer to the fleet: it can be timed, and a timed one is bounded. */
|
|
25
|
+
export const MIN_SWITCH_MS = 60_000;
|
|
26
|
+
export const MAX_SWITCH_MS = 7 * 24 * 3_600_000;
|
|
27
|
+
const MAX_AUDIT_BYTES = 1024 * 1024;
|
|
28
|
+
/** Rotated copies kept besides the current file (`audit.jsonl.1` is the newest). */
|
|
29
|
+
export const AUDIT_KEEP = 5;
|
|
30
|
+
export function isRemoteSwitchName(value) {
|
|
31
|
+
return typeof value === "string" && REMOTE_SWITCHES.includes(value);
|
|
32
|
+
}
|
|
33
|
+
/** The command that turns a switch on, for a refusal. */
|
|
34
|
+
export function remoteSwitchCommand(name) { return `agend-runtime remote-setup ${name} on [--for 2h]`; }
|
|
35
|
+
/** A refusal whose text is ours and safe to show anywhere: it names a switch and a command, never a path, an account or a secret. */
|
|
36
|
+
export class RemoteSetupRefusal extends Error {
|
|
37
|
+
reason;
|
|
38
|
+
constructor(message, reason) {
|
|
39
|
+
super(message);
|
|
40
|
+
this.reason = reason;
|
|
41
|
+
this.name = "RemoteSetupRefusal";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** `2h`, `90m` or a bare number of hours. Bounded; anything else is an error, never "cleaned up". */
|
|
45
|
+
export function parseSwitchDuration(text) {
|
|
46
|
+
const match = /^(\d{1,4}(?:\.\d{1,2})?)(h|m)?$/.exec(text.trim());
|
|
47
|
+
if (!match)
|
|
48
|
+
throw new Error("Use --for with a time such as 2h, 90m or 0.5h");
|
|
49
|
+
const ms = Math.round(Number(match[1]) * (match[2] === "m" ? 60_000 : 3_600_000));
|
|
50
|
+
if (!Number.isFinite(ms) || ms < MIN_SWITCH_MS || ms > MAX_SWITCH_MS)
|
|
51
|
+
throw new Error("--for must be between 1 minute and 168 hours (7 days)");
|
|
52
|
+
return ms;
|
|
53
|
+
}
|
|
54
|
+
function readPrivateJson(path, limit) {
|
|
55
|
+
const stat = lstatSync(path);
|
|
56
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > limit)
|
|
57
|
+
throw new Error("Unsafe remote-setup file");
|
|
58
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
59
|
+
}
|
|
60
|
+
const off = () => ({ accounts: { on: false }, install: { on: false } });
|
|
61
|
+
/** The switches as they stand now. Fail closed: a missing, unreadable or malformed file is "both off"; an expired switch is off. */
|
|
62
|
+
export function readRemoteSwitches(directory, now = Date.now()) {
|
|
63
|
+
const result = off();
|
|
64
|
+
let value;
|
|
65
|
+
try {
|
|
66
|
+
value = readPrivateJson(join(directory, REMOTE_SETUP_FILE), 4096);
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || value.version !== 1)
|
|
72
|
+
return result;
|
|
73
|
+
for (const name of REMOTE_SWITCHES) {
|
|
74
|
+
const row = value[name];
|
|
75
|
+
if (!row || typeof row !== "object" || Array.isArray(row) || row.on !== true)
|
|
76
|
+
continue;
|
|
77
|
+
const until = row.until;
|
|
78
|
+
if (until === undefined) {
|
|
79
|
+
result[name] = { on: true };
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
// A timed switch never reaches further than the longest a person can set it for: a clock that was moved back, or a hand-written huge
|
|
83
|
+
// value, would otherwise bring an expired switch back to life.
|
|
84
|
+
if (typeof until === "number" && Number.isFinite(until) && until > now && until - now <= MAX_SWITCH_MS)
|
|
85
|
+
result[name] = { on: true, until };
|
|
86
|
+
}
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
export function remoteSwitchOn(directory, name, now = Date.now()) { return readRemoteSwitches(directory, now)[name].on; }
|
|
90
|
+
/** Local administrator only: nothing in the Runtime protocol calls this. */
|
|
91
|
+
export function setRemoteSwitch(directory, name, on, forMs, now = Date.now()) {
|
|
92
|
+
if (!isRemoteSwitchName(name))
|
|
93
|
+
throw new Error("Unknown remote-setup switch");
|
|
94
|
+
if (forMs !== undefined && (!on || !Number.isFinite(forMs) || forMs < MIN_SWITCH_MS || forMs > MAX_SWITCH_MS))
|
|
95
|
+
throw new Error("--for applies only when turning a switch on, and must be between 1 minute and 168 hours");
|
|
96
|
+
const current = readRemoteSwitches(directory, now), next = on ? { on: true, ...(forMs !== undefined ? { until: now + forMs } : {}) } : { on: false };
|
|
97
|
+
const file = { version: 1 };
|
|
98
|
+
for (const other of REMOTE_SWITCHES) {
|
|
99
|
+
const state = other === name ? next : current[other];
|
|
100
|
+
file[other] = state.on ? { on: true, ...(state.until !== undefined ? { until: state.until } : {}) } : { on: false };
|
|
101
|
+
}
|
|
102
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
103
|
+
atomicWriteFileSync(join(directory, REMOTE_SETUP_FILE), JSON.stringify(file), { mode: 0o600 });
|
|
104
|
+
return next;
|
|
105
|
+
}
|
|
106
|
+
/** Throws the refusal (with the command to run) while a switch is off. */
|
|
107
|
+
export function requireRemoteSwitch(directory, name, now = Date.now()) {
|
|
108
|
+
if (!remoteSwitchOn(directory, name, now))
|
|
109
|
+
throw new RemoteSetupRefusal(`This computer has "${name}" turned off. On this computer run: ${remoteSwitchCommand(name)}`, "switch_off");
|
|
110
|
+
}
|
|
111
|
+
/** A one-line status for `remote-setup status` and the Runtime's report. */
|
|
112
|
+
export function describeRemoteSwitches(switches, now = Date.now()) {
|
|
113
|
+
return REMOTE_SWITCHES.map(name => {
|
|
114
|
+
const state = switches[name];
|
|
115
|
+
return `${name}: ${state.on ? `on${state.until !== undefined ? ` (turns off in ${Math.max(1, Math.round((state.until - now) / 60_000))} min)` : ""}` : "off"}`;
|
|
116
|
+
}).join("\n");
|
|
117
|
+
}
|
|
118
|
+
/** Closed vocabulary of the audit record. Free text has no field here. */
|
|
119
|
+
export const AUDIT_ACTIONS = ["switch", "profile.add", "signin", "signin.write", "profile.signout", "profile.remove", "cli.install"];
|
|
120
|
+
export const AUDIT_OUTCOMES = ["started", "ok", "refused", "failed"];
|
|
121
|
+
export const AUDIT_REASONS = ["switch_off", "invalid_request", "busy", "not_found", "not_owned", "in_use", "default_profile", "link", "unsupported", "unconfirmed", "timeout", "rate_limited", "failed"];
|
|
122
|
+
/** What the dashboard may call a person in the record: a name or an id, not an address and not free text. */
|
|
123
|
+
export const AUDIT_ACTOR = /^[A-Za-z0-9._:-]{1,64}$/;
|
|
124
|
+
const AUDIT_DETAIL = /^(?:on|off|expired|\d{1,4}\.\d{1,4}\.\d{1,4}(?:[-+][A-Za-z0-9.-]{1,32})?)$/;
|
|
125
|
+
const AUDIT_SINCE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
126
|
+
const AUDIT_CLI = /^[a-z][a-z0-9-]{0,31}$/;
|
|
127
|
+
const AUDIT_PROFILE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
128
|
+
export function validAuditActor(value) { return typeof value === "string" && AUDIT_ACTOR.test(value); }
|
|
129
|
+
/** One line, built from checked fields only. Throws on a field that does not fit, which refuses the operation that was about to be recorded. */
|
|
130
|
+
export function formatAuditLine(entry, now = Date.now()) {
|
|
131
|
+
if (!validAuditActor(entry.actor) || !AUDIT_ACTIONS.includes(entry.action) || !AUDIT_OUTCOMES.includes(entry.outcome)
|
|
132
|
+
|| entry.cli !== undefined && !AUDIT_CLI.test(entry.cli) || entry.profile !== undefined && !AUDIT_PROFILE.test(entry.profile)
|
|
133
|
+
|| entry.detail !== undefined && !AUDIT_DETAIL.test(entry.detail) || entry.repeated !== undefined && (!Number.isSafeInteger(entry.repeated) || entry.repeated < 2 || entry.repeated > 1_000_000_000) || entry.since !== undefined && (entry.repeated === undefined || !AUDIT_SINCE.test(entry.since))
|
|
134
|
+
|| entry.switch !== undefined && (entry.action !== "switch" || !isRemoteSwitchName(entry.switch)) || entry.until !== undefined && (entry.action !== "switch" || !AUDIT_SINCE.test(entry.until)) || entry.reason !== undefined && !AUDIT_REASONS.includes(entry.reason))
|
|
135
|
+
throw new Error("Audit entry is not in its closed form");
|
|
136
|
+
return `${JSON.stringify({ at: new Date(now).toISOString(), actor: entry.actor, action: entry.action, outcome: entry.outcome,
|
|
137
|
+
...(entry.cli !== undefined ? { cli: entry.cli } : {}), ...(entry.profile !== undefined ? { profile: entry.profile } : {}),
|
|
138
|
+
...(entry.detail !== undefined ? { detail: entry.detail } : {}), ...(entry.reason !== undefined ? { reason: entry.reason } : {}),
|
|
139
|
+
...(entry.repeated !== undefined ? { repeated: entry.repeated } : {}), ...(entry.since !== undefined ? { since: entry.since } : {}),
|
|
140
|
+
...(entry.switch !== undefined ? { switch: entry.switch } : {}), ...(entry.until !== undefined ? { until: entry.until } : {}) })}\n`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Lock file of the audit log, in the pairing folder. Every supported writer (the Runtime, `agend-runtime remote-setup`, a second Runtime) takes it, and holds
|
|
144
|
+
* it for the whole of: rotation, the look at the end of the log, the repair, the write, and the taking back of a failed write. Nothing destructive is done to
|
|
145
|
+
* the log without it, and a writer that finds it no longer owns it stops there.
|
|
146
|
+
*/
|
|
147
|
+
export const AUDIT_LOCK_FILE = "audit.lock";
|
|
148
|
+
/** Held while one writer takes over the lock of a process that is gone. At most one takeover at a time. */
|
|
149
|
+
const AUDIT_RECLAIM_FILE = `${AUDIT_LOCK_FILE}.reclaim`;
|
|
150
|
+
/** How long a writer waits for the one before it (it then refuses: it never touches the log without the lock). Tests lower it. */
|
|
151
|
+
export const auditLockTiming = { waitMs: 3_000 };
|
|
152
|
+
const heldAuditLocks = new Set(); // tokens of the lock files (the lock, or the takeover guard) this process holds right now
|
|
153
|
+
const pause = (ms) => { Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms); };
|
|
154
|
+
const AUDIT_BUSY = `Audit log is busy (another process is writing it, or ${AUDIT_LOCK_FILE} or ${AUDIT_LOCK_FILE}.reclaim in this folder was left behind and needs a look on this computer): nothing was written; try again`;
|
|
155
|
+
function processAlive(pid) { try {
|
|
156
|
+
process.kill(pid, 0);
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
return error.code === "EPERM";
|
|
161
|
+
} }
|
|
162
|
+
function parseAuditLockOwner(raw) {
|
|
163
|
+
try {
|
|
164
|
+
const parsed = JSON.parse(raw);
|
|
165
|
+
return parsed && typeof parsed.pid === "number" && Number.isSafeInteger(parsed.pid) && parsed.pid > 0 && typeof parsed.token === "string" && /^[0-9a-f]{16}$/.test(parsed.token) ? { pid: parsed.pid, token: parsed.token } : "unreadable";
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
return "unreadable";
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function snapshotAuditLock(path) {
|
|
172
|
+
let stat;
|
|
173
|
+
try {
|
|
174
|
+
stat = lstatSync(path);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if (error.code === "ENOENT")
|
|
178
|
+
return "gone";
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
if (!stat.isFile())
|
|
182
|
+
throw new Error("Audit lock must be a regular file");
|
|
183
|
+
let raw = "";
|
|
184
|
+
try {
|
|
185
|
+
raw = readFileSync(path, "utf8");
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
if (error.code === "ENOENT")
|
|
189
|
+
return "gone";
|
|
190
|
+
}
|
|
191
|
+
return { dev: stat.dev, ino: stat.ino, size: stat.size, mtimeMs: stat.mtimeMs, raw, owner: parseAuditLockOwner(raw) };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* A lock nobody is using any more: it names an owner (pid and token, readable), and that process is gone, or it is this process's pid with a token this process
|
|
195
|
+
* does not hold (a pid that was reused). Nothing else is ever stale: a live owner's lock, and a lock that holds nothing readable, however old. The creator of an
|
|
196
|
+
* empty lock may only be slow (between creating the file and writing its owner into it), and age does not show that it is gone; it is waited for, and when the wait
|
|
197
|
+
* runs out the writer refuses and the file is left for someone to look at on this computer.
|
|
198
|
+
*/
|
|
199
|
+
function auditLockIsStale(lock) {
|
|
200
|
+
return lock.owner !== "unreadable" && !heldAuditLocks.has(lock.owner.token) && (lock.owner.pid === process.pid || !processAlive(lock.owner.pid));
|
|
201
|
+
}
|
|
202
|
+
/** The very file that was looked at: same device and inode, same bytes. */
|
|
203
|
+
function sameAuditLockFile(before, after) {
|
|
204
|
+
return after !== "gone" && after.dev === before.dev && after.ino === before.ino && after.size === before.size && after.raw === before.raw;
|
|
205
|
+
}
|
|
206
|
+
/** Creates a lock file exclusively (`O_EXCL`). Returns which file it is, or undefined when one is already there. */
|
|
207
|
+
function createAuditLockFile(path, token) {
|
|
208
|
+
let fd;
|
|
209
|
+
try {
|
|
210
|
+
fd = openSync(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, 0o600);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
if (error.code === "EEXIST")
|
|
214
|
+
return undefined;
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
writeSync(fd, JSON.stringify({ pid: process.pid, token }));
|
|
219
|
+
const stat = fstatSync(fd);
|
|
220
|
+
return { dev: stat.dev, ino: stat.ino };
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
try {
|
|
224
|
+
unlinkSync(path);
|
|
225
|
+
}
|
|
226
|
+
catch { /* nothing else can be done */ }
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
229
|
+
finally {
|
|
230
|
+
closeSync(fd);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** Removes a lock file only if it is still the one that was made: ours by token and by file. */
|
|
234
|
+
function removeAuditLockFile(path, token, identity) {
|
|
235
|
+
for (let attempt = 0; attempt < 5; attempt++) {
|
|
236
|
+
try {
|
|
237
|
+
const lock = snapshotAuditLock(path);
|
|
238
|
+
if (lock === "gone" || lock.owner === "unreadable" || lock.owner.token !== token || (identity !== undefined && (lock.dev !== identity.dev || lock.ino !== identity.ino)))
|
|
239
|
+
return;
|
|
240
|
+
unlinkSync(path);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
if (error.code === "ENOENT")
|
|
245
|
+
return;
|
|
246
|
+
pause(10);
|
|
247
|
+
} // a handle another process holds for a moment (Windows)
|
|
248
|
+
}
|
|
249
|
+
// Still there: it is ours, so the next writer of this process clears it (same pid, token not held) and another process waits until this one ends.
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Takes over the lock of a process that is gone, and only that: the lock names its owner, and that process is gone. Only one taker at a time, and only without
|
|
253
|
+
* contention: it creates the reclaim file exclusively and removes only that file, by token and identity; a reclaim file that is already there is never touched
|
|
254
|
+
* (its taker may be alive, or it was left behind by one that died: either way it is left for someone to look at, and writers wait and then refuse). Under it the
|
|
255
|
+
* lock file is looked at again: it must still be the very file that was seen to be stale (same inode, same bytes) and stale. The new lock is written whole to a
|
|
256
|
+
* file of its own and renamed over the old one, so there is never a moment without a lock. If the rename fails the takeover fails: the lock file is never
|
|
257
|
+
* unlinked here, since a writer that is about to create it would own the path in the gap before the rename. Anything uncertain: no takeover (the caller
|
|
258
|
+
* waits, and refuses when the wait runs out).
|
|
259
|
+
*/
|
|
260
|
+
function takeOverAuditLock(directory, path, reclaimPath, token, seen) {
|
|
261
|
+
const claimed = createAuditLockFile(reclaimPath, token);
|
|
262
|
+
if (!claimed)
|
|
263
|
+
return undefined; // another taker is at it, or left it behind: not ours to touch
|
|
264
|
+
heldAuditLocks.add(token);
|
|
265
|
+
const next = join(directory, `${AUDIT_LOCK_FILE}.next-${token}`);
|
|
266
|
+
let staged = false, taken = false;
|
|
267
|
+
try {
|
|
268
|
+
const now = snapshotAuditLock(path);
|
|
269
|
+
if (now === "gone" || !sameAuditLockFile(seen, now) || !auditLockIsStale(now))
|
|
270
|
+
return undefined;
|
|
271
|
+
if (!createAuditLockFile(next, token))
|
|
272
|
+
return undefined;
|
|
273
|
+
staged = true;
|
|
274
|
+
if (!sameAuditLockFile(seen, snapshotAuditLock(path)))
|
|
275
|
+
return undefined;
|
|
276
|
+
renameSync(next, path);
|
|
277
|
+
staged = false;
|
|
278
|
+
const mine = snapshotAuditLock(path);
|
|
279
|
+
if (mine === "gone" || mine.owner === "unreadable" || mine.owner.token !== token)
|
|
280
|
+
return undefined;
|
|
281
|
+
taken = true;
|
|
282
|
+
return { dev: mine.dev, ino: mine.ino };
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
finally {
|
|
288
|
+
if (staged) {
|
|
289
|
+
try {
|
|
290
|
+
unlinkSync(next);
|
|
291
|
+
}
|
|
292
|
+
catch { /* left behind: it holds nothing but a token */ }
|
|
293
|
+
}
|
|
294
|
+
removeAuditLockFile(reclaimPath, token, claimed);
|
|
295
|
+
if (!taken)
|
|
296
|
+
heldAuditLocks.delete(token);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Takes the audit lock: a file created exclusively (`O_EXCL`) that holds this process's pid and a token of its own. A lock held by a live process is waited
|
|
301
|
+
* for, and when the wait runs out this THROWS: a writer that cannot have the lock never looks at the log, never repairs it and never cuts it. A lock whose
|
|
302
|
+
* process is gone is taken over (`takeOverAuditLock`).
|
|
303
|
+
*/
|
|
304
|
+
function acquireAuditLock(directory) {
|
|
305
|
+
const path = join(directory, AUDIT_LOCK_FILE), reclaimPath = join(directory, AUDIT_RECLAIM_FILE), token = randomBytes(8).toString("hex"), deadline = Date.now() + auditLockTiming.waitMs;
|
|
306
|
+
const wait = () => { if (Date.now() >= deadline)
|
|
307
|
+
throw new Error(AUDIT_BUSY); pause(10); };
|
|
308
|
+
const owned = (identity) => {
|
|
309
|
+
heldAuditLocks.add(token);
|
|
310
|
+
return {
|
|
311
|
+
release: () => { heldAuditLocks.delete(token); removeAuditLockFile(path, token, identity); },
|
|
312
|
+
assertOwned: () => {
|
|
313
|
+
const lock = snapshotAuditLock(path);
|
|
314
|
+
if (!heldAuditLocks.has(token) || lock === "gone" || lock.owner === "unreadable" || lock.owner.token !== token || lock.dev !== identity.dev || lock.ino !== identity.ino)
|
|
315
|
+
throw new Error("Audit log lock was lost (it was cleared or replaced while this writer held it): nothing more was done; try again");
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
for (;;) {
|
|
320
|
+
if (snapshotAuditLock(reclaimPath) !== "gone") {
|
|
321
|
+
wait();
|
|
322
|
+
continue;
|
|
323
|
+
} // a takeover is under way, or was left behind: nobody creates or takes over in the middle of it, and nothing here removes it (a link or a folder is refused)
|
|
324
|
+
const made = createAuditLockFile(path, token);
|
|
325
|
+
if (made)
|
|
326
|
+
return owned(made);
|
|
327
|
+
const seen = snapshotAuditLock(path);
|
|
328
|
+
if (seen === "gone") {
|
|
329
|
+
wait();
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (auditLockIsStale(seen)) {
|
|
333
|
+
const taken = takeOverAuditLock(directory, path, reclaimPath, token, seen);
|
|
334
|
+
if (taken)
|
|
335
|
+
return owned(taken);
|
|
336
|
+
}
|
|
337
|
+
wait();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Appends to `<pairing folder>\audit.jsonl` (private; a link is refused; five rotated copies, each up to about 1 MiB). Throws when it cannot write: a remote
|
|
342
|
+
* operation whose record cannot be kept does not run. The whole of it (rotation, the look at the end of the log, the repair, the write, the taking back of a
|
|
343
|
+
* failed write) runs under the audit lock, so two writers (the Runtime and `agend-runtime remote-setup`, two Runtimes) never repair, cut and write at once.
|
|
344
|
+
*/
|
|
345
|
+
export function appendAudit(directory, entry, now = Date.now()) {
|
|
346
|
+
const line = formatAuditLine(entry, now), path = join(directory, AUDIT_FILE);
|
|
347
|
+
mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
348
|
+
const lock = acquireAuditLock(directory);
|
|
349
|
+
try {
|
|
350
|
+
appendLocked(path, line, lock.assertOwned);
|
|
351
|
+
}
|
|
352
|
+
finally {
|
|
353
|
+
lock.release();
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function appendLocked(path, line, assertOwned) {
|
|
357
|
+
try {
|
|
358
|
+
const stat = lstatSync(path);
|
|
359
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
360
|
+
throw new Error("Audit log must be a regular file");
|
|
361
|
+
if (stat.size > MAX_AUDIT_BYTES) {
|
|
362
|
+
assertOwned();
|
|
363
|
+
// .4 -> .5, ... , .1 -> .2, current -> .1; the oldest copy goes.
|
|
364
|
+
for (let index = AUDIT_KEEP; index >= 2; index--) {
|
|
365
|
+
const from = `${path}.${index - 1}`;
|
|
366
|
+
if (existsSync(from))
|
|
367
|
+
renameSync(from, `${path}.${index}`);
|
|
368
|
+
}
|
|
369
|
+
renameSync(path, `${path}.1`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
catch (error) {
|
|
373
|
+
if (error.code !== "ENOENT")
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
376
|
+
// Two handles on the one file. `rw` (read and write, no append flag) looks at the end of the file and repairs or cuts it: on Windows a handle opened for
|
|
377
|
+
// append has no right to truncate. `app` (append only) writes the record, so what it writes is only ever added at the end of the file.
|
|
378
|
+
const rw = openSync(path, constants.O_RDWR | constants.O_CREAT, 0o600);
|
|
379
|
+
try {
|
|
380
|
+
const app = openSync(path, constants.O_WRONLY | constants.O_APPEND, 0o600);
|
|
381
|
+
try {
|
|
382
|
+
const one = fstatSync(rw), two = fstatSync(app);
|
|
383
|
+
if (!one.isFile() || !two.isFile() || one.dev !== two.dev || one.ino !== two.ino)
|
|
384
|
+
throw new Error("Audit log must be a regular file");
|
|
385
|
+
const valid = repairedEnd(rw, assertOwned);
|
|
386
|
+
assertOwned(); // the write itself: only while the lock is still ours
|
|
387
|
+
// A record is whole or it is an error: a partial write (a full disk, an interrupted call) is never accepted as written, and what was written of it is taken back.
|
|
388
|
+
const bytes = Buffer.from(line, "utf8");
|
|
389
|
+
let done = 0;
|
|
390
|
+
try {
|
|
391
|
+
while (done < bytes.byteLength) {
|
|
392
|
+
const wrote = writeSync(app, bytes, done, bytes.byteLength - done);
|
|
393
|
+
if (!(wrote > 0))
|
|
394
|
+
throw new Error("Audit log write was incomplete");
|
|
395
|
+
done += wrote;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
catch (error) {
|
|
399
|
+
// Cut our part off again, but only if the file is exactly what it was after our part went in (the same length and our bytes where our part is, looked at
|
|
400
|
+
// before and after) AND the lock is still ours, checked last, right before the cut. If either does not hold, nothing here is ours to cut: whatever another writer
|
|
401
|
+
// committed stays, and this write still fails with its own error, so the operation that needed this record is not admitted.
|
|
402
|
+
try {
|
|
403
|
+
if (done > 0 && stillExactly(rw, valid + done, valid, bytes.subarray(0, done))) {
|
|
404
|
+
assertOwned();
|
|
405
|
+
ftruncateSync(rw, valid);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
catch { /* the next append finds the incomplete tail and repairs it, or refuses */ }
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
finally {
|
|
413
|
+
closeSync(app);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
finally {
|
|
417
|
+
closeSync(rw);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
const AUDIT_PREFIX = '{"at":"';
|
|
421
|
+
/** The file is exactly `size` bytes and holds `expected` at `from`: a snapshot looked at before and after reading it, so a writer that changed the file meanwhile (its length, or the bytes at the cut) is seen. */
|
|
422
|
+
function stillExactly(fd, size, from, expected) {
|
|
423
|
+
if (fstatSync(fd).size !== size)
|
|
424
|
+
return false;
|
|
425
|
+
const buffer = Buffer.alloc(expected.length), read = readSync(fd, buffer, 0, buffer.length, from);
|
|
426
|
+
return read === expected.length && buffer.equals(expected) && fstatSync(fd).size === size;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* The end of the last WHOLE record, after repairing what an interrupted write left: a tail without its newline is the front of a record that was never
|
|
430
|
+
* completed. If it is the front of one of ours (it begins the way every record begins, and stays unchanged for a moment, so a record another process is
|
|
431
|
+
* writing right now is not mistaken for it) it is cut off; anything else, or a last whole line that is not JSON, is damage this code does not guess about:
|
|
432
|
+
* it refuses (so no operation that needs its record goes ahead on an unreadable log). The cut is made only on a snapshot nobody has changed (`stillExactly`)
|
|
433
|
+
* and only while the lock is still this writer's (`assertOwned`, the last thing before the cut, which throws when it is not): if a writer has completed or
|
|
434
|
+
* replaced that tail meanwhile the end is looked at again, and what that writer committed is never cut.
|
|
435
|
+
*/
|
|
436
|
+
function repairedEnd(fd, assertOwned) {
|
|
437
|
+
for (let round = 0; round < 32; round++) {
|
|
438
|
+
const size = fstatSync(fd).size;
|
|
439
|
+
if (size === 0)
|
|
440
|
+
return 0;
|
|
441
|
+
const start = Math.max(0, size - 16 * 1024), raw = Buffer.alloc(size - start);
|
|
442
|
+
readSync(fd, raw, 0, raw.length, start);
|
|
443
|
+
if (raw[raw.length - 1] !== 0x0a) {
|
|
444
|
+
const newline = raw.lastIndexOf(0x0a), cut = start + newline + 1;
|
|
445
|
+
if (newline < 0 && start > 0)
|
|
446
|
+
throw new Error("Audit log has an unreadable tail; repair or remove it on this computer");
|
|
447
|
+
const tailBytes = raw.subarray(newline + 1), tail = tailBytes.toString("utf8");
|
|
448
|
+
if (!(AUDIT_PREFIX.startsWith(tail) || tail.startsWith(AUDIT_PREFIX)))
|
|
449
|
+
throw new Error("Audit log has an unreadable tail; repair or remove it on this computer");
|
|
450
|
+
pause(25); // looked at again after a moment: it must be the same bytes
|
|
451
|
+
if (!stillExactly(fd, size, cut, tailBytes))
|
|
452
|
+
continue;
|
|
453
|
+
assertOwned();
|
|
454
|
+
ftruncateSync(fd, cut);
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
const lines = raw.toString("utf8").split("\n").filter(line => line.trim()), last = lines[lines.length - 1];
|
|
458
|
+
if (last !== undefined && !(start > 0 && lines.length === 1)) {
|
|
459
|
+
let parsed;
|
|
460
|
+
try {
|
|
461
|
+
parsed = JSON.parse(last);
|
|
462
|
+
}
|
|
463
|
+
catch {
|
|
464
|
+
throw new Error("Audit log has an unreadable last record; repair or remove it on this computer");
|
|
465
|
+
}
|
|
466
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
467
|
+
throw new Error("Audit log has an unreadable last record; repair or remove it on this computer");
|
|
468
|
+
}
|
|
469
|
+
return size;
|
|
470
|
+
}
|
|
471
|
+
throw new Error("Audit log keeps changing while it is being read; nothing was written; try again");
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* The record of one Runtime process, with the refusals folded together.
|
|
475
|
+
*
|
|
476
|
+
* A refusal costs the asker nothing, and the one who asks is whoever the server says (a compromised server is the threat model), so an unbounded
|
|
477
|
+
* stream of them could push the real operations out of a rotating file. So: a `refused` entry that repeats within a minute is not written again; it is
|
|
478
|
+
* counted, and the count goes out with the next entry of its kind (or with the next non-refused entry, or at `flush`). The folding key is the
|
|
479
|
+
* action and the reason ONLY. It must not hold the actor, the profile or the CLI, which the server chooses freely: a new name per request would
|
|
480
|
+
* defeat it. What is never folded: `started`, `ok` and `failed` entries and the switch changes, which only a real operation can produce. A refusal is
|
|
481
|
+
* only ever the answer to a request that changed nothing, so every check that can refuse without changing anything has to run BEFORE `started` is
|
|
482
|
+
* written (RemoteAccounts does). Therefore the most refusals can write is one line per (action, reason) pair per minute. The line of a folded run carries
|
|
483
|
+
* the actor, profile and CLI of the FIRST request of that run; `repeated` counts requests that may have named others.
|
|
484
|
+
*/
|
|
485
|
+
export const AUDIT_FOLD_MS = 60_000;
|
|
486
|
+
export class AuditLog {
|
|
487
|
+
directory;
|
|
488
|
+
now;
|
|
489
|
+
folded = new Map();
|
|
490
|
+
constructor(directory, now = Date.now) {
|
|
491
|
+
this.directory = directory;
|
|
492
|
+
this.now = now;
|
|
493
|
+
}
|
|
494
|
+
/** Throws when the line cannot be written (the caller decides whether that stops its operation). */
|
|
495
|
+
append(entry) {
|
|
496
|
+
const now = this.now();
|
|
497
|
+
// A real operation is about to start: the counts of what was folded so far go out first. Nothing else flushes: an `ok`, a `failed` or a refusal
|
|
498
|
+
// must not make every request write twice, which would undo the folding.
|
|
499
|
+
if (entry.outcome === "started")
|
|
500
|
+
this.flush();
|
|
501
|
+
if (entry.outcome !== "refused") {
|
|
502
|
+
appendAudit(this.directory, entry, now);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const key = `${entry.action}\u0000${entry.reason ?? ""}`, seen = this.folded.get(key);
|
|
506
|
+
if (seen && now - seen.since < AUDIT_FOLD_MS) {
|
|
507
|
+
seen.suppressed++;
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
appendAudit(this.directory, { ...entry, ...(seen && seen.suppressed + 1 >= 2 ? { repeated: seen.suppressed + 1, since: new Date(seen.since).toISOString() } : {}) }, now);
|
|
511
|
+
this.folded.set(key, { since: now, suppressed: 0, entry });
|
|
512
|
+
}
|
|
513
|
+
/** Writes what was folded and not yet written (best effort), so no count is lost when a process ends. */
|
|
514
|
+
flush() {
|
|
515
|
+
const now = this.now();
|
|
516
|
+
for (const [key, seen] of [...this.folded]) {
|
|
517
|
+
if (!seen.suppressed)
|
|
518
|
+
continue;
|
|
519
|
+
try {
|
|
520
|
+
appendAudit(this.directory, { ...seen.entry, ...(seen.suppressed >= 2 ? { repeated: seen.suppressed, since: new Date(seen.since).toISOString() } : {}) }, now);
|
|
521
|
+
seen.suppressed = 0;
|
|
522
|
+
seen.since = now;
|
|
523
|
+
}
|
|
524
|
+
catch { /* kept for the next flush */ }
|
|
525
|
+
this.folded.set(key, seen);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
//# s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EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;gBAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC;gBAAC,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC,CAAC,6BAA6B,CAAC,CAAC;YACtP,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3190 Part 3c: the server's side of a sign-in on a paired computer. It implements `StructuredSignInTransport` (the one sign-in implementation, structured-signin.ts)
|
|
3
|
+
* for ONE computer and ONE credential profile, over the existing authenticated Runtime connection, in `account.request` frames (never `request`: the
|
|
4
|
+
* coordinator journals every `request`, and a sign-in link or code must not reach the disk).
|
|
5
|
+
*
|
|
6
|
+
* - `start(spec)`: `spec.argv` is mapped to a CLI id by EXACT match against a closed table, and only `{cli, profile, method, actor}` is sent. The server never
|
|
7
|
+
* sends an argv, a command, a path or an environment, and the profile is a NAME. A re-login ("logout first") is refused: signing out is its own, confirmed operation.
|
|
8
|
+
* - `capture()`: the Runtime's reduced screen, read through the same closed table once more here, so a line outside it (an e-mail address in a success line)
|
|
9
|
+
* cannot reach the sign-in view even from a Runtime that did not reduce it.
|
|
10
|
+
* - `write(input)`: the driver's own rule again (printable ASCII, a code's characters, one line) before it is sent.
|
|
11
|
+
* - `close()`: ends exactly the sign-in this transport started and answers only when the Runtime says it is gone (or that it is no longer running).
|
|
12
|
+
* - `checkAuth` (`runtimeCheckAuth`): the CLI's own `auth status` for that profile on the computer, as a masked identity; text alone is never success.
|
|
13
|
+
*
|
|
14
|
+
* Nothing from a reply is logged here, and errors are fixed words: a URL, a code, output or an e-mail address cannot travel in one.
|
|
15
|
+
*/
|
|
16
|
+
import type { StructuredSignInTransport } from "./structured-signin.js";
|
|
17
|
+
import type { AuthCheckResult } from "./login-flows.js";
|
|
18
|
+
import { type AccountIdentity } from "./claude-auth-status.js";
|
|
19
|
+
import type { RuntimeRemoteOperation, RuntimeRemotePayloads } from "./runtime-protocol.js";
|
|
20
|
+
/** Sends one `account.request` to a computer (`RuntimeCoordinator.callAccount`) and gives back its reply. */
|
|
21
|
+
export type AccountCaller = <K extends RuntimeRemoteOperation>(machineId: string, operation: K, payload: RuntimeRemotePayloads[K], timeoutMs?: number) => Promise<unknown>;
|
|
22
|
+
/** The sign-ins a computer can run for the dashboard: the CLI's id, and the exact argv `StructuredSignIn` launches for it. Only subscription sign-ins (the Runtime refuses Console). */
|
|
23
|
+
export declare const RUNTIME_SIGNIN_CLIS: Readonly<Record<string, readonly string[]>>;
|
|
24
|
+
/** What the Runtime says for a profile folder it does not have yet (a new account is created by its first sign-in): not signed in, not an error. */
|
|
25
|
+
export declare const PROFILE_DOES_NOT_EXIST: RegExp;
|
|
26
|
+
export interface RuntimeSignInTransportOptions {
|
|
27
|
+
machineId: string;
|
|
28
|
+
/** The credential profile NAME on that computer. */
|
|
29
|
+
profile: string;
|
|
30
|
+
/** The name the computer's audit log records for the person who asked (`admin:<handle>`). */
|
|
31
|
+
actor: string;
|
|
32
|
+
call: AccountCaller;
|
|
33
|
+
}
|
|
34
|
+
export declare function createRuntimeSignInTransport(options: RuntimeSignInTransportOptions): StructuredSignInTransport;
|
|
35
|
+
/** The CLI's own `auth status` for one profile on a computer: signed in (masked identity), signed out, or unknown. A profile with no folder yet is signed out. */
|
|
36
|
+
export declare function runtimeAccountStatus(call: AccountCaller, machineId: string, profile: string): Promise<{
|
|
37
|
+
state: AuthCheckResult;
|
|
38
|
+
identity?: AccountIdentity;
|
|
39
|
+
}>;
|