@mostra/cli 0.6.2 → 0.7.0
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/dist/bin.js +1 -1
- package/dist/{flush-CFJkvi2R.js → flush-CBN3AU9X.js} +90 -30
- package/dist/flush-CBN3AU9X.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/reference/cli.md +107 -1
- package/dist/reference/diagnostics.json +72 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_FRAME_SESSION.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_NOT_ENABLED.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_PORTS_EXHAUSTED.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TOOL_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TOOL_NOT_READY.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TTL_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TUNNEL_FAILED.md +23 -0
- package/dist/run-DKNRTR1j.js +1 -0
- package/dist/{run-3QZacDLc.js → run-DO9Y3Dtm.js} +197 -5
- package/dist/run-DO9Y3Dtm.js.map +1 -0
- package/dist/telemetry/flush-main.js +1 -1
- package/package.json +4 -4
- package/src/command.ts +1 -1
- package/src/commands/index.ts +6 -2
- package/src/commands/sharing.ts +209 -0
- package/src/detached.ts +3 -0
- package/src/telemetry/index.ts +3 -3
- package/src/telemetry/store.ts +95 -30
- package/dist/flush-CFJkvi2R.js.map +0 -1
- package/dist/run-3QZacDLc.js.map +0 -1
- package/dist/run-K42fyQo0.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as TelemetryStore, t as flush } from "../flush-
|
|
1
|
+
import { r as TelemetryStore, t as flush } from "../flush-CBN3AU9X.js";
|
|
2
2
|
//#region src/telemetry/flush-main.ts
|
|
3
3
|
/**
|
|
4
4
|
* The flusher process (D140 item 6): `node flush-main.js <config dir>`, started detached by the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostra/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "The mostra command: author, verify, publish, share and wait on agent artifacts, as a thin client of the Mostra host protocol.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "The Mostra Authors",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"provenance": true
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@mostra/protocol": "0.
|
|
38
|
-
"@mostra/sdk": "0.
|
|
37
|
+
"@mostra/protocol": "0.7.0",
|
|
38
|
+
"@mostra/sdk": "0.7.0",
|
|
39
39
|
"zod": "4.6.7"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@mostra/runtime": "0.
|
|
42
|
+
"@mostra/runtime": "0.7.0",
|
|
43
43
|
"@mostra/tools": "0.0.0",
|
|
44
44
|
"@types/node": "24.19.2",
|
|
45
45
|
"tsdown": "0.23.1",
|
package/src/command.ts
CHANGED
|
@@ -91,7 +91,7 @@ export interface CommandContext {
|
|
|
91
91
|
/** A command-specific telemetry event: its name and its own fields. */
|
|
92
92
|
export interface TelemetryEventInput {
|
|
93
93
|
/** The event's name. */
|
|
94
|
-
readonly event: "verify.result" | "publish.done";
|
|
94
|
+
readonly event: "verify.result" | "publish.done" | "share.done";
|
|
95
95
|
/** Its own fields; the schema keeps only the published ones. */
|
|
96
96
|
readonly fields: Readonly<Record<string, unknown>>;
|
|
97
97
|
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Every command of `mostra` (D60, D140 item 13), in the order help lists them. Commands later
|
|
3
|
-
* packages own (`
|
|
4
|
-
*
|
|
3
|
+
* packages own (`review export`, `export`, `mcp`, `plugin`, `term`, `run`) join this list with
|
|
4
|
+
* their packages, never as placeholders; `share` joined with WP-13.
|
|
5
5
|
*/
|
|
6
6
|
import type { CommandDef } from "../command.ts";
|
|
7
7
|
import {
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
stateSetCommand,
|
|
35
35
|
waitCommand,
|
|
36
36
|
} from "./interaction.ts";
|
|
37
|
+
import { shareCommand, shareListCommand, shareStopCommand } from "./sharing.ts";
|
|
37
38
|
import { openCommand } from "./viewing.ts";
|
|
38
39
|
|
|
39
40
|
/** The commands, in help's order: the authoring loop first. */
|
|
@@ -43,6 +44,9 @@ export const COMMANDS: readonly CommandDef[] = [
|
|
|
43
44
|
verifyCommand,
|
|
44
45
|
publishCommand,
|
|
45
46
|
openCommand,
|
|
47
|
+
shareCommand,
|
|
48
|
+
shareStopCommand,
|
|
49
|
+
shareListCommand,
|
|
46
50
|
waitCommand,
|
|
47
51
|
resultsCommand,
|
|
48
52
|
stateGetCommand,
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mostra share`: an artifact opened to people beyond this machine through a tunnel the daemon
|
|
3
|
+
* runs (D47, D158): `--tailnet` (Tailscale Serve, inside your tailnet, with each person's
|
|
4
|
+
* identity) or `--public` (a Cloudflare quick tunnel by default, or Tailscale Funnel with `--via
|
|
5
|
+
* funnel`), whose link expires (1 hour by default, 7 days at most). The share lives in the
|
|
6
|
+
* daemon, so the command returns at once with the link; `share stop` ends it and `share list`
|
|
7
|
+
* shows what is shared. A client of `share/start`, `share/stop` and `share/list`.
|
|
8
|
+
*/
|
|
9
|
+
import {
|
|
10
|
+
type CapabilityScope,
|
|
11
|
+
type Share,
|
|
12
|
+
type ShareVia,
|
|
13
|
+
shareListMethod,
|
|
14
|
+
shareStartMethod,
|
|
15
|
+
shareStopMethod,
|
|
16
|
+
} from "@mostra/protocol";
|
|
17
|
+
import { type CommandDef, defineCommand } from "../command.ts";
|
|
18
|
+
import { EXIT } from "../exit.ts";
|
|
19
|
+
import { usage } from "../parse.ts";
|
|
20
|
+
import { arg, artifactRef, flag } from "./shared.ts";
|
|
21
|
+
|
|
22
|
+
const SHARE_ID = /^shr_[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
23
|
+
|
|
24
|
+
/** How each tunnel is named in human output. */
|
|
25
|
+
const THROUGH: Readonly<Record<ShareVia, string>> = {
|
|
26
|
+
tailnet: "Tailscale Serve, inside your tailnet",
|
|
27
|
+
funnel: "Tailscale Funnel, public",
|
|
28
|
+
cloudflare: "a Cloudflare quick tunnel, public",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What a tailnet viewer's device needs, found on a real tailnet in WP-13: the tailnet's access
|
|
33
|
+
* policy must let them reach the share's two ports of this device, and their browser's traffic
|
|
34
|
+
* must go through Tailscale (no private or secure DNS of its own, no split tunneling that leaves
|
|
35
|
+
* the browser out).
|
|
36
|
+
*/
|
|
37
|
+
function tailnetReach(share: { readonly url?: string; readonly artifactOrigin?: string }): string {
|
|
38
|
+
const port = (origin: string | undefined): string | undefined =>
|
|
39
|
+
origin === undefined ? undefined : new URL(origin).port || "443";
|
|
40
|
+
const ports = [port(share.url), port(share.artifactOrigin)].filter(
|
|
41
|
+
(value): value is string => value !== undefined,
|
|
42
|
+
);
|
|
43
|
+
return `Viewers need this device's port${ports.length === 1 ? "" : "s"} ${ports.join(" and ")} allowed by the tailnet's access policy, and their browser's traffic sent through Tailscale.\n`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** One share as a line of human output. */
|
|
47
|
+
function line(share: Share): string {
|
|
48
|
+
const until =
|
|
49
|
+
share.state === "stopped"
|
|
50
|
+
? `stopped${share.stopReason ? ` (${share.stopReason})` : ""}`
|
|
51
|
+
: share.expiresAt
|
|
52
|
+
? `until ${share.expiresAt}`
|
|
53
|
+
: "no expiry";
|
|
54
|
+
return `${share.shareId} ${share.via} ${share.hostname} ${until}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** `mostra share <artifact> --tailnet | --public`. */
|
|
58
|
+
export const shareCommand: CommandDef = defineCommand({
|
|
59
|
+
path: ["share"],
|
|
60
|
+
summary:
|
|
61
|
+
"Open an artifact to people beyond this machine: inside your tailnet, or publicly with a link that expires.",
|
|
62
|
+
args: [{ name: "artifact", summary: "The artifact: its source path or its ID." }],
|
|
63
|
+
flags: [
|
|
64
|
+
{
|
|
65
|
+
name: "tailnet",
|
|
66
|
+
kind: "boolean",
|
|
67
|
+
summary:
|
|
68
|
+
"Share inside your tailnet through Tailscale Serve; each viewer is their tailnet identity.",
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "public",
|
|
72
|
+
kind: "boolean",
|
|
73
|
+
summary: "Share publicly: anyone with the link can open it until it expires.",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "via",
|
|
77
|
+
kind: "string",
|
|
78
|
+
value: "<tunnel>",
|
|
79
|
+
choices: ["cloudflare", "funnel"],
|
|
80
|
+
default: "cloudflare",
|
|
81
|
+
summary:
|
|
82
|
+
"The public tunnel: a Cloudflare quick tunnel (no account), or Tailscale Funnel (shows your device's tailnet name).",
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: "ttl",
|
|
86
|
+
kind: "duration",
|
|
87
|
+
value: "<d>",
|
|
88
|
+
summary: "How long the link works, such as 30m or 24h. Public: 1h by default, 7d at most.",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: "scope",
|
|
92
|
+
kind: "list",
|
|
93
|
+
value: "<a,b>",
|
|
94
|
+
summary: "The link's scopes: view, draft, submit, review, signal, action:*. Default: all.",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "viewer",
|
|
98
|
+
kind: "string",
|
|
99
|
+
value: "<ref>",
|
|
100
|
+
summary:
|
|
101
|
+
"The person the link is for, by your own stable key for them; without it, each link is a viewer of its own.",
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "viewer-name",
|
|
105
|
+
kind: "string",
|
|
106
|
+
value: "<name>",
|
|
107
|
+
summary: "The display name of --viewer.",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "request-id",
|
|
111
|
+
kind: "string",
|
|
112
|
+
value: "<id>",
|
|
113
|
+
summary: "Make a retried share return the same share instead of opening another.",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
output: { type: "ShareStartResult", topic: "cli" },
|
|
117
|
+
exits: [EXIT.failure, EXIT.environment],
|
|
118
|
+
example: "share ./sidebar-review --public --ttl 2h",
|
|
119
|
+
async run(context) {
|
|
120
|
+
const artifact = artifactRef(arg(context, "artifact"), context.cwd);
|
|
121
|
+
const tailnet = context.flags["tailnet"] === true;
|
|
122
|
+
const publicly = context.flags["public"] === true;
|
|
123
|
+
if (tailnet === publicly) throw usage("Give --tailnet or --public.");
|
|
124
|
+
const viaFlag = flag(context, "via");
|
|
125
|
+
if (viaFlag !== undefined && !publicly)
|
|
126
|
+
throw usage("--via chooses a public tunnel: add --public.");
|
|
127
|
+
const via: ShareVia = tailnet ? "tailnet" : viaFlag === "funnel" ? "funnel" : "cloudflare";
|
|
128
|
+
const ttl = flag(context, "ttl");
|
|
129
|
+
const scopes = context.flags["scope"] as readonly string[] | undefined;
|
|
130
|
+
const viewerRef = flag(context, "viewer");
|
|
131
|
+
const viewerName = flag(context, "viewer-name");
|
|
132
|
+
const requestId = flag(context, "request-id");
|
|
133
|
+
if (viewerName !== undefined && viewerRef === undefined)
|
|
134
|
+
throw usage("--viewer-name needs --viewer.");
|
|
135
|
+
const share = await context.call(shareStartMethod, {
|
|
136
|
+
artifact,
|
|
137
|
+
via,
|
|
138
|
+
...(ttl !== undefined ? { ttl: ttl as `${number}${"s" | "m" | "h" | "d"}` } : {}),
|
|
139
|
+
...(scopes !== undefined ? { scopes: scopes as CapabilityScope[] } : {}),
|
|
140
|
+
...(viewerRef !== undefined
|
|
141
|
+
? { viewer: { ref: viewerRef, ...(viewerName !== undefined ? { name: viewerName } : {}) } }
|
|
142
|
+
: {}),
|
|
143
|
+
...(requestId !== undefined ? { requestId } : {}),
|
|
144
|
+
});
|
|
145
|
+
context.record({ event: "share.done", fields: { kind: via } });
|
|
146
|
+
const until = share.expiresAt ? `until ${share.expiresAt}` : "until you stop it";
|
|
147
|
+
return {
|
|
148
|
+
result: share,
|
|
149
|
+
human: `${share.url}\nShared through ${THROUGH[via]}, ${until}.\n${via === "tailnet" ? tailnetReach(share) : ""}Stop it with: mostra share stop ${share.shareId}\n`,
|
|
150
|
+
};
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
/** `mostra share stop <artifact|shareId>`. */
|
|
155
|
+
export const shareStopCommand: CommandDef = defineCommand({
|
|
156
|
+
path: ["share", "stop"],
|
|
157
|
+
summary:
|
|
158
|
+
"Stop a share, or every share of an artifact: its link stops working and its tunnel closes.",
|
|
159
|
+
args: [{ name: "target", summary: "A share's ID (shr_…), or an artifact's source path or ID." }],
|
|
160
|
+
flags: [],
|
|
161
|
+
output: { type: "ShareStopResult", topic: "cli" },
|
|
162
|
+
exits: [EXIT.failure, EXIT.environment],
|
|
163
|
+
example: "share stop ./sidebar-review",
|
|
164
|
+
async run(context) {
|
|
165
|
+
const target = arg(context, "target");
|
|
166
|
+
const result = await context.call(
|
|
167
|
+
shareStopMethod,
|
|
168
|
+
SHARE_ID.test(target) ? { shareId: target } : { artifact: artifactRef(target, context.cwd) },
|
|
169
|
+
);
|
|
170
|
+
return {
|
|
171
|
+
result,
|
|
172
|
+
human:
|
|
173
|
+
result.stopped.length === 0
|
|
174
|
+
? "Nothing was shared.\n"
|
|
175
|
+
: result.stopped.map((share) => `Stopped ${share.shareId}\n`).join(""),
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
/** `mostra share list [artifact] [--all]`. */
|
|
181
|
+
export const shareListCommand: CommandDef = defineCommand({
|
|
182
|
+
path: ["share", "list"],
|
|
183
|
+
summary: "List the active shares, of every artifact or of one; --all adds the ones that ended.",
|
|
184
|
+
args: [
|
|
185
|
+
{
|
|
186
|
+
name: "artifact",
|
|
187
|
+
summary: "Only this artifact's shares: its source path or ID.",
|
|
188
|
+
optional: true,
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
flags: [{ name: "all", kind: "boolean", summary: "Also list shares that ended, and why." }],
|
|
192
|
+
output: { type: "ShareListResult", topic: "cli" },
|
|
193
|
+
exits: [EXIT.failure],
|
|
194
|
+
example: "share list --all",
|
|
195
|
+
async run(context) {
|
|
196
|
+
const given = context.args["artifact"];
|
|
197
|
+
const result = await context.call(shareListMethod, {
|
|
198
|
+
...(typeof given === "string" ? { artifact: artifactRef(given, context.cwd) } : {}),
|
|
199
|
+
...(context.flags["all"] === true ? { all: true } : {}),
|
|
200
|
+
});
|
|
201
|
+
return {
|
|
202
|
+
result,
|
|
203
|
+
human:
|
|
204
|
+
result.shares.length === 0
|
|
205
|
+
? "Nothing is shared.\n"
|
|
206
|
+
: `${result.shares.map((share) => line(share)).join("\n")}\n`,
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
});
|
package/src/detached.ts
CHANGED
|
@@ -26,6 +26,9 @@ export const PATH_VARIABLES: readonly string[] = [
|
|
|
26
26
|
"MOSTRA_WIN_HELPER",
|
|
27
27
|
"MOSTRA_TEST_WORKER_HOST",
|
|
28
28
|
"MOSTRA_TEST_BUNDLE_PINS",
|
|
29
|
+
"MOSTRA_TAILSCALE",
|
|
30
|
+
"MOSTRA_CLOUDFLARED",
|
|
31
|
+
"MOSTRA_TEST_TUNNELS",
|
|
29
32
|
];
|
|
30
33
|
|
|
31
34
|
/** `env` with every relative path variable resolved against `cwd`. */
|
package/src/telemetry/index.ts
CHANGED
|
@@ -84,9 +84,9 @@ export const QUESTION_TIMEOUT_MS = 60_000;
|
|
|
84
84
|
export interface TelemetrySession {
|
|
85
85
|
/** Before the command's work: the notice, or the question. Resolves `false` when Ctrl-C ended it. */
|
|
86
86
|
begin(): Promise<boolean>;
|
|
87
|
-
/** Records an event of the command (`verify.result`, `publish.done`). */
|
|
87
|
+
/** Records an event of the command (`verify.result`, `publish.done`, `share.done`). */
|
|
88
88
|
record(event: {
|
|
89
|
-
readonly event: "verify.result" | "publish.done";
|
|
89
|
+
readonly event: "verify.result" | "publish.done" | "share.done";
|
|
90
90
|
readonly fields: Readonly<Record<string, unknown>>;
|
|
91
91
|
}): void;
|
|
92
92
|
/** After the command: queues its events and starts the flusher, when telemetry allows. */
|
|
@@ -121,7 +121,7 @@ export function telemetrySession(options: TelemetryOptions): TelemetrySession {
|
|
|
121
121
|
const now = options.now ?? Date.now;
|
|
122
122
|
const store = new TelemetryStore(options.configDir);
|
|
123
123
|
const pending: {
|
|
124
|
-
event: "verify.result" | "publish.done";
|
|
124
|
+
event: "verify.result" | "publish.done" | "share.done";
|
|
125
125
|
fields: Readonly<Record<string, unknown>>;
|
|
126
126
|
}[] = [];
|
|
127
127
|
const decision = (embedded: boolean): TelemetryDecision =>
|
package/src/telemetry/store.ts
CHANGED
|
@@ -16,13 +16,14 @@ import {
|
|
|
16
16
|
linkSync,
|
|
17
17
|
mkdirSync,
|
|
18
18
|
openSync,
|
|
19
|
+
readdirSync,
|
|
19
20
|
readFileSync,
|
|
20
21
|
renameSync,
|
|
21
22
|
rmSync,
|
|
22
23
|
statSync,
|
|
23
24
|
writeFileSync,
|
|
24
25
|
} from "node:fs";
|
|
25
|
-
import { dirname, join } from "node:path";
|
|
26
|
+
import { basename, dirname, join } from "node:path";
|
|
26
27
|
|
|
27
28
|
/** What `telemetry.json` holds. */
|
|
28
29
|
export interface TelemetrySettings {
|
|
@@ -340,43 +341,94 @@ export class TelemetryStore {
|
|
|
340
341
|
}
|
|
341
342
|
|
|
342
343
|
/**
|
|
343
|
-
* Takes a crashed owner's lock away.
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
344
|
+
* Takes a crashed owner's lock away (#98). Only one process breaks locks at a time: it holds the
|
|
345
|
+
* break lock while it judges the lock again and removes it. An owner removes only its own lock
|
|
346
|
+
* and every other remover holds the break lock, so the lock judged is the lock removed: no
|
|
347
|
+
* breaker ever moves a live owner's lock aside or brings back one its owner released.
|
|
348
|
+
*
|
|
349
|
+
* The break lock is never removed by anyone but its holder, since removing a file only if it is
|
|
350
|
+
* the one judged can't be done atomically (Opus review of WP-13): break locks are numbered
|
|
351
|
+
* (`telemetry.lock.break.<n>`), the highest is the one in force, and a crashed breaker's is
|
|
352
|
+
* superseded, never removed, by creating the next number exclusively. Two that judged the same
|
|
353
|
+
* one crashed race for the same next number, and one of them wins; one that created a number
|
|
354
|
+
* below a higher one holds nothing. The holder removes the ones below its own, then its own
|
|
355
|
+
* when done. A break lock is crashed by the lock's own rules (older
|
|
356
|
+
* than 10 s with its owner gone, or older than 60 s).
|
|
357
|
+
*
|
|
358
|
+
* Answers `broken` when the caller should try again at once, `absent` when no lock file exists,
|
|
359
|
+
* and `held` when the caller should wait: a live owner's lock, another breaker at work, or a
|
|
360
|
+
* lock that can't be read (on Windows, a lock being deleted).
|
|
348
361
|
*/
|
|
349
362
|
#breakStale(): "broken" | "absent" | "held" {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
+
const judged = judge(this.#lockFile);
|
|
364
|
+
if (judged !== "stale") return judged;
|
|
365
|
+
const dir = dirname(this.#lockFile);
|
|
366
|
+
const prefix = `${basename(this.#lockFile)}.break.`;
|
|
367
|
+
const numbered = (): number[] => {
|
|
368
|
+
try {
|
|
369
|
+
return readdirSync(dir)
|
|
370
|
+
.filter(
|
|
371
|
+
(name) =>
|
|
372
|
+
name.startsWith(prefix) && /^[1-9][0-9]{0,15}$/.test(name.slice(prefix.length)),
|
|
373
|
+
)
|
|
374
|
+
.map((name) => Number(name.slice(prefix.length)))
|
|
375
|
+
.sort((a, b) => a - b);
|
|
376
|
+
} catch {
|
|
377
|
+
return [];
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
const file = (n: number): string => join(dir, `${prefix}${n}`);
|
|
381
|
+
const below = numbered();
|
|
382
|
+
const current = below.at(-1);
|
|
383
|
+
if (current !== undefined) {
|
|
384
|
+
// Another breaker is at work, or one crashed at it.
|
|
385
|
+
if (judge(file(current)) !== "stale") return "held";
|
|
386
|
+
pause(breakPauseMs());
|
|
363
387
|
}
|
|
364
|
-
|
|
365
|
-
const
|
|
388
|
+
const mine = (current ?? 0) + 1;
|
|
389
|
+
const token = `${process.pid} ${randomUUID()}`;
|
|
366
390
|
try {
|
|
367
|
-
|
|
368
|
-
} catch
|
|
369
|
-
// Another breaker
|
|
370
|
-
return
|
|
391
|
+
writeFileSync(file(mine), token, { flag: "wx", mode: 0o600 });
|
|
392
|
+
} catch {
|
|
393
|
+
// Another breaker took this number first, or the directory can't be written.
|
|
394
|
+
return "held";
|
|
371
395
|
}
|
|
372
396
|
try {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
397
|
+
// A process that listed before a later number existed may create a lower one: the highest
|
|
398
|
+
// holds, and this one, not the highest, never acts.
|
|
399
|
+
if (numbered().some((n) => n > mine)) return "held";
|
|
400
|
+
// The ones before are superseded: a crashed breaker's, or ones a holder left by crashing.
|
|
401
|
+
for (const n of below) rmSync(file(n), { force: true });
|
|
402
|
+
// Judged again under the break lock: the lock may have gone, or been replaced, meanwhile.
|
|
403
|
+
const now = judge(this.#lockFile);
|
|
404
|
+
if (now !== "stale") return now;
|
|
405
|
+
pause(breakPauseMs());
|
|
406
|
+
rmSync(this.#lockFile, { force: true });
|
|
407
|
+
return "broken";
|
|
376
408
|
} finally {
|
|
377
|
-
rmSync(
|
|
409
|
+
rmSync(file(mine), { force: true });
|
|
378
410
|
}
|
|
379
|
-
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* Whether a lock file may be taken away: `stale` when it is older than 10 s and its owner no
|
|
416
|
+
* longer runs, or older than 60 s whoever it names; `held` while it is younger, its owner runs,
|
|
417
|
+
* or it can't be read; `absent` when there is none. One descriptor reads the age and the
|
|
418
|
+
* contents, so both describe the same file.
|
|
419
|
+
*/
|
|
420
|
+
function judge(file: string): "stale" | "absent" | "held" {
|
|
421
|
+
let handle: number | undefined;
|
|
422
|
+
try {
|
|
423
|
+
handle = openSync(file, "r");
|
|
424
|
+
const age = Date.now() - fstatSync(handle).mtimeMs;
|
|
425
|
+
if (age <= STALE_LOCK_MS) return "held";
|
|
426
|
+
const seen = readFileSync(handle, "utf8");
|
|
427
|
+
return age <= DEAD_LOCK_MS && ownerAlive(seen) ? "held" : "stale";
|
|
428
|
+
} catch (error) {
|
|
429
|
+
return (error as NodeJS.ErrnoException).code === "ENOENT" ? "absent" : "held";
|
|
430
|
+
} finally {
|
|
431
|
+
if (handle !== undefined) closeSync(handle);
|
|
380
432
|
}
|
|
381
433
|
}
|
|
382
434
|
|
|
@@ -477,3 +529,16 @@ function bounded(lines: readonly string[], now: number): string[] {
|
|
|
477
529
|
});
|
|
478
530
|
return fresh.slice(-QUEUE_MAX_EVENTS);
|
|
479
531
|
}
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* A pause inside a breaker's step, for tests only (`MOSTRA_TEST_LOCK_BREAK_MS`): it widens the
|
|
535
|
+
* window a slow machine opens between judging a lock and acting on it (#98).
|
|
536
|
+
*/
|
|
537
|
+
const BREAK_PAUSE_VARIABLE = "MOSTRA_TEST_LOCK_BREAK_MS";
|
|
538
|
+
function breakPauseMs(): number {
|
|
539
|
+
const value = Number(process.env[BREAK_PAUSE_VARIABLE] ?? "0");
|
|
540
|
+
return Number.isFinite(value) && value > 0 ? Math.min(value, 5_000) : 0;
|
|
541
|
+
}
|
|
542
|
+
function pause(ms: number): void {
|
|
543
|
+
if (ms > 0) Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
544
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"flush-CFJkvi2R.js","names":["httpsRequest","httpRequest"],"sources":["../src/version.ts","../src/telemetry/decision.ts","../src/telemetry/harness.ts","../src/telemetry/events.ts","../src/detached.ts","../src/telemetry/store.ts","../src/telemetry/flush.ts"],"sourcesContent":["/** The CLI's own package: its root directory and its release. */\nimport { readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nlet found: { readonly root: string; readonly version: string } | undefined;\n\nfunction own(): { readonly root: string; readonly version: string } {\n if (found) return found;\n let dir = dirname(fileURLToPath(import.meta.url));\n for (;;) {\n try {\n const manifest = JSON.parse(readFileSync(join(dir, \"package.json\"), \"utf8\")) as {\n name?: string;\n version?: string;\n };\n if (manifest.name === \"@mostra/cli\" && manifest.version) {\n found = { root: dir, version: manifest.version };\n return found;\n }\n } catch {\n // Keep looking upwards.\n }\n const parent = dirname(dir);\n if (parent === dir) throw new Error(\"Couldn't find @mostra/cli's package.json.\");\n dir = parent;\n }\n}\n\n/** This CLI's version (`mostra --version`, the client version it reports, telemetry's `version`). */\nexport function cliVersion(): string {\n return own().version;\n}\n\n/** The CLI package's directory: its `dist/`, `src/` and bundled reference live under it. */\nexport function packageRoot(): string {\n return own().root;\n}\n\n/** Whether this CLI runs from its TypeScript sources (tests), not its build. */\nexport function fromSource(): boolean {\n return import.meta.url.endsWith(\".ts\");\n}\n","/**\n * Whether telemetry sends, and why (D140 item 3). The first match decides, so an explicit \"off\"\n * anywhere wins over any \"on\", and withdrawn consent sticks.\n */\nimport type { Environment } from \"../home.ts\";\nimport type { ReadSettings } from \"./store.ts\";\nimport type { TelemetryReason } from \"./words.ts\";\n\n/** The endpoint this build sends to, set only by the release workflow at bundle time (D140 item 7). */\ndeclare const __MOSTRA_TELEMETRY_ENDPOINT__: string | undefined;\n\n/** The build's endpoint: empty in this package and in every development build. */\nexport function buildEndpoint(): string {\n return typeof __MOSTRA_TELEMETRY_ENDPOINT__ === \"string\" ? __MOSTRA_TELEMETRY_ENDPOINT__ : \"\";\n}\n\n/** What the decision reads. */\nexport interface DecisionInputs {\n readonly env: Environment;\n /** The build's endpoint ({@link buildEndpoint}); tests pass their own. */\n readonly buildEndpoint: string;\n /** Whether this use is embedded: a host-spawned instance, or a home a host configures. */\n readonly embedded: boolean;\n readonly settings: ReadSettings;\n /** Whether this machine's time zone asks first. */\n readonly askFirst: boolean;\n}\n\n/** The decision. */\nexport interface TelemetryDecision {\n readonly enabled: boolean;\n readonly reason: TelemetryReason;\n readonly askFirst: boolean;\n /** The endpoint events go to, when there is one. */\n readonly endpoint?: string;\n /** For an enabled decision: whether the person said yes, or it is the default. */\n readonly consent?: \"explicit\" | \"default\";\n}\n\nconst OFF_VALUES = new Set([\"0\", \"false\", \"off\", \"no\"]);\nconst ON_VALUES = new Set([\"1\", \"true\", \"on\", \"yes\"]);\n\n/** `DO_NOT_TRACK` and `MOSTRA_OFFLINE`'s parser: set to anything but empty, `0` or `false`. */\nexport function truthy(value: string | undefined): boolean {\n if (value === undefined) return false;\n const normalized = value.trim().toLowerCase();\n return normalized !== \"\" && normalized !== \"0\" && normalized !== \"false\";\n}\n\n/**\n * The endpoint in use: `MOSTRA_TELEMETRY_ENDPOINT` when it is `https:` or `http:` to a loopback\n * address, else the build's; `undefined` when there is none (D140 item 7).\n */\nexport function endpointOf(env: Environment, build: string): string | undefined {\n const override = env[\"MOSTRA_TELEMETRY_ENDPOINT\"];\n const chosen = override !== undefined && override !== \"\" ? override : build;\n if (chosen === \"\") return undefined;\n let url: URL;\n try {\n url = new URL(chosen);\n } catch {\n return undefined;\n }\n if (url.username !== \"\" || url.password !== \"\") return undefined;\n if (url.protocol === \"https:\") return url.href;\n const loopback =\n url.hostname === \"127.0.0.1\" || url.hostname === \"[::1]\" || url.hostname === \"localhost\";\n return url.protocol === \"http:\" && loopback ? url.href : undefined;\n}\n\n/** Decides, in D140's order. */\nexport function decide(inputs: DecisionInputs): TelemetryDecision {\n const { askFirst } = inputs;\n const off = (reason: TelemetryReason): TelemetryDecision => ({\n enabled: false,\n reason,\n askFirst,\n });\n const endpoint = endpointOf(inputs.env, inputs.buildEndpoint);\n if (endpoint === undefined) return off(\"no-collector\");\n const at = { askFirst, endpoint };\n if (inputs.embedded) return { ...at, enabled: false, reason: \"embedded\" };\n if (truthy(inputs.env[\"DO_NOT_TRACK\"])) return { ...at, enabled: false, reason: \"do-not-track\" };\n const variable = inputs.env[\"MOSTRA_TELEMETRY\"];\n const normalized = variable?.trim().toLowerCase();\n if (normalized !== undefined && OFF_VALUES.has(normalized)) {\n return { ...at, enabled: false, reason: \"variable\" };\n }\n if (!inputs.settings.ok) return { ...at, enabled: false, reason: \"unreadable\" };\n const choice = inputs.settings.settings.choice;\n if (choice === \"off\") return { ...at, enabled: false, reason: \"setting\" };\n if (normalized !== undefined && normalized !== \"\") {\n return ON_VALUES.has(normalized)\n ? { ...at, enabled: true, reason: \"variable\", consent: \"explicit\" }\n : { ...at, enabled: false, reason: \"variable-invalid\" };\n }\n if (choice === \"on\") return { ...at, enabled: true, reason: \"setting\", consent: \"explicit\" };\n return askFirst\n ? { ...at, enabled: false, reason: \"default\" }\n : { ...at, enabled: true, reason: \"default\", consent: \"default\" };\n}\n","/**\n * Which agent ran the CLI (D140 item 9), from environment markers each agent documents or sets in\n * its source (VERIFIED_FACTS, WP-10). Only the agent's ID is ever sent, never a marker's value.\n */\nimport type { Environment } from \"../home.ts\";\n\n/** The agents Mostra recognizes, in the order their markers are checked. */\nexport const HARNESSES = [\"claude-code\", \"codex\", \"gemini-cli\", \"opencode\", \"cursor\"] as const;\n\n/** A recognized agent, `other` for an agent Mostra doesn't know, `none` for no agent at all. */\nexport type Harness = (typeof HARNESSES)[number] | \"other\" | \"none\";\n\n/** Each agent's own marker. */\nconst MARKERS: Readonly<Record<(typeof HARNESSES)[number], string>> = {\n \"claude-code\": \"CLAUDECODE\",\n codex: \"CODEX_THREAD_ID\",\n \"gemini-cli\": \"GEMINI_CLI\",\n opencode: \"OPENCODE\",\n cursor: \"CURSOR_AGENT\",\n};\n\nconst set = (value: string | undefined): boolean => value !== undefined && value !== \"\";\n\n/**\n * The agent that ran this process: `AI_AGENT` when it starts with a known ID (the convention\n * `@vercel/detect-agent` reads), else the first agent whose own marker is set, else `other` when\n * `AI_AGENT` or `AGENT` names something else, else `none`. Cursor's editor terminal sets\n * `CURSOR_TRACE_ID` without `CURSOR_AGENT`: that is a person, so it isn't `cursor`.\n */\nexport function detectHarness(env: Environment): Harness {\n const declared = env[\"AI_AGENT\"];\n if (set(declared)) {\n const known = HARNESSES.find((id) => declared?.startsWith(id));\n if (known) return known;\n }\n for (const id of HARNESSES) if (set(env[MARKERS[id]])) return id;\n if (set(declared) || set(env[\"AGENT\"])) return \"other\";\n return \"none\";\n}\n","/**\n * Telemetry's event schema 1 (D140 item 8), the one published in `docs/reference/telemetry.md`.\n * Every event is checked against it before it is queued and again before it is sent, so nothing\n * that isn't on that page can leave the machine: the objects are strict, every string is from a\n * closed set or a pattern, and no field takes free text.\n */\nimport { DIAGNOSTIC_AREAS } from \"@mostra/protocol\";\nimport * as z from \"zod\";\nimport { HARNESSES, type Harness } from \"./harness.ts\";\n\n/** The schema version every event carries. */\nexport const SCHEMA = 1;\n\n/** The duration buckets of `cli.command`. */\nexport const DURATIONS = [\"<1s\", \"1-5s\", \"5-30s\", \"30s-2m\", \"2-10m\", \">10m\"] as const;\n\n/** A command's duration bucket. */\nexport function durationBucket(ms: number): (typeof DURATIONS)[number] {\n if (ms < 1000) return \"<1s\";\n if (ms < 5000) return \"1-5s\";\n if (ms < 30_000) return \"5-30s\";\n if (ms < 120_000) return \"30s-2m\";\n if (ms < 600_000) return \"2-10m\";\n return \">10m\";\n}\n\n/** A catalog-shaped diagnostic code: `MOSTRA_<AREA>_<NAME>`, never a message. */\nconst code = z\n .string()\n .regex(new RegExp(`^MOSTRA_(${DIAGNOSTIC_AREAS.join(\"|\")})_[A-Z0-9_]{1,64}$`));\n\n/** A command path from the definitions: lowercase words. */\nconst command = z.string().regex(/^[a-z]+( [a-z]+)?$/);\n\nconst common = {\n schema: z.literal(SCHEMA),\n at: z.string().regex(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:00Z$/),\n installId: z.uuid(),\n version: z.string().regex(/^\\d+\\.\\d+\\.\\d+(-[0-9A-Za-z.-]+)?$/),\n os: z.enum([\"darwin\", \"linux\", \"win32\"]),\n arch: z.string().regex(/^[a-z0-9]{2,12}$/),\n node: z.int().min(0).max(999),\n harness: z.enum([...HARNESSES, \"other\", \"none\"]),\n ci: z.boolean(),\n consent: z.enum([\"explicit\", \"default\"]),\n};\n\n/** The fields every event carries. */\nexport interface CommonFields {\n readonly schema: typeof SCHEMA;\n readonly at: string;\n readonly installId: string;\n readonly version: string;\n readonly os: \"darwin\" | \"linux\" | \"win32\";\n readonly arch: string;\n readonly node: number;\n readonly harness: Harness;\n readonly ci: boolean;\n readonly consent: \"explicit\" | \"default\";\n}\n\n/** One event, as sent (D140 item 8). */\nexport type TelemetryEvent = CommonFields &\n (\n | { readonly event: \"cli.first_run\" }\n | {\n readonly event: \"cli.command\";\n readonly command: string;\n readonly exit: number;\n readonly duration: (typeof DURATIONS)[number];\n readonly json: boolean;\n readonly error?: string | undefined;\n }\n | {\n readonly event: \"verify.result\";\n readonly status: \"pass\" | \"fail\";\n readonly codes: readonly string[];\n readonly codesTruncated: boolean;\n }\n | { readonly event: \"publish.done\"; readonly reused: boolean; readonly forced: boolean }\n | {\n readonly event: \"share.done\";\n readonly kind: \"tailnet\" | \"funnel\" | \"cloudflare\" | \"remote\";\n }\n | {\n readonly event: \"mcp.session\";\n readonly client: (typeof HARNESSES)[number] | \"other\";\n readonly clientVersion?: string | undefined;\n }\n );\n\n/** Every event Mostra may send, as a strict union on `event`. */\nexport const TelemetryEvent: z.ZodType<TelemetryEvent> = z.discriminatedUnion(\"event\", [\n z.strictObject({ ...common, event: z.literal(\"cli.first_run\") }),\n z.strictObject({\n ...common,\n event: z.literal(\"cli.command\"),\n command,\n exit: z.int().min(0).max(255),\n duration: z.enum(DURATIONS),\n json: z.boolean(),\n error: code.optional(),\n }),\n z.strictObject({\n ...common,\n event: z.literal(\"verify.result\"),\n status: z.enum([\"pass\", \"fail\"]),\n codes: z.array(code).max(50),\n codesTruncated: z.boolean(),\n }),\n z.strictObject({\n ...common,\n event: z.literal(\"publish.done\"),\n reused: z.boolean(),\n forced: z.boolean(),\n }),\n // Emitted by WP-13 and WP-29.\n z.strictObject({\n ...common,\n event: z.literal(\"share.done\"),\n kind: z.enum([\"tailnet\", \"funnel\", \"cloudflare\", \"remote\"]),\n }),\n // Emitted by WP-15: a known agent's ID for the MCP client, or `other`; its version only then.\n z.strictObject({\n ...common,\n event: z.literal(\"mcp.session\"),\n client: z.enum([...HARNESSES, \"other\"]),\n clientVersion: z\n .string()\n .regex(/^[0-9A-Za-z.+-]{1,32}$/)\n .optional(),\n }),\n]);\n\n/** `at`: now in UTC, rounded down to the minute. */\nexport function minute(now: Date): string {\n return `${now.toISOString().slice(0, 16)}:00Z`;\n}\n\n/** The distinct catalog codes of `codes`, sorted, at most 50, and whether some were left out. */\nexport function catalogCodes(\n codes: readonly string[],\n known: ReadonlySet<string>,\n): { codes: string[]; codesTruncated: boolean } {\n const distinct = [...new Set(codes.filter((value) => known.has(value)))].sort();\n return { codes: distinct.slice(0, 50), codesTruncated: distinct.length > 50 };\n}\n","/**\n * The directory and environment of the processes the CLI leaves running: its home's daemon and\n * the telemetry flusher. They run in their file system's root, because on Windows nobody can\n * rename or remove a running process's working directory, and they outlive the command (WP-W2,\n * D151 item 3). Every path the environment names relative to the command's directory is made\n * absolute first, so it still names what it named for the command (Opus review of WP-W2,\n * finding 3).\n */\nimport { isAbsolute, parse, resolve } from \"node:path\";\n\n/**\n * The variables whose values are paths: Mostra's own, as the runtime, the SDK and the CLI read\n * them. A test keeps the list complete.\n */\nexport const PATH_VARIABLES: readonly string[] = [\n \"MOSTRA_HOME\",\n \"MOSTRA_RUNTIME_DIR\",\n \"MOSTRA_CONFIG_DIR\",\n \"MOSTRA_CACHE_DIR\",\n \"MOSTRA_BUNDLE\",\n \"MOSTRA_RUNTIME_BIN\",\n \"MOSTRA_SHELL_DIR\",\n \"MOSTRA_WARM_DIR\",\n \"MOSTRA_WORKER_ENTRY\",\n \"MOSTRA_VERIFY_ENTRY\",\n \"MOSTRA_WIN_HELPER\",\n \"MOSTRA_TEST_WORKER_HOST\",\n \"MOSTRA_TEST_BUNDLE_PINS\",\n];\n\n/** `env` with every relative path variable resolved against `cwd`. */\nexport function detachedEnvironment(\n env: Readonly<Record<string, string | undefined>>,\n cwd: string = process.cwd(),\n): Record<string, string | undefined> {\n const result: Record<string, string | undefined> = { ...env };\n for (const name of PATH_VARIABLES) {\n const value = result[name];\n if (value !== undefined && value !== \"\" && !isAbsolute(value)) {\n result[name] = resolve(cwd, value);\n }\n }\n return result;\n}\n\n/** The working directory of a process the CLI leaves running: the root of `anchor`'s file system. */\nexport function detachedDirectory(anchor: string): string {\n return parse(resolve(anchor)).root;\n}\n","/**\n * Telemetry's files in the CLI's config directory (D140 item 5): `telemetry.json` (the choice,\n * when the notice was shown, when a flush last started), `telemetry-id` (the random install ID)\n * and `telemetry-queue.ndjson` (events waiting to be sent). The directory is 0700 and the files\n * 0600; `telemetry.json` and the queue are written by rename. The install ID is made by an\n * exclusive create (a hard link that fails when the file exists), so processes on a first run\n * agree on one ID whatever happens to the lock. Every other change goes through one lock file,\n * owned by a token and taken over only when its holder has died, so a flusher never loses an\n * event appended while it sends.\n */\nimport { randomUUID } from \"node:crypto\";\nimport {\n chmodSync,\n closeSync,\n fstatSync,\n linkSync,\n mkdirSync,\n openSync,\n readFileSync,\n renameSync,\n rmSync,\n statSync,\n writeFileSync,\n} from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\n/** What `telemetry.json` holds. */\nexport interface TelemetrySettings {\n /** The person's choice: `mostra telemetry on|off`, or their answer to the question. */\n readonly choice?: \"on\" | \"off\";\n /**\n * The random install ID, made on the first run that sends; deleted when telemetry turns off.\n * Read from `telemetry-id`, never written into `telemetry.json`.\n */\n readonly installId?: string;\n /**\n * When the notice of what is sent was shown where sending follows: the default notice, the\n * question, or `mostra telemetry on`'s. A `default`-consent event needs it (Opus review\n * finding 3).\n */\n readonly noticeShownAt?: string;\n /**\n * When the ask-first notice (\"Nothing is sent unless you run: mostra telemetry on\") was\n * shown. It never stands for the default notice: a later run where telemetry is on by default\n * still shows that one before anything is sent.\n */\n readonly askFirstNoticeShownAt?: string;\n /** When a flush last started. */\n readonly lastFlushAt?: string;\n}\n\n/** The settings, or why they can't be read (which means off, D140 item 5). */\nexport type ReadSettings =\n | { readonly ok: true; readonly settings: TelemetrySettings }\n | { readonly ok: false; readonly file: string };\n\n/** A lock older than this whose owner no longer runs is taken over as stale. */\nconst STALE_LOCK_MS = 10_000;\n/**\n * A lock older than this is taken over whoever it names: a held section takes milliseconds, and\n * a PID can name an unrelated live process once the owner died (in a container, PID 1 always\n * runs), which would otherwise hold every later command up forever (Opus review finding 5).\n */\nconst DEAD_LOCK_MS = 60_000;\n/** The queue's bounds (D140 item 6). */\nexport const QUEUE_MAX_EVENTS = 1000;\nexport const QUEUE_MAX_AGE_MS: number = 7 * 24 * 60 * 60 * 1000;\n\nconst UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;\n\n/** Telemetry's files in one config directory. */\nexport class TelemetryStore {\n readonly dir: string;\n readonly settingsFile: string;\n readonly queueFile: string;\n readonly idFile: string;\n readonly #lockFile: string;\n readonly #platform: string;\n\n /** `platform` is the system whose lock rules apply: this process's, but for tests. */\n constructor(dir: string, platform: string = process.platform) {\n this.dir = dir;\n this.#platform = platform;\n this.settingsFile = join(dir, \"telemetry.json\");\n this.queueFile = join(dir, \"telemetry-queue.ndjson\");\n this.idFile = join(dir, \"telemetry-id\");\n this.#lockFile = join(dir, \"telemetry.lock\");\n }\n\n /** The settings; a file that isn't telemetry settings is unreadable, never guessed at. */\n read(): ReadSettings {\n // A directory that can never exist (a part of its path is a file) is unreadable, never\n // \"nothing stored yet\". POSIX says so for every read (ENOTDIR); Windows answers ENOENT, which\n // would read as the default, on, though nothing could ever be recorded (WP-W2).\n if (blocked(this.dir)) return { ok: false, file: this.dir };\n const id = this.#readId();\n if (id === null) return { ok: false, file: this.idFile };\n let text: string;\n try {\n text = readFileSync(this.settingsFile, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\")\n return { ok: true, settings: id !== undefined ? { installId: id } : {} };\n return { ok: false, file: this.settingsFile };\n }\n try {\n const data = JSON.parse(text) as Record<string, unknown>;\n if (typeof data !== \"object\" || data === null || Array.isArray(data)) throw new Error();\n const { choice, noticeShownAt, askFirstNoticeShownAt, lastFlushAt } = data;\n const installId = id;\n if (choice !== undefined && choice !== \"on\" && choice !== \"off\") throw new Error();\n // An install ID belongs in `telemetry-id`; one here is a file Mostra didn't write.\n if (data[\"installId\"] !== undefined) throw new Error();\n if (noticeShownAt !== undefined && typeof noticeShownAt !== \"string\") throw new Error();\n if (askFirstNoticeShownAt !== undefined && typeof askFirstNoticeShownAt !== \"string\")\n throw new Error();\n if (lastFlushAt !== undefined && typeof lastFlushAt !== \"string\") throw new Error();\n return {\n ok: true,\n settings: {\n ...(choice !== undefined ? { choice } : {}),\n ...(installId !== undefined ? { installId } : {}),\n ...(noticeShownAt !== undefined ? { noticeShownAt } : {}),\n ...(askFirstNoticeShownAt !== undefined ? { askFirstNoticeShownAt } : {}),\n ...(lastFlushAt !== undefined ? { lastFlushAt } : {}),\n },\n };\n } catch {\n return { ok: false, file: this.settingsFile };\n }\n }\n\n /**\n * Changes the settings under the lock and returns what they became; `undefined` when the file\n * can't be read (nothing is written over it).\n */\n update(change: (current: TelemetrySettings) => TelemetrySettings): TelemetrySettings | undefined {\n return this.locked(() => {\n const current = this.read();\n if (!current.ok) return undefined;\n const next = change(current.settings);\n this.#write(next);\n return next;\n });\n }\n\n /**\n * The install ID, made when there is none yet. A new ID is written to a file of this process's\n * own, then hard-linked to `telemetry-id`, which fails when the file exists: of any processes\n * making one at once exactly one wins, and the others read the winner's. `undefined` when the\n * settings can't be read.\n */\n installId(): { readonly id: string; readonly created: boolean } | undefined {\n const current = this.read();\n if (!current.ok) return undefined;\n if (current.settings.installId !== undefined)\n return { id: current.settings.installId, created: false };\n const candidate = `${this.idFile}.${process.pid}.${randomUUID()}.tmp`;\n const id = randomUUID();\n try {\n this.#prepareDir();\n writeFileSync(candidate, `${id}\\n`, { mode: 0o600 });\n linkSync(candidate, this.idFile);\n return { id, created: true };\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") return undefined;\n const winner = this.#readId();\n return winner ? { id: winner, created: false } : undefined;\n } finally {\n rmSync(candidate, { force: true });\n }\n }\n\n /** The install ID in `telemetry-id`: `undefined` when there is none, `null` when it's damaged. */\n #readId(): string | undefined | null {\n let text: string;\n try {\n text = readFileSync(this.idFile, \"utf8\");\n } catch (error) {\n return (error as NodeJS.ErrnoException).code === \"ENOENT\" ? undefined : null;\n }\n const id = text.trim();\n return UUID.test(id) ? id : null;\n }\n\n /**\n * Replaces a file that can't be read with these settings; only `telemetry on|off` do, as the\n * person's explicit choice. Call it holding the lock.\n */\n reset(settings: TelemetrySettings): TelemetrySettings {\n const { installId: _id, ...rest } = settings;\n this.#write(rest);\n // A damaged install ID goes too; `on` makes a new one on its first send.\n rmSync(this.idFile, { force: true });\n if (settings.choice === \"off\") rmSync(this.queueFile, { force: true });\n return rest;\n }\n\n /** Turns telemetry off: the choice, and the install ID and the queue deleted at once. */\n turnOff(): boolean {\n return (\n this.locked(() => {\n const current = this.read();\n if (!current.ok) return false;\n const { installId: _id, ...rest } = current.settings;\n this.#write({ ...rest, choice: \"off\" });\n rmSync(this.idFile, { force: true });\n rmSync(this.queueFile, { force: true });\n return true;\n }) ?? false\n );\n }\n\n /** Appends events to the queue, keeping its bounds. */\n append(lines: readonly string[], now: number): void {\n if (lines.length === 0) return;\n this.locked(() => {\n const kept = bounded([...this.#queued(), ...lines], now);\n this.#writeQueue(kept);\n });\n }\n\n /** The queued events, within their bounds. */\n queued(now: number): string[] {\n return bounded(this.#queued(), now);\n }\n\n /**\n * Removes the lines a flush sent from the head of the queue, after pruning what expired or\n * fell outside the bounds, as {@link queued} did; how many sent lines were removed (0 when the\n * lock can't be had). A flusher stops when this is 0, so it never sends a batch twice.\n */\n drop(sent: readonly string[], now: number): number {\n return (\n this.locked(() => {\n const queued = bounded(this.#queued(), now);\n let index = 0;\n while (index < sent.length && queued[index] === sent[index]) index += 1;\n this.#writeQueue(queued.slice(index));\n return index;\n }) ?? 0\n );\n }\n\n #queued(): string[] {\n try {\n return readFileSync(this.queueFile, \"utf8\")\n .split(\"\\n\")\n .filter((line) => line.length > 0);\n } catch {\n return [];\n }\n }\n\n #writeQueue(lines: readonly string[]): void {\n if (lines.length === 0) {\n rmSync(this.queueFile, { force: true });\n return;\n }\n const temporary = `${this.queueFile}.${process.pid}.tmp`;\n writeFileSync(temporary, `${lines.join(\"\\n\")}\\n`, { mode: 0o600 });\n replace(temporary, this.queueFile, this.#platform);\n }\n\n #write(settings: TelemetrySettings): void {\n const { installId: _id, ...stored } = settings;\n const temporary = `${this.settingsFile}.${process.pid}.tmp`;\n writeFileSync(temporary, `${JSON.stringify(stored, null, 2)}\\n`, { mode: 0o600 });\n replace(temporary, this.settingsFile, this.#platform);\n }\n\n #prepareDir(): void {\n mkdirSync(this.dir, { recursive: true, mode: 0o700 });\n // Windows has no modes: the directory keeps the access list `%APPDATA%` hands down.\n if (this.#platform === \"win32\") return;\n try {\n chmodSync(this.dir, 0o700);\n } catch {\n // A directory someone else owns: the files below fail or succeed on their own terms.\n }\n }\n\n /**\n * Runs `fn` holding the lock file; `undefined` when the lock can't be had within 2 s, or the\n * directory or a file in it can't be written (a full disk, a directory someone else owns):\n * telemetry never stops a command (D140 item 5). The lock\n * holds its owner's PID and a token of its own, is released only by its owner, and is taken\n * over when it is older than 10 s and its owner is no longer running (a crash), or older than\n * 60 s whoever it names.\n */\n locked<T>(fn: () => T): T | undefined {\n try {\n this.#prepareDir();\n } catch {\n return undefined;\n }\n const token = `${process.pid} ${randomUUID()}`;\n const deadline = Date.now() + 2000;\n for (;;) {\n try {\n writeFileSync(this.#lockFile, token, { flag: \"wx\", mode: 0o600 });\n break;\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (!held(code, this.#platform)) return undefined;\n // Every path back to the create checks the deadline, so nothing can hold the CLI here\n // (GPT review of WP-W2), and only a lock that just went is tried again without a pause,\n // so nothing spins either (Opus review of WP-W2, finding 2).\n if (Date.now() > deadline) return undefined;\n const next = this.#breakStale();\n if (next === \"absent\") {\n // No lock there, though the create was refused. After `EEXIST` it was removed in\n // between: try again. After access denied, either a lock Windows was deleting went in\n // between (twelve processes at once keep that happening), or this user can't write the\n // directory and waiting changes nothing (Opus review of WP-W2, finding 2). A file of\n // this process's own tells which, whatever the timing (MT-01: a count of such rounds\n // in a row still gave up under contention).\n if (code === \"EEXIST\") continue;\n if (!writable(this.dir)) return undefined;\n } else if (next === \"broken\") continue;\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);\n }\n }\n try {\n return fn();\n } catch {\n return undefined;\n } finally {\n this.#release(token);\n }\n }\n\n /** Removes the lock when it is still this owner's. */\n #release(token: string): void {\n try {\n if (readFileSync(this.#lockFile, \"utf8\") === token) rmSync(this.#lockFile, { force: true });\n } catch {\n // Gone already.\n }\n }\n\n /**\n * Takes a crashed owner's lock away. The lock is moved aside under a name of this process's own\n * (a rename is atomic, so of two processes breaking it one gets it), and a lock that turns out\n * to be another, live owner's goes back. Answers `broken` when the caller should try again at\n * once, `absent` when no lock file exists, and `held` when the caller should wait: a live\n * owner's lock, or one that can't be read (on Windows, a lock being deleted).\n */\n #breakStale(): \"broken\" | \"absent\" | \"held\" {\n // One descriptor for the age and the contents, so both describe the same file.\n let seen: string;\n let age: number;\n let handle: number | undefined;\n try {\n handle = openSync(this.#lockFile, \"r\");\n age = Date.now() - fstatSync(handle).mtimeMs;\n if (age <= STALE_LOCK_MS) return \"held\";\n seen = readFileSync(handle, \"utf8\");\n } catch (error) {\n return (error as NodeJS.ErrnoException).code === \"ENOENT\" ? \"absent\" : \"held\";\n } finally {\n if (handle !== undefined) closeSync(handle);\n }\n if (age <= DEAD_LOCK_MS && ownerAlive(seen)) return \"held\";\n const aside = `${this.#lockFile}.${process.pid}.${randomUUID()}.stale`;\n try {\n renameSync(this.#lockFile, aside);\n } catch (error) {\n // Another breaker moved it first: try for it at once; anything else, wait.\n return (error as NodeJS.ErrnoException).code === \"ENOENT\" ? \"broken\" : \"held\";\n }\n try {\n if (readFileSync(aside, \"utf8\") !== seen) linkSync(aside, this.#lockFile);\n } catch {\n // Another process holds a new lock already; ours goes, and the caller waits for theirs.\n } finally {\n rmSync(aside, { force: true });\n }\n return \"broken\";\n }\n}\n\n/**\n * Renames `from` over `to`. Windows refuses to replace a file another process has open, as a\n * process reading the settings outside the lock does, with `EPERM` (MT-01: CI's install-ID race,\n * traced on `windows-latest`); the rename is tried again for up to a second, as the runtime's\n * renames are (D150 item 8), and never turned into a copy.\n */\nexport function replace(\n from: string,\n to: string,\n platform: string,\n rename: (from: string, to: string) => void = renameSync,\n): void {\n const deadline = Date.now() + 1000;\n for (let pause = 5; ; pause = Math.min(pause * 2, 100)) {\n try {\n rename(from, to);\n return;\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n const shared = code === \"EPERM\" || code === \"EACCES\" || code === \"EBUSY\";\n if (platform !== \"win32\" || !shared || Date.now() > deadline) throw error;\n Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, pause);\n }\n }\n}\n\n/** Whether this process can create a file in `dir`: a probe of its own, removed at once. */\nexport function writable(\n dir: string,\n remove: (path: string) => void = (path) => rmSync(path, { force: true }),\n): boolean {\n const probe = join(dir, `.probe-${process.pid}-${randomUUID()}`);\n try {\n writeFileSync(probe, \"\", { flag: \"wx\", mode: 0o600 });\n } catch {\n return false;\n }\n // The probe was made, so the directory is writable whatever its removal meets: on Windows an\n // antivirus or the indexer may hold the new file for a moment (EBUSY, EPERM), and telemetry never\n // stops a command (D140 item 5; Opus review of MT-01, 8). An empty probe left behind is harmless.\n try {\n remove(probe);\n } catch {\n // Left for the next probe's directory to carry; nothing reads it.\n }\n return true;\n}\n\n/**\n * Whether a lock's exclusive create failed because another process holds it. On Windows a lock\n * its owner just removed stays \"delete pending\" while anyone still has it open (another process\n * judging its age), and creating it again meanwhile is refused as access denied, not `EEXIST`\n * (WP-W2: twelve first runs at once on an arm64 runner): that is contention too, never a reason\n * to give up.\n */\nfunction held(code: string | undefined, platform: string): boolean {\n return code === \"EEXIST\" || (platform === \"win32\" && (code === \"EPERM\" || code === \"EACCES\"));\n}\n\n/** Whether `dir` can never be created: its nearest existing ancestor isn't a directory. */\nfunction blocked(dir: string): boolean {\n for (let path = dir; ; path = dirname(path)) {\n try {\n return !statSync(path).isDirectory();\n } catch (error) {\n const code = (error as NodeJS.ErrnoException).code;\n if (code === \"ENOTDIR\") return true;\n if (code !== \"ENOENT\") return false;\n }\n if (dirname(path) === path) return false;\n }\n}\n\n/** Whether the process a lock names still runs; a lock whose owner can't be read counts as live. */\nfunction ownerAlive(lock: string): boolean {\n const pid = Number(lock.split(\" \")[0]);\n if (!Number.isSafeInteger(pid) || pid <= 0) return false;\n try {\n process.kill(pid, 0);\n return true;\n } catch (error) {\n return (error as NodeJS.ErrnoException).code === \"EPERM\";\n }\n}\n\n/** The newest events within 1,000, none older than 7 days; lines that aren't JSON go. */\nfunction bounded(lines: readonly string[], now: number): string[] {\n const fresh = lines.filter((line) => {\n try {\n const at = Date.parse((JSON.parse(line) as { at?: string }).at ?? \"\");\n return Number.isFinite(at) && now - at <= QUEUE_MAX_AGE_MS;\n } catch {\n return false;\n }\n });\n return fresh.slice(-QUEUE_MAX_EVENTS);\n}\n","/**\n * Sending the queue (D140 item 6): a detached process the CLI starts after a command, at most one\n * at a time and at most once a minute. It reads the decision again before it sends, so consent\n * withdrawn in between drops the events; it posts at most 100 events per request with no header\n * but `Content-Type`, `User-Agent` and the ones HTTP itself needs, and keeps what a failed\n * attempt couldn't send for the next flush.\n */\n\nimport { spawn } from \"node:child_process\";\nimport { request as httpRequest } from \"node:http\";\nimport { request as httpsRequest } from \"node:https\";\nimport { join } from \"node:path\";\nimport { detachedDirectory, detachedEnvironment } from \"../detached.ts\";\nimport type { Environment } from \"../home.ts\";\nimport { cliVersion, fromSource, packageRoot } from \"../version.ts\";\nimport { buildEndpoint, decide } from \"./decision.ts\";\nimport { TelemetryEvent } from \"./events.ts\";\nimport { QUEUE_MAX_EVENTS, type TelemetryStore } from \"./store.ts\";\n\n/** At most this many events per request. */\nexport const BATCH = 100;\n/** A flush starts at most this often. */\nexport const FLUSH_INTERVAL_MS = 60_000;\n/** The flush interval; `MOSTRA_TEST_FLUSH_INTERVAL_MS` shortens it, for tests only. */\nfunction flushInterval(env: Environment): number {\n const test = Number(env[\"MOSTRA_TEST_FLUSH_INTERVAL_MS\"]);\n return Number.isInteger(test) && test >= 0 && test < FLUSH_INTERVAL_MS ? test : FLUSH_INTERVAL_MS;\n}\n\n/** One request's limit. */\nconst REQUEST_TIMEOUT_MS = 5000;\n\n/** Posts one batch; resolves with whether the collector took it (any 2xx). */\nexport function post(endpoint: string, body: string): Promise<boolean> {\n return new Promise((resolve) => {\n const url = new URL(endpoint);\n const send = url.protocol === \"https:\" ? httpsRequest : httpRequest;\n const req = send(\n url,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"User-Agent\": `mostra-cli/${cliVersion()}`,\n \"Content-Length\": Buffer.byteLength(body),\n },\n timeout: REQUEST_TIMEOUT_MS,\n },\n (response) => {\n response.resume();\n response.on(\"end\", () =>\n resolve((response.statusCode ?? 0) >= 200 && (response.statusCode ?? 0) < 300),\n );\n response.on(\"error\", () => resolve(false));\n },\n );\n req.on(\"timeout\", () => req.destroy());\n req.on(\"error\", () => resolve(false));\n req.end(body);\n });\n}\n\n/**\n * Sends the queue: the decision again, then batches until one fails. Events the schema refuses\n * never leave the machine.\n */\nexport async function flush(\n store: TelemetryStore,\n env: Environment,\n now: () => number,\n): Promise<void> {\n const settings = store.read();\n // The queue holds only events of uses that aren't embedded; the rest of the order applies again.\n const decision = decide({\n env,\n buildEndpoint: buildEndpoint(),\n embedded: false,\n settings,\n askFirst: false,\n });\n if (!decision.enabled || decision.endpoint === undefined) {\n // Consent withdrawn (or never given) since the events were queued: they go unsent.\n if (decision.reason !== \"no-collector\" && settings.ok) store.drop(store.queued(now()), now());\n return;\n }\n // The queue holds at most QUEUE_MAX_EVENTS, so a flush needs at most this many batches.\n for (let round = 0; round <= Math.ceil(QUEUE_MAX_EVENTS / BATCH); round += 1) {\n const lines = store.queued(now()).slice(0, BATCH);\n if (lines.length === 0) return;\n const events: unknown[] = [];\n for (const line of lines) {\n try {\n const parsed = TelemetryEvent.safeParse(JSON.parse(line));\n if (parsed.success) events.push(parsed.data);\n } catch {\n // Not an event: dropped with the batch.\n }\n }\n const sent = events.length === 0 || (await post(decision.endpoint, JSON.stringify({ events })));\n if (!sent) return;\n // Nothing removed (another process changed the queue, or the lock was out of reach): stop\n // rather than send the same batch again.\n if (store.drop(lines, now()) === 0) return;\n }\n}\n\n/** The flusher's entry in the CLI's package. */\nfunction flusherEntry(): { readonly entry: string; readonly nodeArgs: readonly string[] } {\n const root = packageRoot();\n return fromSource()\n ? {\n entry: join(root, \"src\", \"telemetry\", \"flush-main.ts\"),\n nodeArgs: [\"--conditions=@mostra/source\"],\n }\n : { entry: join(root, \"dist\", \"telemetry\", \"flush-main.js\"), nodeArgs: [] };\n}\n\n/**\n * Starts a flusher when the queue has events and no flush started in the last minute, fully\n * detached: no stdio, its own process group, never waited for, so `mostra … | jq` and every\n * harness reading to end of file finish when the command does.\n */\nexport function startFlusher(store: TelemetryStore, env: Environment, now: number): void {\n if (store.queued(now).length === 0) return;\n let due = false;\n store.update((current) => {\n const last = current.lastFlushAt === undefined ? 0 : Date.parse(current.lastFlushAt);\n if (Number.isFinite(last) && now - last < flushInterval(env)) return current;\n due = true;\n return { ...current, lastFlushAt: new Date(now).toISOString() };\n });\n if (!due) return;\n const { entry, nodeArgs } = flusherEntry();\n try {\n const child = spawn(process.execPath, [...nodeArgs, entry, store.dir], {\n detached: true,\n stdio: \"ignore\",\n // Not the command's directory but its file system's root, which always exists: on Windows\n // a process's working directory can't be removed or renamed while it runs, and the flusher\n // outlives the command (WP-W2).\n cwd: detachedDirectory(store.dir),\n env: detachedEnvironment({ ...process.env, ...env }) as NodeJS.ProcessEnv,\n });\n child.on(\"error\", () => {});\n child.unref();\n } catch {\n // Telemetry never changes a command's outcome.\n }\n}\n"],"mappings":";;;;;;;;;;;AAKA,IAAI;AAEJ,SAAS,MAA2D;CAClE,IAAI,OAAO,OAAO;CAClB,IAAI,MAAM,QAAQ,cAAc,YAAY,GAAG,CAAC;CAChD,SAAS;EACP,IAAI;GACF,MAAM,WAAW,KAAK,MAAM,aAAa,KAAK,KAAK,cAAc,GAAG,MAAM,CAAC;GAI3E,IAAI,SAAS,SAAS,iBAAiB,SAAS,SAAS;IACvD,QAAQ;KAAE,MAAM;KAAK,SAAS,SAAS;IAAQ;IAC/C,OAAO;GACT;EACF,QAAQ,CAER;EACA,MAAM,SAAS,QAAQ,GAAG;EAC1B,IAAI,WAAW,KAAK,MAAM,IAAI,MAAM,2CAA2C;EAC/E,MAAM;CACR;AACF;;AAGA,SAAgB,aAAqB;CACnC,OAAO,IAAI,CAAC,CAAC;AACf;;AAGA,SAAgB,cAAsB;CACpC,OAAO,IAAI,CAAC,CAAC;AACf;;AAGA,SAAgB,aAAsB;CACpC,OAAO,YAAY,IAAI,S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