@treestructuredplanning/gateway 0.3.0 → 0.3.2
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/cli.js +239 -110
- package/dist/{shared-KRIZBGVD.js → shared-SSP3A5QQ.js} +651 -387
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire } from "node:module"; const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// ../tsp-shared/src/generated/constants.ts
|
|
4
|
-
var GATEWAY_PACKAGE_VERSION = "0.3.
|
|
4
|
+
var GATEWAY_PACKAGE_VERSION = "0.3.2";
|
|
5
5
|
var GATEWAY_PROTOCOL_VERSION = 3;
|
|
6
6
|
var SESSION_ACTIVITY_COUNT_MAX = 1e6;
|
|
7
7
|
var AGENT_SESSION_STATE = {
|
|
@@ -381,8 +381,8 @@ function decodeRegistration(value) {
|
|
|
381
381
|
throw new Error("Invalid machine hub path");
|
|
382
382
|
return registration;
|
|
383
383
|
}
|
|
384
|
-
function parseJson(
|
|
385
|
-
return JSON.parse(
|
|
384
|
+
function parseJson(text5) {
|
|
385
|
+
return JSON.parse(text5);
|
|
386
386
|
}
|
|
387
387
|
function decodeHubText(data) {
|
|
388
388
|
if (typeof data !== "string" || data.length > 131072) throw new Error("Invalid frame");
|
|
@@ -430,19 +430,19 @@ function opaque(value) {
|
|
|
430
430
|
}
|
|
431
431
|
var WAITING_FOR_MAX_LENGTH = 4e3;
|
|
432
432
|
var LAST_MESSAGE_MAX_LENGTH = 240;
|
|
433
|
-
function sanitizeWords(
|
|
433
|
+
function sanitizeWords(text5, maxLength) {
|
|
434
434
|
return [
|
|
435
|
-
...
|
|
435
|
+
...text5.replace(
|
|
436
436
|
/(?:\\\\[?.]\\|\\\?\?\\|\\\\|[A-Za-z]:[\\/]|~?\/|\.\.?\/)[^\s"'<>]+/g,
|
|
437
437
|
"[local path]"
|
|
438
438
|
).split("").map((char) => char.charCodeAt(0) < 32 || char.charCodeAt(0) === 127 ? " " : char).join("")
|
|
439
439
|
].slice(0, maxLength).join("");
|
|
440
440
|
}
|
|
441
|
-
function sanitizeWaiting(
|
|
442
|
-
return sanitizeWords(
|
|
441
|
+
function sanitizeWaiting(text5) {
|
|
442
|
+
return sanitizeWords(text5, WAITING_FOR_MAX_LENGTH);
|
|
443
443
|
}
|
|
444
|
-
function sanitizeLastMessage(
|
|
445
|
-
return sanitizeWords(
|
|
444
|
+
function sanitizeLastMessage(text5) {
|
|
445
|
+
return sanitizeWords(text5, LAST_MESSAGE_MAX_LENGTH);
|
|
446
446
|
}
|
|
447
447
|
var STARTUP_GRACE_MS = 1e4;
|
|
448
448
|
function backgroundSession(row) {
|
|
@@ -701,8 +701,8 @@ var ShellOutput = class {
|
|
|
701
701
|
return output;
|
|
702
702
|
}
|
|
703
703
|
};
|
|
704
|
-
function decodeEnvironment(
|
|
705
|
-
const value = parseJson(
|
|
704
|
+
function decodeEnvironment(text5) {
|
|
705
|
+
const value = parseJson(text5);
|
|
706
706
|
if (!isObject(value)) throw new Error("Invalid shell environment capture");
|
|
707
707
|
const env = {};
|
|
708
708
|
for (const name of Object.keys(value)) {
|
|
@@ -1073,11 +1073,11 @@ function decodeStoredSessions(result) {
|
|
|
1073
1073
|
function heldRequestText(params) {
|
|
1074
1074
|
if (!isObject(params)) return null;
|
|
1075
1075
|
const toolCall = field(params, "toolCall");
|
|
1076
|
-
for (const
|
|
1077
|
-
if (!
|
|
1076
|
+
for (const source of [isObject(toolCall) ? toolCall : null, params]) {
|
|
1077
|
+
if (!source) continue;
|
|
1078
1078
|
for (const key of ["title", "question", "name"]) {
|
|
1079
|
-
const
|
|
1080
|
-
if (typeof
|
|
1079
|
+
const text5 = field(source, key);
|
|
1080
|
+
if (typeof text5 === "string" && text5.trim()) return text5.trim();
|
|
1081
1081
|
}
|
|
1082
1082
|
}
|
|
1083
1083
|
return null;
|
|
@@ -1252,11 +1252,11 @@ var AcpConnection = class _AcpConnection {
|
|
|
1252
1252
|
const error = field(message, "error");
|
|
1253
1253
|
if (isObject(error)) {
|
|
1254
1254
|
const code = field(error, "code");
|
|
1255
|
-
const
|
|
1255
|
+
const text5 = field(error, "message");
|
|
1256
1256
|
request.reject(
|
|
1257
1257
|
new AcpRpcError(
|
|
1258
1258
|
typeof code === "number" ? code : -32603,
|
|
1259
|
-
typeof
|
|
1259
|
+
typeof text5 === "string" ? text5 : "ACP request failed"
|
|
1260
1260
|
)
|
|
1261
1261
|
);
|
|
1262
1262
|
} else request.resolve(field(message, "result"));
|
|
@@ -1353,8 +1353,8 @@ var BETWEEN_UPDATES = /* @__PURE__ */ new Set([
|
|
|
1353
1353
|
]);
|
|
1354
1354
|
function messageText(update) {
|
|
1355
1355
|
const content = field(update, "content");
|
|
1356
|
-
const
|
|
1357
|
-
return typeof
|
|
1356
|
+
const text5 = isObject(content) && field(content, "type") === "text" ? field(content, "text") : null;
|
|
1357
|
+
return typeof text5 === "string" ? text5 : "";
|
|
1358
1358
|
}
|
|
1359
1359
|
var AcpSession = class {
|
|
1360
1360
|
constructor(id, name, folder) {
|
|
@@ -1449,8 +1449,8 @@ var AcpSession = class {
|
|
|
1449
1449
|
}
|
|
1450
1450
|
/** The turn's last words, only for a finished turn, as the owner's canvas shows them. */
|
|
1451
1451
|
lastMessage() {
|
|
1452
|
-
const
|
|
1453
|
-
return this.state === "done" &&
|
|
1452
|
+
const text5 = sanitizeLastMessage(this.said.replace(/\s+/g, " ").trim());
|
|
1453
|
+
return this.state === "done" && text5 ? text5 : void 0;
|
|
1454
1454
|
}
|
|
1455
1455
|
async snapshot(activityRoot) {
|
|
1456
1456
|
return {
|
|
@@ -1484,15 +1484,15 @@ var AcpDriver = class {
|
|
|
1484
1484
|
this.timeouts = timeouts;
|
|
1485
1485
|
this.groups = groups;
|
|
1486
1486
|
this.displayName = agent.displayName;
|
|
1487
|
-
this.
|
|
1488
|
-
this.
|
|
1487
|
+
this.signInStep = agent.signInStep;
|
|
1488
|
+
this.installStep = agent.installStep;
|
|
1489
1489
|
this.unknownTrustAdmits = agent.unknownTrustAdmits;
|
|
1490
1490
|
this.repositorySetup = (folder) => agent.repositorySetup(folder);
|
|
1491
1491
|
this.hold = /* @__PURE__ */ new Set([ACP_PERMISSION_METHOD, ...agent.holdMethods]);
|
|
1492
1492
|
}
|
|
1493
1493
|
displayName;
|
|
1494
|
-
|
|
1495
|
-
|
|
1494
|
+
signInStep;
|
|
1495
|
+
installStep;
|
|
1496
1496
|
unknownTrustAdmits;
|
|
1497
1497
|
repositorySetup;
|
|
1498
1498
|
sessions = /* @__PURE__ */ new Map();
|
|
@@ -1566,14 +1566,14 @@ var AcpDriver = class {
|
|
|
1566
1566
|
return session;
|
|
1567
1567
|
}
|
|
1568
1568
|
/** Sends one prompt without waiting for its turn, which ends through `settle`. */
|
|
1569
|
-
beginTurn(session, connection,
|
|
1569
|
+
beginTurn(session, connection, text5, check) {
|
|
1570
1570
|
check();
|
|
1571
1571
|
session.beginTurn(connection);
|
|
1572
1572
|
connection.onUpdate = (params) => session.observe(params);
|
|
1573
1573
|
connection.onHeldChange = () => session.holding(connection.held);
|
|
1574
1574
|
void connection.request(
|
|
1575
1575
|
"session/prompt",
|
|
1576
|
-
{ sessionId: session.id, prompt: [{ type: "text", text:
|
|
1576
|
+
{ sessionId: session.id, prompt: [{ type: "text", text: text5 }] },
|
|
1577
1577
|
{ timeoutMs: null }
|
|
1578
1578
|
).then((result) => decodeStopReason(result)).then(
|
|
1579
1579
|
(reason) => this.settle(session, connection, reason),
|
|
@@ -1597,7 +1597,7 @@ var AcpDriver = class {
|
|
|
1597
1597
|
);
|
|
1598
1598
|
await connection.close();
|
|
1599
1599
|
}
|
|
1600
|
-
async start(
|
|
1600
|
+
async start(command2, folder, requireLive, checkpoint) {
|
|
1601
1601
|
await this.requireTrusted(folder);
|
|
1602
1602
|
const connection = await this.connect(folder, requireLive);
|
|
1603
1603
|
try {
|
|
@@ -1609,21 +1609,21 @@ var AcpDriver = class {
|
|
|
1609
1609
|
)
|
|
1610
1610
|
);
|
|
1611
1611
|
await checkpoint?.(id);
|
|
1612
|
-
const session = this.register(id,
|
|
1613
|
-
this.beginTurn(session, connection,
|
|
1612
|
+
const session = this.register(id, command2.session_name, folder);
|
|
1613
|
+
this.beginTurn(session, connection, command2.seed, promptCheck(requireLive));
|
|
1614
1614
|
return id;
|
|
1615
1615
|
} catch (error) {
|
|
1616
1616
|
await connection.close();
|
|
1617
1617
|
throw error;
|
|
1618
1618
|
}
|
|
1619
1619
|
}
|
|
1620
|
-
async reconcileLaunch(ref,
|
|
1620
|
+
async reconcileLaunch(ref, command2, folder, requireLive, beforeSeed) {
|
|
1621
1621
|
const known = this.sessions.get(ref);
|
|
1622
1622
|
if (known?.seeded) return known.snapshot();
|
|
1623
1623
|
const connection = await this.connect(folder, requireLive);
|
|
1624
1624
|
try {
|
|
1625
1625
|
if (!connection.capabilities.loadSession) throw new HarnessRefusal("start_uncertain");
|
|
1626
|
-
const session = known ?? this.register(ref,
|
|
1626
|
+
const session = known ?? this.register(ref, command2.session_name, folder);
|
|
1627
1627
|
const seeded = await this.load(session, connection, folder, requireLive);
|
|
1628
1628
|
if (seeded !== false) {
|
|
1629
1629
|
if (seeded) session.endedWithGateway();
|
|
@@ -1634,7 +1634,7 @@ var AcpDriver = class {
|
|
|
1634
1634
|
await this.requireTrusted(folder);
|
|
1635
1635
|
if (!inside(await realpath2(await beforeSeed()), await realpath2(folder)))
|
|
1636
1636
|
throw new HarnessRefusal("start_uncertain");
|
|
1637
|
-
this.beginTurn(session, connection,
|
|
1637
|
+
this.beginTurn(session, connection, command2.seed, promptCheck(requireLive));
|
|
1638
1638
|
return session.snapshot();
|
|
1639
1639
|
} catch (error) {
|
|
1640
1640
|
await connection.close();
|
|
@@ -1726,7 +1726,7 @@ var AcpDriver = class {
|
|
|
1726
1726
|
if (ended === false && running3.connection === connection) running3.finish("stopped");
|
|
1727
1727
|
await connection.close();
|
|
1728
1728
|
}
|
|
1729
|
-
async resume(session,
|
|
1729
|
+
async resume(session, text5, folder, requireLive) {
|
|
1730
1730
|
if (session.state === "working" || session.state === "needs_input")
|
|
1731
1731
|
throw new HarnessRefusal("already_running");
|
|
1732
1732
|
const detected = await this.detect(folder);
|
|
@@ -1736,7 +1736,7 @@ var AcpDriver = class {
|
|
|
1736
1736
|
if (!this.loadSession) throw new HarnessRefusal("unsupported_command");
|
|
1737
1737
|
const record = this.register(session.id, session.name, folder);
|
|
1738
1738
|
if (record.connection) throw new HarnessRefusal("unsupported_command");
|
|
1739
|
-
const prompt =
|
|
1739
|
+
const prompt = text5 ?? (session.state === "stopped" ? RESUME_CONTINUATION : null);
|
|
1740
1740
|
const connection = await this.connect(folder, requireLive);
|
|
1741
1741
|
try {
|
|
1742
1742
|
if (await this.load(record, connection, folder, requireLive) === void 0)
|
|
@@ -1819,10 +1819,10 @@ function decodeVariables(env) {
|
|
|
1819
1819
|
if (!isObject(env)) throw new Error("launch.env must contain string variables");
|
|
1820
1820
|
const variables = {};
|
|
1821
1821
|
for (const name of Object.keys(env)) {
|
|
1822
|
-
const
|
|
1823
|
-
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || !text(
|
|
1822
|
+
const entry2 = field(env, name);
|
|
1823
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name) || !text(entry2))
|
|
1824
1824
|
throw new Error("launch.env must contain valid names and NUL-free string values");
|
|
1825
|
-
Object.defineProperty(variables, name, { value:
|
|
1825
|
+
Object.defineProperty(variables, name, { value: entry2, enumerable: true });
|
|
1826
1826
|
}
|
|
1827
1827
|
return variables;
|
|
1828
1828
|
}
|
|
@@ -1857,9 +1857,9 @@ async function privateWrite(path, value) {
|
|
|
1857
1857
|
await rename(temporary, path);
|
|
1858
1858
|
}
|
|
1859
1859
|
async function readConfig(path) {
|
|
1860
|
-
let
|
|
1860
|
+
let text5;
|
|
1861
1861
|
try {
|
|
1862
|
-
|
|
1862
|
+
text5 = await readFile(path, "utf8");
|
|
1863
1863
|
} catch (error) {
|
|
1864
1864
|
if (isObject(error) && field(error, "code") === "ENOENT")
|
|
1865
1865
|
return {
|
|
@@ -1872,7 +1872,7 @@ async function readConfig(path) {
|
|
|
1872
1872
|
};
|
|
1873
1873
|
throw error;
|
|
1874
1874
|
}
|
|
1875
|
-
const value = parseJson(
|
|
1875
|
+
const value = parseJson(text5);
|
|
1876
1876
|
if (!isObject(value) || Object.keys(value).some(
|
|
1877
1877
|
(key) => ![
|
|
1878
1878
|
"repositories",
|
|
@@ -1948,7 +1948,7 @@ async function registerFolder(folder, env = process.env) {
|
|
|
1948
1948
|
}
|
|
1949
1949
|
function repositoryFolders(config) {
|
|
1950
1950
|
return Object.fromEntries(
|
|
1951
|
-
Object.entries(config.repositories).map(([key,
|
|
1951
|
+
Object.entries(config.repositories).map(([key, entry2]) => [key, entry2.folder])
|
|
1952
1952
|
);
|
|
1953
1953
|
}
|
|
1954
1954
|
function decodeRepositories(value, repositories) {
|
|
@@ -1959,18 +1959,18 @@ function decodeRepositories(value, repositories) {
|
|
|
1959
1959
|
const map = {};
|
|
1960
1960
|
let upgraded = worktrees === void 0;
|
|
1961
1961
|
for (const slug of Object.keys(repositories)) {
|
|
1962
|
-
const
|
|
1963
|
-
const folder = typeof
|
|
1964
|
-
if (isObject(
|
|
1962
|
+
const entry2 = field(repositories, slug);
|
|
1963
|
+
const folder = typeof entry2 === "string" ? entry2 : isObject(entry2) ? field(entry2, "folder") : null;
|
|
1964
|
+
if (isObject(entry2) && Object.keys(entry2).some((key) => !["folder", "worktreeRoot"].includes(key)))
|
|
1965
1965
|
throw new Error("Invalid repository registry");
|
|
1966
|
-
upgraded ||= typeof
|
|
1966
|
+
upgraded ||= typeof entry2 === "string";
|
|
1967
1967
|
if (typeof folder !== "string" || !isAbsolute6(folder))
|
|
1968
1968
|
throw new Error("Invalid repository registry");
|
|
1969
1969
|
decodeWorktreeRoot(root, folder);
|
|
1970
1970
|
map[repositoryKey(storedRepository(slug))] = {
|
|
1971
1971
|
folder,
|
|
1972
1972
|
worktreeRoot: decodeWorktreeRoot(
|
|
1973
|
-
isObject(
|
|
1973
|
+
isObject(entry2) ? field(entry2, "worktreeRoot") : null,
|
|
1974
1974
|
folder
|
|
1975
1975
|
)
|
|
1976
1976
|
};
|
|
@@ -2147,9 +2147,9 @@ var ClaudeTranscripts = class {
|
|
|
2147
2147
|
if (await exists(expected)) return expected;
|
|
2148
2148
|
if (this.now() - cursor.searchedAt < SEARCH_INTERVAL_MS) return null;
|
|
2149
2149
|
cursor.searchedAt = this.now();
|
|
2150
|
-
for (const
|
|
2151
|
-
if (!
|
|
2152
|
-
const candidate = join4(projects,
|
|
2150
|
+
for (const entry2 of await readdir(projects, { withFileTypes: true })) {
|
|
2151
|
+
if (!entry2.isDirectory()) continue;
|
|
2152
|
+
const candidate = join4(projects, entry2.name, file);
|
|
2153
2153
|
if (await exists(candidate)) return candidate;
|
|
2154
2154
|
}
|
|
2155
2155
|
return null;
|
|
@@ -2177,9 +2177,9 @@ var ClaudeTranscripts = class {
|
|
|
2177
2177
|
cursor.remainder = data.length > LINE_LIMIT_BYTES ? Buffer.alloc(0) : Buffer.from(data);
|
|
2178
2178
|
}
|
|
2179
2179
|
entry(conversationId, tally, line) {
|
|
2180
|
-
const
|
|
2181
|
-
if (!
|
|
2182
|
-
const { role, content, at } =
|
|
2180
|
+
const entry2 = parseEntry(line);
|
|
2181
|
+
if (!entry2) return;
|
|
2182
|
+
const { role, content, at } = entry2;
|
|
2183
2183
|
if (typeof content === "string") {
|
|
2184
2184
|
if (role === "user") {
|
|
2185
2185
|
tally.stepped(at);
|
|
@@ -2608,8 +2608,11 @@ var ClaudeDriver = class {
|
|
|
2608
2608
|
};
|
|
2609
2609
|
}
|
|
2610
2610
|
displayName = "Claude Code";
|
|
2611
|
-
|
|
2612
|
-
|
|
2611
|
+
signInStep = { instruction: "Run claude and sign in.", command: "claude" };
|
|
2612
|
+
installStep = {
|
|
2613
|
+
instruction: "Install it, then run connect again.",
|
|
2614
|
+
link: "https://code.claude.com/docs/en/setup"
|
|
2615
|
+
};
|
|
2613
2616
|
unknownTrustAdmits = true;
|
|
2614
2617
|
capabilities = {
|
|
2615
2618
|
start: true,
|
|
@@ -2656,11 +2659,11 @@ var ClaudeDriver = class {
|
|
|
2656
2659
|
};
|
|
2657
2660
|
}
|
|
2658
2661
|
}
|
|
2659
|
-
async start(
|
|
2662
|
+
async start(command2, folder, requireLive) {
|
|
2660
2663
|
const seeding = promptCheck(requireLive);
|
|
2661
2664
|
seeding();
|
|
2662
2665
|
const result = await this.call(
|
|
2663
|
-
["--bg", "--name",
|
|
2666
|
+
["--bg", "--name", command2.session_name, "--", command2.seed],
|
|
2664
2667
|
folder,
|
|
2665
2668
|
"launch",
|
|
2666
2669
|
seeding
|
|
@@ -2789,7 +2792,7 @@ var ClaudeDriver = class {
|
|
|
2789
2792
|
);
|
|
2790
2793
|
if (result.code !== 0) throw new HarnessRefusal("stop_failed");
|
|
2791
2794
|
}
|
|
2792
|
-
async resume(session,
|
|
2795
|
+
async resume(session, text5, folder, requireLive) {
|
|
2793
2796
|
if (session.state === "working" || session.state === "needs_input")
|
|
2794
2797
|
throw new HarnessRefusal("already_running");
|
|
2795
2798
|
if (session.pid !== null) {
|
|
@@ -2803,7 +2806,7 @@ var ClaudeDriver = class {
|
|
|
2803
2806
|
}
|
|
2804
2807
|
await this.executor.environment(true, folder);
|
|
2805
2808
|
if (await this.signedIn(folder) === false) throw new HarnessRefusal("not_signed_in");
|
|
2806
|
-
const prompt =
|
|
2809
|
+
const prompt = text5 ?? (session.state === "stopped" ? RESUME_CONTINUATION : null);
|
|
2807
2810
|
const resuming = promptCheck(requireLive);
|
|
2808
2811
|
resuming();
|
|
2809
2812
|
const result = await this.call(
|
|
@@ -2962,8 +2965,8 @@ function requestWords(params) {
|
|
|
2962
2965
|
function lastAgentMessage(page2) {
|
|
2963
2966
|
const data = isObject(page2) ? field(page2, "data") : null;
|
|
2964
2967
|
if (!Array.isArray(data)) return null;
|
|
2965
|
-
for (const
|
|
2966
|
-
const item = isObject(
|
|
2968
|
+
for (const entry2 of data) {
|
|
2969
|
+
const item = isObject(entry2) ? field(entry2, "item") : null;
|
|
2967
2970
|
if (isObject(item) && field(item, "type") === "agentMessage") {
|
|
2968
2971
|
const said2 = text3(field(item, "text"));
|
|
2969
2972
|
if (said2) return said2;
|
|
@@ -3060,14 +3063,14 @@ var CodexActivity = class {
|
|
|
3060
3063
|
throw new Error("Unrecognised Codex item page");
|
|
3061
3064
|
let reachedSettled = false;
|
|
3062
3065
|
for (const raw of field(response, "data")) {
|
|
3063
|
-
const
|
|
3064
|
-
if (!
|
|
3065
|
-
if (thread.settled.has(
|
|
3066
|
+
const entry2 = entryOf(raw);
|
|
3067
|
+
if (!entry2) continue;
|
|
3068
|
+
if (thread.settled.has(entry2.id)) {
|
|
3066
3069
|
reachedSettled = true;
|
|
3067
3070
|
continue;
|
|
3068
3071
|
}
|
|
3069
|
-
unseen.delete(
|
|
3070
|
-
entries.push(
|
|
3072
|
+
unseen.delete(entry2.id);
|
|
3073
|
+
entries.push(entry2);
|
|
3071
3074
|
}
|
|
3072
3075
|
const next = field(response, "nextCursor");
|
|
3073
3076
|
cursor = typeof next === "string" && next ? next : null;
|
|
@@ -3078,7 +3081,7 @@ var CodexActivity = class {
|
|
|
3078
3081
|
thread.commands.delete(id);
|
|
3079
3082
|
thread.tally.finished(id);
|
|
3080
3083
|
}
|
|
3081
|
-
for (const
|
|
3084
|
+
for (const entry2 of entries.reverse()) this.apply(thread, entry2);
|
|
3082
3085
|
return thread.tally.snapshot(root);
|
|
3083
3086
|
}
|
|
3084
3087
|
apply(thread, { id, item, status, at, completed }) {
|
|
@@ -3461,12 +3464,12 @@ async function* threads(server, folder, query) {
|
|
|
3461
3464
|
sourceKinds: ["cli", "vscode", "appServer"]
|
|
3462
3465
|
})
|
|
3463
3466
|
) : loadedThreadPage(await server.request(method, { cursor, limit: 100 }));
|
|
3464
|
-
for (const
|
|
3465
|
-
const id = typeof
|
|
3467
|
+
for (const entry2 of page2.threads) {
|
|
3468
|
+
const id = typeof entry2 === "string" ? entry2 : entry2.id;
|
|
3466
3469
|
if (seen.has(id)) continue;
|
|
3467
3470
|
seen.add(id);
|
|
3468
|
-
if (typeof
|
|
3469
|
-
yield
|
|
3471
|
+
if (typeof entry2 !== "string") {
|
|
3472
|
+
yield entry2;
|
|
3470
3473
|
continue;
|
|
3471
3474
|
}
|
|
3472
3475
|
try {
|
|
@@ -3536,7 +3539,7 @@ async function listCodexSessions(server, folder, query, activity) {
|
|
|
3536
3539
|
// src/codex-driver.ts
|
|
3537
3540
|
var MINIMUM_CODEX_VERSION = "0.162.1";
|
|
3538
3541
|
function supportedCodexVersion(version) {
|
|
3539
|
-
const parts = (
|
|
3542
|
+
const parts = (text5) => (text5.split(/[-+]/)[0] ?? "").split(".").map(Number);
|
|
3540
3543
|
if (!version) return true;
|
|
3541
3544
|
const found = parts(version), minimum = parts(MINIMUM_CODEX_VERSION);
|
|
3542
3545
|
for (const [index, part] of minimum.entries()) {
|
|
@@ -3557,18 +3560,18 @@ async function discardThread(server, threadId) {
|
|
|
3557
3560
|
} catch {
|
|
3558
3561
|
}
|
|
3559
3562
|
}
|
|
3560
|
-
async function seedThread(server, thread,
|
|
3561
|
-
if (thread.name !==
|
|
3563
|
+
async function seedThread(server, thread, command2, requireLive) {
|
|
3564
|
+
if (thread.name !== command2.session_name)
|
|
3562
3565
|
await server.request(
|
|
3563
3566
|
"thread/name/set",
|
|
3564
|
-
{ threadId: thread.id, name:
|
|
3567
|
+
{ threadId: thread.id, name: command2.session_name },
|
|
3565
3568
|
requireLive
|
|
3566
3569
|
);
|
|
3567
3570
|
await server.request(
|
|
3568
3571
|
"turn/start",
|
|
3569
3572
|
{
|
|
3570
3573
|
threadId: thread.id,
|
|
3571
|
-
input: [{ type: "text", text:
|
|
3574
|
+
input: [{ type: "text", text: command2.seed, text_elements: [] }]
|
|
3572
3575
|
},
|
|
3573
3576
|
promptCheck(requireLive)
|
|
3574
3577
|
);
|
|
@@ -3587,8 +3590,11 @@ var CodexDriver = class {
|
|
|
3587
3590
|
};
|
|
3588
3591
|
}
|
|
3589
3592
|
displayName = "Codex";
|
|
3590
|
-
|
|
3591
|
-
|
|
3593
|
+
signInStep = { instruction: "Run codex login and sign in.", command: "codex login" };
|
|
3594
|
+
installStep = {
|
|
3595
|
+
instruction: `Install Codex ${MINIMUM_CODEX_VERSION} or newer, then run connect again.`,
|
|
3596
|
+
link: "https://developers.openai.com/codex/cli"
|
|
3597
|
+
};
|
|
3592
3598
|
/** Codex refuses a folder it has no trust record for, so unknown trust is a step to take. */
|
|
3593
3599
|
unknownTrustAdmits = false;
|
|
3594
3600
|
capabilities = {
|
|
@@ -3630,8 +3636,8 @@ var CodexDriver = class {
|
|
|
3630
3636
|
"read",
|
|
3631
3637
|
folder
|
|
3632
3638
|
);
|
|
3633
|
-
const
|
|
3634
|
-
detection.signed_in = /not logged in/i.test(
|
|
3639
|
+
const text5 = login.stdout + login.stderr;
|
|
3640
|
+
detection.signed_in = /not logged in/i.test(text5) ? false : login.code === 0 && /logged in/i.test(text5) ? true : null;
|
|
3635
3641
|
}
|
|
3636
3642
|
} catch {
|
|
3637
3643
|
}
|
|
@@ -3688,7 +3694,7 @@ var CodexDriver = class {
|
|
|
3688
3694
|
await server.close();
|
|
3689
3695
|
}
|
|
3690
3696
|
}
|
|
3691
|
-
async start(
|
|
3697
|
+
async start(command2, folder, requireLive, checkpoint) {
|
|
3692
3698
|
await this.requireTrusted(folder);
|
|
3693
3699
|
return this.connection(
|
|
3694
3700
|
folder,
|
|
@@ -3699,7 +3705,7 @@ var CodexDriver = class {
|
|
|
3699
3705
|
);
|
|
3700
3706
|
await checkpoint?.(thread.id);
|
|
3701
3707
|
try {
|
|
3702
|
-
await seedThread(server, thread,
|
|
3708
|
+
await seedThread(server, thread, command2, requireLive);
|
|
3703
3709
|
} catch (error) {
|
|
3704
3710
|
if (error instanceof HarnessRefusal) await discardThread(server, thread.id);
|
|
3705
3711
|
throw error;
|
|
@@ -3709,7 +3715,7 @@ var CodexDriver = class {
|
|
|
3709
3715
|
requireLive
|
|
3710
3716
|
);
|
|
3711
3717
|
}
|
|
3712
|
-
async reconcileLaunch(ref,
|
|
3718
|
+
async reconcileLaunch(ref, command2, folder, requireLive, beforeSeed) {
|
|
3713
3719
|
return this.connection(
|
|
3714
3720
|
folder,
|
|
3715
3721
|
async (server) => {
|
|
@@ -3742,7 +3748,7 @@ var CodexDriver = class {
|
|
|
3742
3748
|
requireLive.prompt?.();
|
|
3743
3749
|
if (!await inside2(await realpath6(await beforeSeed()), thread.cwd))
|
|
3744
3750
|
throw new HarnessRefusal("start_uncertain");
|
|
3745
|
-
await seedThread(server, thread,
|
|
3751
|
+
await seedThread(server, thread, command2, requireLive);
|
|
3746
3752
|
return { ...sessionFromThread(thread), state: "starting", waitingFor: null };
|
|
3747
3753
|
},
|
|
3748
3754
|
requireLive
|
|
@@ -3753,10 +3759,10 @@ var CodexDriver = class {
|
|
|
3753
3759
|
const turn = await this.connection(folder, (server) => lastTurn(server, session.id));
|
|
3754
3760
|
return turn ? [turn.id] : [];
|
|
3755
3761
|
},
|
|
3756
|
-
reconcile: async (session,
|
|
3762
|
+
reconcile: async (session, text5, observedRefs, folder, requireLive) => {
|
|
3757
3763
|
const turn = await this.connection(folder, (server) => lastTurn(server, session.id));
|
|
3758
3764
|
if (turn && !observedRefs.includes(turn.id)) return session.id;
|
|
3759
|
-
return this.resume(session,
|
|
3765
|
+
return this.resume(session, text5, folder, requireLive);
|
|
3760
3766
|
}
|
|
3761
3767
|
};
|
|
3762
3768
|
async list(folder, requireLive, query) {
|
|
@@ -3781,7 +3787,7 @@ var CodexDriver = class {
|
|
|
3781
3787
|
requireLive
|
|
3782
3788
|
);
|
|
3783
3789
|
}
|
|
3784
|
-
async resume(session,
|
|
3790
|
+
async resume(session, text5, folder, requireLive) {
|
|
3785
3791
|
if (session.state === "working" || session.state === "needs_input")
|
|
3786
3792
|
throw new HarnessRefusal("already_running");
|
|
3787
3793
|
const detected = await this.detect(folder);
|
|
@@ -3797,8 +3803,8 @@ var CodexDriver = class {
|
|
|
3797
3803
|
{ threadId: id, excludeTurns: true },
|
|
3798
3804
|
requireLive
|
|
3799
3805
|
);
|
|
3800
|
-
const turn =
|
|
3801
|
-
const prompt =
|
|
3806
|
+
const turn = text5 === null ? await lastTurn(server, id) : null;
|
|
3807
|
+
const prompt = text5 ?? (turn?.status === "interrupted" ? RESUME_CONTINUATION : null);
|
|
3802
3808
|
if (prompt !== null)
|
|
3803
3809
|
await server.request(
|
|
3804
3810
|
"turn/start",
|
|
@@ -3839,7 +3845,7 @@ import { basename as basename4, dirname as dirname4, join as join8 } from "node:
|
|
|
3839
3845
|
var MINIMUM_CURSOR_VERSION = "2026.10.19";
|
|
3840
3846
|
var MAX_RECORD_BYTES = 64 * 1024;
|
|
3841
3847
|
function supportedVersion(version) {
|
|
3842
|
-
const parts = (
|
|
3848
|
+
const parts = (text5) => (text5.split(/[-+]/)[0] ?? "").split(".").map(Number);
|
|
3843
3849
|
if (!version) return true;
|
|
3844
3850
|
const found = parts(version), minimum = parts(MINIMUM_CURSOR_VERSION);
|
|
3845
3851
|
for (const [index, part] of minimum.entries()) {
|
|
@@ -3863,8 +3869,11 @@ var CursorAgent = class {
|
|
|
3863
3869
|
command: inFolder(folder, "agent")
|
|
3864
3870
|
};
|
|
3865
3871
|
}
|
|
3866
|
-
|
|
3867
|
-
|
|
3872
|
+
signInStep = { instruction: "Run agent login and sign in.", command: "agent login" };
|
|
3873
|
+
installStep = {
|
|
3874
|
+
instruction: `Install the Cursor CLI ${MINIMUM_CURSOR_VERSION} or newer, then run connect again.`,
|
|
3875
|
+
link: "https://cursor.com/docs/cli/installation"
|
|
3876
|
+
};
|
|
3868
3877
|
/** ACP has no trust gate of its own, so an undecided folder is a step to take, not a launch to admit. */
|
|
3869
3878
|
unknownTrustAdmits = false;
|
|
3870
3879
|
async probe(executor, folder) {
|
|
@@ -3874,8 +3883,8 @@ var CursorAgent = class {
|
|
|
3874
3883
|
probe.available = version.code === 0 && probe.version !== null && supportedVersion(probe.version);
|
|
3875
3884
|
if (!probe.available) return probe;
|
|
3876
3885
|
const status = await executor.execute(this.executable, ["status"], "read", folder);
|
|
3877
|
-
const
|
|
3878
|
-
probe.signedIn = /not logged in|not authenticated|login required/i.test(
|
|
3886
|
+
const text5 = status.stdout + status.stderr;
|
|
3887
|
+
probe.signedIn = /not logged in|not authenticated|login required/i.test(text5) ? false : status.code === 0 && /logged in/i.test(text5) ? true : null;
|
|
3879
3888
|
return probe;
|
|
3880
3889
|
}
|
|
3881
3890
|
/**
|
|
@@ -4139,11 +4148,11 @@ async function copyIncluded(git, folder, requireLive, prefix = "") {
|
|
|
4139
4148
|
const clone = await realpath9(git.clone);
|
|
4140
4149
|
const destinationRoot = await realpath9(folder);
|
|
4141
4150
|
for (const name of result.stdout.split("\0").filter(Boolean)) {
|
|
4142
|
-
const
|
|
4151
|
+
const source = resolve8(clone, name);
|
|
4143
4152
|
const destinationName = posix2.join(prefix, name);
|
|
4144
4153
|
const destination = resolve8(destinationRoot, destinationName);
|
|
4145
|
-
if (!inside(clone,
|
|
4146
|
-
if (!(await lstat(
|
|
4154
|
+
if (!inside(clone, source) || !inside(destinationRoot, destination)) continue;
|
|
4155
|
+
if (!(await lstat(source)).isFile() || !inside(clone, await realpath9(source))) continue;
|
|
4147
4156
|
if (await checkDestination(destinationRoot, destination)) continue;
|
|
4148
4157
|
const tracked = await git.run(
|
|
4149
4158
|
["--literal-pathspecs", "ls-files", "--error-unmatch", "--", destinationName],
|
|
@@ -4156,7 +4165,7 @@ async function copyIncluded(git, folder, requireLive, prefix = "") {
|
|
|
4156
4165
|
requireLive();
|
|
4157
4166
|
await mkdir2(dirname5(destination), { recursive: true });
|
|
4158
4167
|
requireLive();
|
|
4159
|
-
await copyFile(
|
|
4168
|
+
await copyFile(source, destination, constants3.COPYFILE_EXCL).catch((error) => {
|
|
4160
4169
|
if (!(error instanceof Error && "code" in error && error.code === "EEXIST"))
|
|
4161
4170
|
throw error;
|
|
4162
4171
|
});
|
|
@@ -4565,14 +4574,110 @@ async function createBranch(git, context, requireLive) {
|
|
|
4565
4574
|
return !local && !prior;
|
|
4566
4575
|
}
|
|
4567
4576
|
|
|
4577
|
+
// src/cli-output.ts
|
|
4578
|
+
import { styleText } from "node:util";
|
|
4579
|
+
var MARKS = {
|
|
4580
|
+
pass: { glyph: "\u2713", format: "green" },
|
|
4581
|
+
fail: { glyph: "\u2717", format: "red" },
|
|
4582
|
+
wait: { glyph: "\u25CB", format: "yellow" },
|
|
4583
|
+
next: { glyph: "\u2192", format: "cyan" }
|
|
4584
|
+
};
|
|
4585
|
+
var heading = (text5) => ({ kind: "heading", text: text5 });
|
|
4586
|
+
var marked = (mark, text5, depth = 0) => ({
|
|
4587
|
+
kind: "marked",
|
|
4588
|
+
mark,
|
|
4589
|
+
text: text5,
|
|
4590
|
+
depth
|
|
4591
|
+
});
|
|
4592
|
+
var text4 = (value, depth = 0) => ({
|
|
4593
|
+
kind: "text",
|
|
4594
|
+
text: value,
|
|
4595
|
+
depth,
|
|
4596
|
+
muted: false
|
|
4597
|
+
});
|
|
4598
|
+
var note = (value, depth = 0) => ({
|
|
4599
|
+
kind: "text",
|
|
4600
|
+
text: value,
|
|
4601
|
+
depth,
|
|
4602
|
+
muted: true
|
|
4603
|
+
});
|
|
4604
|
+
var command = (value, depth = 0) => ({
|
|
4605
|
+
kind: "command",
|
|
4606
|
+
text: value,
|
|
4607
|
+
depth
|
|
4608
|
+
});
|
|
4609
|
+
var entry = (name, summary, width, depth = 0) => ({
|
|
4610
|
+
kind: "entry",
|
|
4611
|
+
name,
|
|
4612
|
+
summary,
|
|
4613
|
+
width,
|
|
4614
|
+
depth
|
|
4615
|
+
});
|
|
4616
|
+
var blank = { kind: "blank" };
|
|
4617
|
+
function nextLines(action, depth = 0) {
|
|
4618
|
+
return [marked("next", `${action.instruction}:`, depth), command(action.command, depth + 2)];
|
|
4619
|
+
}
|
|
4620
|
+
function colorEnabled(stream, env) {
|
|
4621
|
+
if (env["NO_COLOR"]) return false;
|
|
4622
|
+
const force = env["FORCE_COLOR"];
|
|
4623
|
+
if (force !== void 0) return force !== "0" && force !== "false";
|
|
4624
|
+
return stream.isTTY === true && stream.hasColors() === true;
|
|
4625
|
+
}
|
|
4626
|
+
function renderLines(lines, color) {
|
|
4627
|
+
const style = (format, value) => color ? styleText(format, value, { validateStream: false }) : value;
|
|
4628
|
+
return lines.map((line) => {
|
|
4629
|
+
if (line.kind === "blank") return "";
|
|
4630
|
+
if (line.kind === "heading") return style("bold", line.text);
|
|
4631
|
+
const indent = " ".repeat(line.depth);
|
|
4632
|
+
if (line.kind === "command") return indent + style("cyan", line.text);
|
|
4633
|
+
if (line.kind === "entry")
|
|
4634
|
+
return `${indent}${style("cyan", line.name.padEnd(line.width))} ${line.summary}`;
|
|
4635
|
+
if (line.kind === "text")
|
|
4636
|
+
return indent + (line.muted ? style("dim", line.text) : line.text);
|
|
4637
|
+
const mark = MARKS[line.mark];
|
|
4638
|
+
return `${indent}${style(mark.format, mark.glyph)} ${line.text}`;
|
|
4639
|
+
});
|
|
4640
|
+
}
|
|
4641
|
+
function writeLines(lines, stream = process.stdout, env = process.env) {
|
|
4642
|
+
if (lines.length === 0) return;
|
|
4643
|
+
stream.write(renderLines(lines, colorEnabled(stream, env)).join("\n") + "\n");
|
|
4644
|
+
}
|
|
4645
|
+
var ActionableError = class extends Error {
|
|
4646
|
+
constructor(message, next) {
|
|
4647
|
+
super(message);
|
|
4648
|
+
this.next = next;
|
|
4649
|
+
this.name = "ActionableError";
|
|
4650
|
+
}
|
|
4651
|
+
};
|
|
4652
|
+
var UsageError = class extends Error {
|
|
4653
|
+
constructor(usage) {
|
|
4654
|
+
super(`Usage: ${usage}`);
|
|
4655
|
+
this.usage = usage;
|
|
4656
|
+
this.name = "UsageError";
|
|
4657
|
+
}
|
|
4658
|
+
};
|
|
4659
|
+
function errorLines(error) {
|
|
4660
|
+
if (error instanceof UsageError)
|
|
4661
|
+
return [
|
|
4662
|
+
marked("fail", "That command takes different arguments. Usage:"),
|
|
4663
|
+
command(error.usage, 2),
|
|
4664
|
+
note("tsp-gateway --help lists every command.", 1)
|
|
4665
|
+
];
|
|
4666
|
+
const message = error instanceof Error ? error.message : "Gateway could not complete the command";
|
|
4667
|
+
return [
|
|
4668
|
+
marked("fail", message),
|
|
4669
|
+
...error instanceof ActionableError ? nextLines(error.next, 1) : []
|
|
4670
|
+
];
|
|
4671
|
+
}
|
|
4672
|
+
|
|
4568
4673
|
// src/checkout-config.ts
|
|
4569
4674
|
import { realpath as realpath12 } from "node:fs/promises";
|
|
4570
4675
|
import { resolve as resolve11 } from "node:path";
|
|
4571
4676
|
async function configureWorktrees(config, path) {
|
|
4572
4677
|
decodeWorktreeRoot(config.worktrees.root);
|
|
4573
|
-
for (const
|
|
4574
|
-
decodeWorktreeRoot(config.worktrees.root,
|
|
4575
|
-
decodeWorktreeRoot(
|
|
4678
|
+
for (const entry2 of Object.values(config.repositories)) {
|
|
4679
|
+
decodeWorktreeRoot(config.worktrees.root, entry2.folder);
|
|
4680
|
+
decodeWorktreeRoot(entry2.worktreeRoot, entry2.folder);
|
|
4576
4681
|
}
|
|
4577
4682
|
await saveConfig(path, config);
|
|
4578
4683
|
}
|
|
@@ -4580,46 +4685,59 @@ var SETTING_SOURCE = {
|
|
|
4580
4685
|
repository: "set for this repository with --repo",
|
|
4581
4686
|
machine: "set for this machine"
|
|
4582
4687
|
};
|
|
4583
|
-
function
|
|
4584
|
-
return
|
|
4688
|
+
function worktreeView(clone, root) {
|
|
4689
|
+
return {
|
|
4690
|
+
folder: root?.folder ?? UNRESOLVED_WORKTREE_ROOT,
|
|
4691
|
+
source: root?.setting ? SETTING_SOURCE[root.setting] : "the default inside the repository",
|
|
4692
|
+
outsideClone: root !== null && !inside(clone, root.folder)
|
|
4693
|
+
};
|
|
4585
4694
|
}
|
|
4586
|
-
|
|
4695
|
+
function worktreeLines(view, depth) {
|
|
4696
|
+
return [
|
|
4697
|
+
text4(`Worktrees: ${view.folder} (${view.source})`, depth),
|
|
4698
|
+
...view.outsideClone ? [
|
|
4699
|
+
note(
|
|
4700
|
+
"Codex: trust the registered clone; linked worktrees inherit that trust.",
|
|
4701
|
+
depth
|
|
4702
|
+
)
|
|
4703
|
+
] : []
|
|
4704
|
+
];
|
|
4705
|
+
}
|
|
4706
|
+
async function printWorktreeRoots(config, executor, print = (lines) => writeLines(lines)) {
|
|
4707
|
+
const lines = [];
|
|
4587
4708
|
if (Object.keys(config.repositories).length === 0)
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
const root = await previewWorktreeRoot(executor, entry.folder, config);
|
|
4593
|
-
console.log(
|
|
4594
|
-
`Worktrees for ${entry.folder}: ${root?.folder ?? UNRESOLVED_WORKTREE_ROOT} (${source(root)})`
|
|
4709
|
+
lines.push(
|
|
4710
|
+
text4(
|
|
4711
|
+
`Worktrees for future clones: ${config.worktrees.root ?? UNRESOLVED_WORKTREE_ROOT}`
|
|
4712
|
+
)
|
|
4595
4713
|
);
|
|
4596
|
-
|
|
4597
|
-
|
|
4714
|
+
for (const entry2 of Object.values(config.repositories)) {
|
|
4715
|
+
const root = await previewWorktreeRoot(executor, entry2.folder, config);
|
|
4716
|
+
lines.push(heading(entry2.folder), ...worktreeLines(worktreeView(entry2.folder, root), 1));
|
|
4598
4717
|
}
|
|
4718
|
+
print(lines);
|
|
4599
4719
|
}
|
|
4600
4720
|
function connectWorktreeArgs(args) {
|
|
4601
4721
|
if (args.length <= 2) return args[1] ? { folder: args[1] } : {};
|
|
4602
4722
|
if (args.length !== 4 || args[2] !== "--worktrees-root")
|
|
4603
|
-
throw new
|
|
4723
|
+
throw new UsageError("tsp-gateway connect [folder] [--worktrees-root <path>]");
|
|
4604
4724
|
const root = decodeWorktreeRoot(args[3], resolve11(args[1]));
|
|
4605
4725
|
if (root === null) throw new Error("A worktree root is required");
|
|
4606
4726
|
return { folder: args[1], root };
|
|
4607
4727
|
}
|
|
4608
4728
|
async function setWorktreeRoot(config, path, args) {
|
|
4609
4729
|
if (args[1] !== "worktrees-root" || !(args.length === 3 && !args[2].startsWith("--repo") || args.length === 5 && args[2] === "--repo"))
|
|
4610
|
-
throw new
|
|
4611
|
-
"Usage: tsp-gateway config worktrees-root [--repo <folder>] <path|--reset>"
|
|
4612
|
-
);
|
|
4730
|
+
throw new UsageError("tsp-gateway config worktrees-root [--repo <folder>] <path|--reset>");
|
|
4613
4731
|
const value = args.at(-1);
|
|
4614
4732
|
const root = value === "--reset" ? null : value;
|
|
4615
4733
|
if (args.length === 5) {
|
|
4616
4734
|
const folder = await realpath12(args[3]);
|
|
4617
|
-
const
|
|
4618
|
-
if (!
|
|
4735
|
+
const entry2 = Object.values(config.repositories).find((entry3) => entry3.folder === folder);
|
|
4736
|
+
if (!entry2)
|
|
4619
4737
|
throw new Error(
|
|
4620
4738
|
"Repository folder is not registered. Run tsp-gateway add <folder> first."
|
|
4621
4739
|
);
|
|
4622
|
-
|
|
4740
|
+
entry2.worktreeRoot = decodeWorktreeRoot(root, folder);
|
|
4623
4741
|
} else config.worktrees.root = decodeWorktreeRoot(root);
|
|
4624
4742
|
await configureWorktrees(config, path);
|
|
4625
4743
|
}
|
|
@@ -4635,13 +4753,13 @@ async function worktreesCommand({
|
|
|
4635
4753
|
args
|
|
4636
4754
|
}) {
|
|
4637
4755
|
if (args[0] === "config") await setWorktreeRoot(config, paths.config, args);
|
|
4638
|
-
else if (args.length !== 1) throw new
|
|
4756
|
+
else if (args.length !== 1) throw new UsageError("tsp-gateway worktrees");
|
|
4639
4757
|
await printWorktreeRoots(config, executor);
|
|
4640
4758
|
}
|
|
4641
4759
|
|
|
4642
4760
|
// src/command-lifetime.ts
|
|
4643
|
-
function withdrawnReason(
|
|
4644
|
-
return
|
|
4761
|
+
function withdrawnReason(command2) {
|
|
4762
|
+
return command2.kind === "launch" ? "launch_withdrawn" : "control_withdrawn";
|
|
4645
4763
|
}
|
|
4646
4764
|
var lifetimeClock = {
|
|
4647
4765
|
monotonic: () => performance.now(),
|
|
@@ -4678,28 +4796,28 @@ var CommandLifetime = class {
|
|
|
4678
4796
|
* Aborts `signal` and fails every later check of this launch or resume, or only holds an
|
|
4679
4797
|
* uncertain one. Repeating it changes nothing.
|
|
4680
4798
|
*/
|
|
4681
|
-
withdraw(
|
|
4682
|
-
if (
|
|
4799
|
+
withdraw(command2) {
|
|
4800
|
+
if (command2.kind === "stop" || this.held || this.withdrawal.signal.aborted) return;
|
|
4683
4801
|
if (this.uncertain) {
|
|
4684
4802
|
this.held = true;
|
|
4685
4803
|
return;
|
|
4686
4804
|
}
|
|
4687
|
-
this.withdrawal.abort(new HarnessRefusal(withdrawnReason(
|
|
4805
|
+
this.withdrawal.abort(new HarnessRefusal(withdrawnReason(command2)));
|
|
4688
4806
|
}
|
|
4689
|
-
requireLive(
|
|
4807
|
+
requireLive(command2) {
|
|
4690
4808
|
if (this.withdrawal.signal.aborted) throw this.withdrawal.signal.reason;
|
|
4691
4809
|
if (this.remaining() <= 0)
|
|
4692
4810
|
throw new HarnessRefusal(
|
|
4693
|
-
|
|
4811
|
+
command2.kind === "launch" ? "launch_expired" : "control_expired"
|
|
4694
4812
|
);
|
|
4695
4813
|
}
|
|
4696
4814
|
/** The checks a command's harness effects run, carrying the withdrawal signal with them. */
|
|
4697
|
-
check(
|
|
4698
|
-
return Object.assign(() => this.requireLive(
|
|
4815
|
+
check(command2) {
|
|
4816
|
+
return Object.assign(() => this.requireLive(command2), {
|
|
4699
4817
|
signal: this.withdrawal.signal,
|
|
4700
4818
|
prompt: () => {
|
|
4701
|
-
this.requireLive(
|
|
4702
|
-
if (this.held) throw new HarnessRefusal(withdrawnReason(
|
|
4819
|
+
this.requireLive(command2);
|
|
4820
|
+
if (this.held) throw new HarnessRefusal(withdrawnReason(command2));
|
|
4703
4821
|
}
|
|
4704
4822
|
});
|
|
4705
4823
|
}
|
|
@@ -4729,27 +4847,27 @@ var CommandLifetimes = class {
|
|
|
4729
4847
|
constructor(journal, clock) {
|
|
4730
4848
|
this.journal = journal;
|
|
4731
4849
|
this.clock = clock;
|
|
4732
|
-
for (const
|
|
4733
|
-
const { command } =
|
|
4734
|
-
const lifetime = new CommandLifetime(
|
|
4735
|
-
this.lifetimes.set(
|
|
4736
|
-
if (
|
|
4737
|
-
if (
|
|
4850
|
+
for (const entry2 of journal.entries.values()) {
|
|
4851
|
+
const { command: command2 } = entry2;
|
|
4852
|
+
const lifetime = new CommandLifetime(command2.ttl_ms, clock, entry2.lifetime);
|
|
4853
|
+
this.lifetimes.set(command2.command_id, lifetime);
|
|
4854
|
+
if (entry2.receipt === null && command2.kind !== "stop") lifetime.uncertainStart();
|
|
4855
|
+
if (command2.kind === "stop") this.withdrawStarts(command2);
|
|
4738
4856
|
}
|
|
4739
4857
|
}
|
|
4740
4858
|
lifetimes = /* @__PURE__ */ new Map();
|
|
4741
4859
|
/** Commands received but not journaled yet, so a Stop can withdraw a start still queued. */
|
|
4742
4860
|
queued = /* @__PURE__ */ new Map();
|
|
4743
|
-
receive(
|
|
4744
|
-
let lifetime = this.lifetimes.get(
|
|
4861
|
+
receive(command2) {
|
|
4862
|
+
let lifetime = this.lifetimes.get(command2.command_id);
|
|
4745
4863
|
if (!lifetime) {
|
|
4746
|
-
lifetime = new CommandLifetime(
|
|
4747
|
-
this.lifetimes.set(
|
|
4748
|
-
if (!this.journal.entries.has(
|
|
4749
|
-
this.queued.set(
|
|
4864
|
+
lifetime = new CommandLifetime(command2.ttl_ms, this.clock);
|
|
4865
|
+
this.lifetimes.set(command2.command_id, lifetime);
|
|
4866
|
+
if (!this.journal.entries.has(command2.command_id))
|
|
4867
|
+
this.queued.set(command2.command_id, command2);
|
|
4750
4868
|
}
|
|
4751
|
-
if (
|
|
4752
|
-
this.withdrawStarts(
|
|
4869
|
+
if (command2.kind === "stop" && !this.journal.entries.get(command2.command_id)?.receipt)
|
|
4870
|
+
this.withdrawStarts(command2);
|
|
4753
4871
|
return lifetime;
|
|
4754
4872
|
}
|
|
4755
4873
|
/** The command left the queue; the journal holds it from here on. */
|
|
@@ -4757,10 +4875,10 @@ var CommandLifetimes = class {
|
|
|
4757
4875
|
this.queued.delete(commandId);
|
|
4758
4876
|
}
|
|
4759
4877
|
retire(actionId) {
|
|
4760
|
-
for (const { command } of this.journal.entries.values())
|
|
4761
|
-
if (
|
|
4762
|
-
for (const [id,
|
|
4763
|
-
if (
|
|
4878
|
+
for (const { command: command2 } of this.journal.entries.values())
|
|
4879
|
+
if (command2.action_id === actionId) this.lifetimes.delete(command2.command_id);
|
|
4880
|
+
for (const [id, command2] of this.queued)
|
|
4881
|
+
if (command2.action_id === actionId) {
|
|
4764
4882
|
this.queued.delete(id);
|
|
4765
4883
|
this.lifetimes.delete(id);
|
|
4766
4884
|
}
|
|
@@ -4768,10 +4886,10 @@ var CommandLifetimes = class {
|
|
|
4768
4886
|
/** Withdraws every unfinished launch or resume of the Stop's action received before it. */
|
|
4769
4887
|
withdrawStarts(stop) {
|
|
4770
4888
|
for (const [id, lifetime] of this.lifetimes) {
|
|
4771
|
-
const
|
|
4772
|
-
const
|
|
4773
|
-
if (
|
|
4774
|
-
lifetime.withdraw(
|
|
4889
|
+
const entry2 = this.journal.entries.get(id);
|
|
4890
|
+
const command2 = entry2?.command ?? this.queued.get(id);
|
|
4891
|
+
if (command2 && command2.kind !== "stop" && command2.action_id === stop.action_id && !entry2?.receipt)
|
|
4892
|
+
lifetime.withdraw(command2);
|
|
4775
4893
|
}
|
|
4776
4894
|
}
|
|
4777
4895
|
};
|
|
@@ -4840,17 +4958,17 @@ function readCommand(value, version) {
|
|
|
4840
4958
|
throw new Error("Invalid stored operation");
|
|
4841
4959
|
}
|
|
4842
4960
|
}
|
|
4843
|
-
function checkIdentity(row,
|
|
4961
|
+
function checkIdentity(row, command2) {
|
|
4844
4962
|
for (const key of ["action_id", "command_id"]) {
|
|
4845
4963
|
const value = field(row, key);
|
|
4846
|
-
if (value !== void 0 && value !==
|
|
4964
|
+
if (value !== void 0 && value !== command2[key])
|
|
4847
4965
|
throw new Error("Invalid stored identity");
|
|
4848
4966
|
}
|
|
4849
4967
|
}
|
|
4850
|
-
function readReceipt(value,
|
|
4968
|
+
function readReceipt(value, command2) {
|
|
4851
4969
|
if (value === null) return null;
|
|
4852
4970
|
const row = object(value);
|
|
4853
|
-
checkIdentity(row,
|
|
4971
|
+
checkIdentity(row, command2);
|
|
4854
4972
|
switch (field(row, "kind")) {
|
|
4855
4973
|
case "ack":
|
|
4856
4974
|
return { kind: "ack" };
|
|
@@ -4872,10 +4990,10 @@ function readAttachHint(value) {
|
|
|
4872
4990
|
throw new Error("Invalid attach session reference");
|
|
4873
4991
|
return { harness: member2(field(row, "harness"), Object.values(HARNESS_KIND)), session_ref };
|
|
4874
4992
|
}
|
|
4875
|
-
function readObservation(value,
|
|
4993
|
+
function readObservation(value, command2) {
|
|
4876
4994
|
if (value === null) return null;
|
|
4877
4995
|
const row = object(value);
|
|
4878
|
-
checkIdentity(row,
|
|
4996
|
+
checkIdentity(row, command2);
|
|
4879
4997
|
return {
|
|
4880
4998
|
checkout: decodeCheckoutReport(field(row, "checkout")),
|
|
4881
4999
|
session_ref: string(field(row, "session_ref")),
|
|
@@ -4890,11 +5008,11 @@ function readJournalEntry(value, folders = {}) {
|
|
|
4890
5008
|
const row = object(value), version = field(row, "format_version");
|
|
4891
5009
|
if (version !== void 0 && version !== 1 && version !== 2 && version !== 3)
|
|
4892
5010
|
throw new Error("Unsupported journal format");
|
|
4893
|
-
const
|
|
5011
|
+
const command2 = readCommand(field(row, "command"), version);
|
|
4894
5012
|
const lifetime = object(field(row, "lifetime"));
|
|
4895
|
-
const receipt = readReceipt(field(row, "receipt"),
|
|
5013
|
+
const receipt = readReceipt(field(row, "receipt"), command2);
|
|
4896
5014
|
if (receipt?.kind === "refused") validateRefusalDetail(receipt.reason, receipt.detail);
|
|
4897
|
-
const update = readObservation(field(row, "update"),
|
|
5015
|
+
const update = readObservation(field(row, "update"), command2);
|
|
4898
5016
|
const rawRefs = field(row, "observedRefs");
|
|
4899
5017
|
if (!Array.isArray(rawRefs)) throw new Error("Invalid stored observations");
|
|
4900
5018
|
const observedRefs = rawRefs.map((ref) => string(ref));
|
|
@@ -4903,16 +5021,16 @@ function readJournalEntry(value, folders = {}) {
|
|
|
4903
5021
|
throw new Error("Invalid stored attempts");
|
|
4904
5022
|
const envelope = {
|
|
4905
5023
|
protocol_version: GATEWAY_PROTOCOL_VERSION,
|
|
4906
|
-
action_id:
|
|
5024
|
+
action_id: command2.action_id
|
|
4907
5025
|
};
|
|
4908
5026
|
return {
|
|
4909
|
-
checkout: version === 3 ? readPrepared(field(row, "checkout")) : legacyPrepared(
|
|
5027
|
+
checkout: version === 3 ? readPrepared(field(row, "checkout")) : legacyPrepared(command2, folders),
|
|
4910
5028
|
lifetime: {
|
|
4911
5029
|
remainingMs: nonnegative(field(lifetime, "remainingMs")),
|
|
4912
5030
|
savedAtMs: nonnegative(field(lifetime, "savedAtMs"))
|
|
4913
5031
|
},
|
|
4914
|
-
command: { ...
|
|
4915
|
-
receipt: receipt && { ...receipt, ...envelope, command_id:
|
|
5032
|
+
command: { ...command2, protocol_version: GATEWAY_PROTOCOL_VERSION },
|
|
5033
|
+
receipt: receipt && { ...receipt, ...envelope, command_id: command2.command_id },
|
|
4916
5034
|
update: update && {
|
|
4917
5035
|
...update,
|
|
4918
5036
|
...envelope,
|
|
@@ -4923,15 +5041,15 @@ function readJournalEntry(value, folders = {}) {
|
|
|
4923
5041
|
attempts
|
|
4924
5042
|
};
|
|
4925
5043
|
}
|
|
4926
|
-
function storeJournalEntry(
|
|
4927
|
-
const { protocol_version: _version, ...
|
|
4928
|
-
const receipt =
|
|
4929
|
-
const update =
|
|
5044
|
+
function storeJournalEntry(entry2) {
|
|
5045
|
+
const { protocol_version: _version, ...command2 } = entry2.command;
|
|
5046
|
+
const receipt = entry2.receipt;
|
|
5047
|
+
const update = entry2.update;
|
|
4930
5048
|
return {
|
|
4931
5049
|
format_version: 3,
|
|
4932
|
-
checkout:
|
|
4933
|
-
lifetime:
|
|
4934
|
-
command,
|
|
5050
|
+
checkout: entry2.checkout,
|
|
5051
|
+
lifetime: entry2.lifetime,
|
|
5052
|
+
command: command2,
|
|
4935
5053
|
receipt: receipt === null ? null : receipt.kind === "refused" ? { kind: "refused", reason: receipt.reason, detail: receipt.detail ?? null } : { kind: "ack" },
|
|
4936
5054
|
update: update && {
|
|
4937
5055
|
checkout: update.checkout ?? null,
|
|
@@ -4942,9 +5060,9 @@ function storeJournalEntry(entry) {
|
|
|
4942
5060
|
attach_hint: update.attach_hint ?? null,
|
|
4943
5061
|
resumed_as: update.resumed_as ?? null
|
|
4944
5062
|
},
|
|
4945
|
-
conversationId:
|
|
4946
|
-
observedRefs:
|
|
4947
|
-
attempts:
|
|
5063
|
+
conversationId: entry2.conversationId,
|
|
5064
|
+
observedRefs: entry2.observedRefs,
|
|
5065
|
+
attempts: entry2.attempts
|
|
4948
5066
|
};
|
|
4949
5067
|
}
|
|
4950
5068
|
function readPrepared(value) {
|
|
@@ -4971,9 +5089,9 @@ function readPrepared(value) {
|
|
|
4971
5089
|
sharesCheckout: boolean("sharesCheckout")
|
|
4972
5090
|
};
|
|
4973
5091
|
}
|
|
4974
|
-
function legacyPrepared(
|
|
4975
|
-
if (
|
|
4976
|
-
const folder = folders[repositoryKey(
|
|
5092
|
+
function legacyPrepared(command2, folders) {
|
|
5093
|
+
if (command2.kind !== "launch") return null;
|
|
5094
|
+
const folder = folders[repositoryKey(command2.repository)];
|
|
4977
5095
|
if (!folder) return null;
|
|
4978
5096
|
return {
|
|
4979
5097
|
folder,
|
|
@@ -5002,11 +5120,11 @@ function canonical(value) {
|
|
|
5002
5120
|
return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${canonical(field(value, key))}`).join(",")}}`;
|
|
5003
5121
|
return JSON.stringify(value);
|
|
5004
5122
|
}
|
|
5005
|
-
function commandDigest(
|
|
5123
|
+
function commandDigest(command2) {
|
|
5006
5124
|
const identity2 = {
|
|
5007
|
-
...
|
|
5125
|
+
...command2,
|
|
5008
5126
|
ttl_ms: null,
|
|
5009
|
-
...
|
|
5127
|
+
...command2.kind === "resume" ? { text: command2.text ?? null } : {}
|
|
5010
5128
|
};
|
|
5011
5129
|
return createHash("sha256").update(canonical(identity2)).digest("hex");
|
|
5012
5130
|
}
|
|
@@ -5033,9 +5151,9 @@ var Journal = class {
|
|
|
5033
5151
|
let value;
|
|
5034
5152
|
try {
|
|
5035
5153
|
value = parseJson(line);
|
|
5036
|
-
const
|
|
5154
|
+
const entry2 = readJournalEntry(value, folders);
|
|
5037
5155
|
upgrade ||= isObject(value) && field(value, "format_version") !== 3;
|
|
5038
|
-
this.entries.set(
|
|
5156
|
+
this.entries.set(entry2.command.command_id, entry2);
|
|
5039
5157
|
} catch {
|
|
5040
5158
|
this.quarantine(line, value);
|
|
5041
5159
|
console.error("TSP gateway skipped an unreadable journal entry.");
|
|
@@ -5044,40 +5162,40 @@ var Journal = class {
|
|
|
5044
5162
|
if (!upgrade) return;
|
|
5045
5163
|
await privateWrite(
|
|
5046
5164
|
this.path,
|
|
5047
|
-
[...this.entries.values()].map((
|
|
5165
|
+
[...this.entries.values()].map((entry2) => JSON.stringify(storeJournalEntry(entry2)) + "\n").join("") + this.unreadableRows.map((row) => row.line + "\n").join("")
|
|
5048
5166
|
);
|
|
5049
5167
|
}
|
|
5050
5168
|
quarantine(line, value) {
|
|
5051
|
-
const
|
|
5052
|
-
const id = isObject(
|
|
5053
|
-
const action = isObject(
|
|
5169
|
+
const command2 = isObject(value) ? field(value, "command") : null;
|
|
5170
|
+
const id = isObject(command2) ? field(command2, "command_id") : null;
|
|
5171
|
+
const action = isObject(command2) ? field(command2, "action_id") : null;
|
|
5054
5172
|
if (typeof id === "string") this.unreadableCommandIds.add(id);
|
|
5055
5173
|
this.unreadableRows.push({ line, actionId: typeof action === "string" ? action : null });
|
|
5056
5174
|
}
|
|
5057
5175
|
async retire(actionId) {
|
|
5058
5176
|
const retained = [...this.entries.values()].filter(
|
|
5059
|
-
(
|
|
5177
|
+
(entry2) => entry2.command.action_id !== actionId
|
|
5060
5178
|
);
|
|
5061
5179
|
const unreadable = this.unreadableRows.filter((row) => row.actionId !== actionId);
|
|
5062
5180
|
await privateWrite(
|
|
5063
5181
|
this.path,
|
|
5064
|
-
retained.map((
|
|
5182
|
+
retained.map((entry2) => JSON.stringify(storeJournalEntry(entry2)) + "\n").join("") + unreadable.map((row) => row.line + "\n").join("")
|
|
5065
5183
|
);
|
|
5066
5184
|
this.unreadableRows = unreadable;
|
|
5067
|
-
for (const [id,
|
|
5068
|
-
if (
|
|
5185
|
+
for (const [id, entry2] of this.entries) {
|
|
5186
|
+
if (entry2.command.action_id === actionId) this.entries.delete(id);
|
|
5069
5187
|
}
|
|
5070
5188
|
}
|
|
5071
|
-
async append(
|
|
5189
|
+
async append(entry2) {
|
|
5072
5190
|
const handle = await open6(this.path, "a", 384);
|
|
5073
5191
|
try {
|
|
5074
5192
|
await handle.chmod(384);
|
|
5075
|
-
await handle.writeFile(JSON.stringify(storeJournalEntry(
|
|
5193
|
+
await handle.writeFile(JSON.stringify(storeJournalEntry(entry2)) + "\n");
|
|
5076
5194
|
await handle.sync();
|
|
5077
5195
|
} finally {
|
|
5078
5196
|
await handle.close();
|
|
5079
5197
|
}
|
|
5080
|
-
this.entries.set(
|
|
5198
|
+
this.entries.set(entry2.command.command_id, entry2);
|
|
5081
5199
|
}
|
|
5082
5200
|
};
|
|
5083
5201
|
|
|
@@ -5117,12 +5235,12 @@ async function stopUntilSettled(driver, session, folder, requireLive, settleMs)
|
|
|
5117
5235
|
await delay3(STOP_POLL_MS);
|
|
5118
5236
|
}
|
|
5119
5237
|
}
|
|
5120
|
-
function stopUnstarted(journal,
|
|
5238
|
+
function stopUnstarted(journal, command2) {
|
|
5121
5239
|
const launches = [...journal.entries.values()].filter(
|
|
5122
|
-
(
|
|
5240
|
+
(entry2) => entry2.command.action_id === command2.action_id && entry2.command.kind === "launch"
|
|
5123
5241
|
);
|
|
5124
5242
|
if (launches.length === 0) throw new HarnessRefusal("session_not_found");
|
|
5125
|
-
if (launches.some((
|
|
5243
|
+
if (launches.some((entry2) => entry2.receipt === null))
|
|
5126
5244
|
throw new Error("The launch this Stop withdrew is still settling");
|
|
5127
5245
|
return { update: null, conversationId: null };
|
|
5128
5246
|
}
|
|
@@ -5135,12 +5253,12 @@ async function findSession(driver, ref, folder, requireLive) {
|
|
|
5135
5253
|
}
|
|
5136
5254
|
async function launchSession(journal, request) {
|
|
5137
5255
|
const { driver, intent, folder, retry, knownRef, requireLive } = request;
|
|
5138
|
-
const
|
|
5139
|
-
if (
|
|
5256
|
+
const command2 = intent.command;
|
|
5257
|
+
if (command2.kind !== "launch") throw new HarnessRefusal("unsupported_command");
|
|
5140
5258
|
if (driver.reconcileLaunch) {
|
|
5141
|
-
for (const
|
|
5142
|
-
if (
|
|
5143
|
-
intent.observedRefs = [...
|
|
5259
|
+
for (const entry2 of journal.entries.values()) {
|
|
5260
|
+
if (entry2.command.kind === "launch" && entry2.command.action_id === command2.action_id && entry2.observedRefs.length > intent.observedRefs.length)
|
|
5261
|
+
intent.observedRefs = [...entry2.observedRefs];
|
|
5144
5262
|
}
|
|
5145
5263
|
await journal.append(intent);
|
|
5146
5264
|
}
|
|
@@ -5153,7 +5271,7 @@ async function launchSession(journal, request) {
|
|
|
5153
5271
|
if (saved && !knownRef) {
|
|
5154
5272
|
session = await driver.reconcileLaunch(
|
|
5155
5273
|
saved,
|
|
5156
|
-
|
|
5274
|
+
command2,
|
|
5157
5275
|
folder,
|
|
5158
5276
|
requireLive,
|
|
5159
5277
|
request.beforeStart
|
|
@@ -5162,10 +5280,10 @@ async function launchSession(journal, request) {
|
|
|
5162
5280
|
const sessions = await driver.list(
|
|
5163
5281
|
folder,
|
|
5164
5282
|
requireLive,
|
|
5165
|
-
knownRef ? { refs: [knownRef] } : { name:
|
|
5283
|
+
knownRef ? { refs: [knownRef] } : { name: command2.session_name }
|
|
5166
5284
|
);
|
|
5167
5285
|
const matching = sessions.filter(
|
|
5168
|
-
(row) => knownRef ? row.id === knownRef : row.name ===
|
|
5286
|
+
(row) => knownRef ? row.id === knownRef : row.name === command2.session_name
|
|
5169
5287
|
);
|
|
5170
5288
|
if (matching.length > 1) throw new HarnessRefusal("start_uncertain");
|
|
5171
5289
|
session = matching[0];
|
|
@@ -5174,7 +5292,7 @@ async function launchSession(journal, request) {
|
|
|
5174
5292
|
await checkpoint(session.id);
|
|
5175
5293
|
session = await driver.reconcileLaunch(
|
|
5176
5294
|
session.id,
|
|
5177
|
-
|
|
5295
|
+
command2,
|
|
5178
5296
|
folder,
|
|
5179
5297
|
requireLive,
|
|
5180
5298
|
request.beforeStart
|
|
@@ -5186,18 +5304,18 @@ async function launchSession(journal, request) {
|
|
|
5186
5304
|
promptCheck(requireLive)();
|
|
5187
5305
|
const preparedFolder = await request.beforeStart();
|
|
5188
5306
|
promptCheck(requireLive)();
|
|
5189
|
-
const ref = await driver.start(
|
|
5307
|
+
const ref = await driver.start(command2, preparedFolder, requireLive, checkpoint);
|
|
5190
5308
|
return { ref };
|
|
5191
5309
|
}
|
|
5192
5310
|
async function resumeSession(journal, request) {
|
|
5193
5311
|
const { driver, intent, session, folder, retry, requireLive } = request;
|
|
5194
|
-
const
|
|
5195
|
-
if (
|
|
5312
|
+
const command2 = intent.command;
|
|
5313
|
+
if (command2.kind !== "resume") throw new HarnessRefusal("unsupported_command");
|
|
5196
5314
|
if (driver.resumeRecovery) {
|
|
5197
5315
|
if (retry && intent.conversationId !== null)
|
|
5198
5316
|
return driver.resumeRecovery.reconcile(
|
|
5199
5317
|
session,
|
|
5200
|
-
|
|
5318
|
+
command2.text ?? null,
|
|
5201
5319
|
intent.observedRefs,
|
|
5202
5320
|
folder,
|
|
5203
5321
|
requireLive
|
|
@@ -5206,7 +5324,7 @@ async function resumeSession(journal, request) {
|
|
|
5206
5324
|
intent.conversationId = session.conversationId;
|
|
5207
5325
|
await journal.append(intent);
|
|
5208
5326
|
promptCheck(requireLive)();
|
|
5209
|
-
return driver.resume(session,
|
|
5327
|
+
return driver.resume(session, command2.text ?? null, folder, requireLive);
|
|
5210
5328
|
}
|
|
5211
5329
|
const sessions = await driver.list(folder);
|
|
5212
5330
|
if (retry) {
|
|
@@ -5220,7 +5338,7 @@ async function resumeSession(journal, request) {
|
|
|
5220
5338
|
intent.observedRefs = sessions.filter((row) => row.conversationId === session.conversationId).map((row) => row.id);
|
|
5221
5339
|
await journal.append({ ...intent, conversationId: session.conversationId });
|
|
5222
5340
|
promptCheck(requireLive)();
|
|
5223
|
-
return await driver.resume(session,
|
|
5341
|
+
return await driver.resume(session, command2.text ?? null, folder, requireLive);
|
|
5224
5342
|
}
|
|
5225
5343
|
async function observeSessions(drivers, contexts, activity = false) {
|
|
5226
5344
|
const contextList = [...contexts];
|
|
@@ -5290,19 +5408,19 @@ function unreadState(binding) {
|
|
|
5290
5408
|
}
|
|
5291
5409
|
|
|
5292
5410
|
// src/command-bindings.ts
|
|
5293
|
-
function rememberBinding(
|
|
5294
|
-
const { command, update } =
|
|
5295
|
-
if (!update || !
|
|
5411
|
+
function rememberBinding(entry2, previous) {
|
|
5412
|
+
const { command: command2, update } = entry2;
|
|
5413
|
+
if (!update || !entry2.checkout && !previous) return void 0;
|
|
5296
5414
|
return {
|
|
5297
|
-
harness:
|
|
5298
|
-
folder:
|
|
5299
|
-
checkout:
|
|
5415
|
+
harness: command2.kind === "launch" ? command2.harness : previous.harness,
|
|
5416
|
+
folder: entry2.checkout?.folder ?? previous.folder,
|
|
5417
|
+
checkout: entry2.checkout ? checkoutReport(entry2.checkout) : previous?.checkout,
|
|
5300
5418
|
state: update.state,
|
|
5301
5419
|
missingPolls: 0,
|
|
5302
5420
|
unreadablePolls: 0,
|
|
5303
|
-
repository:
|
|
5421
|
+
repository: command2.kind === "launch" ? repositoryKey(command2.repository) : previous.repository,
|
|
5304
5422
|
ref: update.resumed_as ?? update.session_ref,
|
|
5305
|
-
conversationId:
|
|
5423
|
+
conversationId: entry2.conversationId
|
|
5306
5424
|
};
|
|
5307
5425
|
}
|
|
5308
5426
|
|
|
@@ -5318,29 +5436,29 @@ async function prepareLaunchCheckout({
|
|
|
5318
5436
|
}) {
|
|
5319
5437
|
const entries = [...journal.entries.values()];
|
|
5320
5438
|
const launch = intent.command.kind === "resume" ? entries.find(
|
|
5321
|
-
(
|
|
5439
|
+
(entry2) => entry2.command.action_id === intent.command.action_id && entry2.command.kind === "launch"
|
|
5322
5440
|
) : intent;
|
|
5323
|
-
const
|
|
5324
|
-
if (
|
|
5441
|
+
const command2 = launch?.command;
|
|
5442
|
+
if (command2?.kind !== "launch") throw new HarnessRefusal("unsupported_command");
|
|
5325
5443
|
if (!intent.checkout) {
|
|
5326
|
-
const previous = entries.reverse().find((
|
|
5444
|
+
const previous = entries.reverse().find((entry2) => entry2.command.action_id === command2.action_id && entry2.checkout);
|
|
5327
5445
|
if (previous?.checkout) {
|
|
5328
5446
|
intent.checkout = previous.checkout;
|
|
5329
5447
|
await journal.append(intent);
|
|
5330
5448
|
}
|
|
5331
5449
|
}
|
|
5332
5450
|
if (!intent.checkout || revalidate) {
|
|
5333
|
-
const clone = intent.checkout?.clone ?? (await repositories())[launchRepositoryKey(
|
|
5451
|
+
const clone = intent.checkout?.clone ?? (await repositories())[launchRepositoryKey(command2.repository)];
|
|
5334
5452
|
if (!clone) throw new HarnessRefusal("repository_not_registered");
|
|
5335
5453
|
intent.checkout = await checkout.prepare({
|
|
5336
|
-
checkout:
|
|
5337
|
-
repository:
|
|
5454
|
+
checkout: command2.checkout,
|
|
5455
|
+
repository: command2.repository,
|
|
5338
5456
|
clone,
|
|
5339
5457
|
live: {
|
|
5340
5458
|
folders: () => [
|
|
5341
5459
|
...[...bindings.values()].filter((binding) => !isTerminalSessionState(binding.state)).map((binding) => binding.folder),
|
|
5342
5460
|
...[...journal.entries.values()].flatMap(
|
|
5343
|
-
(
|
|
5461
|
+
(entry2) => (entry2.command.kind === "launch" || entry2.command.kind === "resume") && entry2.command.command_id !== intent.command.command_id && entry2.receipt === null && entry2.checkout && (!entry2.update || !isTerminalSessionState(entry2.update.state)) ? [entry2.checkout.folder] : []
|
|
5344
5462
|
)
|
|
5345
5463
|
]
|
|
5346
5464
|
},
|
|
@@ -5353,18 +5471,18 @@ async function prepareLaunchCheckout({
|
|
|
5353
5471
|
}
|
|
5354
5472
|
|
|
5355
5473
|
// src/command-identity.ts
|
|
5356
|
-
function hasUncertainLaunch(journal,
|
|
5474
|
+
function hasUncertainLaunch(journal, command2) {
|
|
5357
5475
|
const earlier = [...journal.entries.values()].filter(
|
|
5358
|
-
(
|
|
5476
|
+
(entry2) => entry2.command.action_id === command2.action_id && entry2.command.command_id !== command2.command_id && entry2.command.kind === "launch"
|
|
5359
5477
|
);
|
|
5360
|
-
for (const
|
|
5361
|
-
if (
|
|
5478
|
+
for (const entry2 of earlier) {
|
|
5479
|
+
if (entry2.command.kind === "launch" && (entry2.command.seed !== command2.seed || entry2.command.harness !== command2.harness || repositoryKey(entry2.command.repository) !== repositoryKey(command2.repository) || JSON.stringify(entry2.command.checkout) !== JSON.stringify(command2.checkout)))
|
|
5362
5480
|
throw new Error("Action identity conflict");
|
|
5363
5481
|
}
|
|
5364
|
-
return earlier.some((
|
|
5482
|
+
return earlier.some((entry2) => entry2.receipt === null && entry2.checkout !== null);
|
|
5365
5483
|
}
|
|
5366
|
-
function startsAsRetry(journal,
|
|
5367
|
-
return
|
|
5484
|
+
function startsAsRetry(journal, command2, previous) {
|
|
5485
|
+
return command2.kind === "launch" ? Boolean(previous?.checkout) || hasUncertainLaunch(journal, command2) : Boolean(previous);
|
|
5368
5486
|
}
|
|
5369
5487
|
|
|
5370
5488
|
// src/command-observation.ts
|
|
@@ -5393,8 +5511,8 @@ var STARTUP_REASONS = {
|
|
|
5393
5511
|
exited: "shell_startup_failed",
|
|
5394
5512
|
folder_unavailable: "repository_folder_unavailable"
|
|
5395
5513
|
};
|
|
5396
|
-
function unreadableCommandRefusal(
|
|
5397
|
-
return new HarnessRefusal(
|
|
5514
|
+
function unreadableCommandRefusal(command2) {
|
|
5515
|
+
return new HarnessRefusal(command2.kind === "stop" ? "stop_failed" : "start_uncertain");
|
|
5398
5516
|
}
|
|
5399
5517
|
function provenRefusal(error, retry) {
|
|
5400
5518
|
if (error instanceof HarnessRefusal) return error;
|
|
@@ -5419,7 +5537,7 @@ var Commands = class {
|
|
|
5419
5537
|
})
|
|
5420
5538
|
);
|
|
5421
5539
|
this.lifetimes = new CommandLifetimes(journal, options.clock ?? lifetimeClock);
|
|
5422
|
-
for (const
|
|
5540
|
+
for (const entry2 of journal.entries.values()) this.remember(entry2);
|
|
5423
5541
|
}
|
|
5424
5542
|
stopSettleMs;
|
|
5425
5543
|
activity;
|
|
@@ -5428,12 +5546,12 @@ var Commands = class {
|
|
|
5428
5546
|
lifetimes;
|
|
5429
5547
|
resolutions = /* @__PURE__ */ new Map();
|
|
5430
5548
|
/** Called at socket receipt, before joining the serial work queue. A Stop withdraws its action's start at once. */
|
|
5431
|
-
receive(
|
|
5432
|
-
return this.lifetimes.receive(
|
|
5549
|
+
receive(command2) {
|
|
5550
|
+
return this.lifetimes.receive(command2);
|
|
5433
5551
|
}
|
|
5434
|
-
remember(
|
|
5435
|
-
const action =
|
|
5436
|
-
const binding = rememberBinding(
|
|
5552
|
+
remember(entry2) {
|
|
5553
|
+
const action = entry2.command.action_id;
|
|
5554
|
+
const binding = rememberBinding(entry2, this.bindings.get(action));
|
|
5437
5555
|
if (binding) this.bindings.set(action, binding);
|
|
5438
5556
|
}
|
|
5439
5557
|
update(harness, action, ref, state, resumedAs) {
|
|
@@ -5442,18 +5560,18 @@ var Commands = class {
|
|
|
5442
5560
|
checkout: this.bindings.get(action)?.checkout ?? null
|
|
5443
5561
|
};
|
|
5444
5562
|
}
|
|
5445
|
-
async process(
|
|
5446
|
-
const previous = this.journal.entries.get(
|
|
5447
|
-
if (previous && commandDigest(previous.command) !== commandDigest(
|
|
5563
|
+
async process(command2, accept) {
|
|
5564
|
+
const previous = this.journal.entries.get(command2.command_id);
|
|
5565
|
+
if (previous && commandDigest(previous.command) !== commandDigest(command2))
|
|
5448
5566
|
throw new Error("Command identity conflict");
|
|
5449
|
-
if (previous?.receipt && !this.resolutions.has(
|
|
5567
|
+
if (previous?.receipt && !this.resolutions.has(command2.command_id))
|
|
5450
5568
|
return await this.replay(previous);
|
|
5451
|
-
const lifetime = this.receive(
|
|
5452
|
-
const decision = this.resolutions.get(
|
|
5569
|
+
const lifetime = this.receive(command2);
|
|
5570
|
+
const decision = this.resolutions.get(command2.command_id) ?? (lifetime.remaining() > 0 ? await accept(command2, lifetime.remaining()) : true);
|
|
5453
5571
|
if (decision === false) return [];
|
|
5454
5572
|
const intent = {
|
|
5455
5573
|
...previous ?? {
|
|
5456
|
-
command,
|
|
5574
|
+
command: command2,
|
|
5457
5575
|
checkout: null,
|
|
5458
5576
|
receipt: null,
|
|
5459
5577
|
update: null,
|
|
@@ -5464,29 +5582,29 @@ var Commands = class {
|
|
|
5464
5582
|
lifetime: lifetime.checkpoint()
|
|
5465
5583
|
};
|
|
5466
5584
|
if (decision !== true) {
|
|
5467
|
-
this.resolutions.set(
|
|
5585
|
+
this.resolutions.set(command2.command_id, decision);
|
|
5468
5586
|
await this.journal.append({ ...intent, receipt: decision });
|
|
5469
|
-
this.resolutions.delete(
|
|
5587
|
+
this.resolutions.delete(command2.command_id);
|
|
5470
5588
|
return [];
|
|
5471
5589
|
}
|
|
5472
5590
|
await this.journal.append(intent);
|
|
5473
5591
|
let update = null, conversationId = intent.conversationId;
|
|
5474
5592
|
let receipt;
|
|
5475
|
-
this.lifetimes.dequeued(
|
|
5593
|
+
this.lifetimes.dequeued(command2.command_id);
|
|
5476
5594
|
try {
|
|
5477
|
-
const retry = startsAsRetry(this.journal,
|
|
5595
|
+
const retry = startsAsRetry(this.journal, command2, previous);
|
|
5478
5596
|
if (retry) lifetime.uncertainStart();
|
|
5479
|
-
else lifetime.requireLive(
|
|
5480
|
-
if (this.journal.unreadableCommandIds.has(
|
|
5481
|
-
throw unreadableCommandRefusal(
|
|
5482
|
-
const result =
|
|
5597
|
+
else lifetime.requireLive(command2);
|
|
5598
|
+
if (this.journal.unreadableCommandIds.has(command2.command_id))
|
|
5599
|
+
throw unreadableCommandRefusal(command2);
|
|
5600
|
+
const result = command2.kind === "launch" ? await this.launch(intent, retry, lifetime) : await this.control(intent, retry, lifetime);
|
|
5483
5601
|
update = result.update;
|
|
5484
5602
|
conversationId = result.conversationId;
|
|
5485
5603
|
receipt = {
|
|
5486
5604
|
kind: "ack",
|
|
5487
5605
|
protocol_version: GATEWAY_PROTOCOL_VERSION,
|
|
5488
|
-
command_id:
|
|
5489
|
-
action_id:
|
|
5606
|
+
command_id: command2.command_id,
|
|
5607
|
+
action_id: command2.action_id
|
|
5490
5608
|
};
|
|
5491
5609
|
} catch (error) {
|
|
5492
5610
|
const refusal = provenRefusal(error, Boolean(previous));
|
|
@@ -5494,15 +5612,15 @@ var Commands = class {
|
|
|
5494
5612
|
receipt = {
|
|
5495
5613
|
kind: "refused",
|
|
5496
5614
|
protocol_version: GATEWAY_PROTOCOL_VERSION,
|
|
5497
|
-
command_id:
|
|
5498
|
-
action_id:
|
|
5615
|
+
command_id: command2.command_id,
|
|
5616
|
+
action_id: command2.action_id,
|
|
5499
5617
|
reason: refusal.reason,
|
|
5500
5618
|
detail: refusalDetail(refusal, intent.checkout)
|
|
5501
5619
|
};
|
|
5502
5620
|
}
|
|
5503
5621
|
const outcome = {
|
|
5504
5622
|
checkout: intent.checkout,
|
|
5505
|
-
command,
|
|
5623
|
+
command: command2,
|
|
5506
5624
|
receipt,
|
|
5507
5625
|
update,
|
|
5508
5626
|
conversationId,
|
|
@@ -5523,10 +5641,10 @@ var Commands = class {
|
|
|
5523
5641
|
}
|
|
5524
5642
|
return [receipt, ...update ? [update] : []];
|
|
5525
5643
|
}
|
|
5526
|
-
async replay(
|
|
5527
|
-
if (!
|
|
5528
|
-
const binding = this.bindings.get(
|
|
5529
|
-
if (
|
|
5644
|
+
async replay(entry2) {
|
|
5645
|
+
if (!entry2.receipt) throw new Error("Cannot replay an unfinished command");
|
|
5646
|
+
const binding = this.bindings.get(entry2.command.action_id);
|
|
5647
|
+
if (entry2.receipt.kind === "refused" || !binding) return [entry2.receipt];
|
|
5530
5648
|
let rows;
|
|
5531
5649
|
try {
|
|
5532
5650
|
const folder = binding.folder;
|
|
@@ -5535,26 +5653,26 @@ var Commands = class {
|
|
|
5535
5653
|
rows = [];
|
|
5536
5654
|
}
|
|
5537
5655
|
const row = rows.find((session) => session.id === binding.ref);
|
|
5538
|
-
const prior =
|
|
5656
|
+
const prior = entry2.update;
|
|
5539
5657
|
const update = prior?.resumed_as === binding.ref ? this.update(
|
|
5540
5658
|
binding.harness,
|
|
5541
|
-
|
|
5659
|
+
entry2.command.action_id,
|
|
5542
5660
|
prior.session_ref,
|
|
5543
5661
|
row?.state ?? unreadState(binding),
|
|
5544
5662
|
binding.ref
|
|
5545
5663
|
) : this.update(
|
|
5546
5664
|
binding.harness,
|
|
5547
|
-
|
|
5665
|
+
entry2.command.action_id,
|
|
5548
5666
|
binding.ref,
|
|
5549
5667
|
row?.state ?? unreadState(binding)
|
|
5550
5668
|
);
|
|
5551
5669
|
update.waiting_for = row?.waitingFor ?? null;
|
|
5552
|
-
return this.emit(
|
|
5670
|
+
return this.emit(entry2.receipt, update);
|
|
5553
5671
|
}
|
|
5554
5672
|
async launch(intent, retry, lifetime) {
|
|
5555
|
-
const
|
|
5556
|
-
if (
|
|
5557
|
-
const requireLive = lifetime.check(
|
|
5673
|
+
const command2 = intent.command;
|
|
5674
|
+
if (command2.kind !== "launch") throw new HarnessRefusal("unsupported_command");
|
|
5675
|
+
const requireLive = lifetime.check(command2);
|
|
5558
5676
|
const preparation = {
|
|
5559
5677
|
journal: this.journal,
|
|
5560
5678
|
checkout: this.checkout,
|
|
@@ -5564,9 +5682,9 @@ var Commands = class {
|
|
|
5564
5682
|
requireLive
|
|
5565
5683
|
};
|
|
5566
5684
|
const folder = await prepareLaunchCheckout(preparation);
|
|
5567
|
-
const driver = await lifetime.unlessWithdrawn(this.drivers.ready(
|
|
5568
|
-
const known = this.bindings.get(
|
|
5569
|
-
if (known && (known.repository !== repositoryKey(
|
|
5685
|
+
const driver = await lifetime.unlessWithdrawn(this.drivers.ready(command2.harness, folder));
|
|
5686
|
+
const known = this.bindings.get(command2.action_id);
|
|
5687
|
+
if (known && (known.repository !== repositoryKey(command2.repository) || known.harness !== command2.harness))
|
|
5570
5688
|
throw new Error("Action identity conflict");
|
|
5571
5689
|
const { ref, session } = await launchSession(this.journal, {
|
|
5572
5690
|
driver,
|
|
@@ -5578,8 +5696,8 @@ var Commands = class {
|
|
|
5578
5696
|
requireLive
|
|
5579
5697
|
});
|
|
5580
5698
|
const update = this.update(
|
|
5581
|
-
|
|
5582
|
-
|
|
5699
|
+
command2.harness,
|
|
5700
|
+
command2.action_id,
|
|
5583
5701
|
ref,
|
|
5584
5702
|
session?.state ?? "starting"
|
|
5585
5703
|
);
|
|
@@ -5588,24 +5706,24 @@ var Commands = class {
|
|
|
5588
5706
|
return { update, conversationId: session?.conversationId ?? null };
|
|
5589
5707
|
}
|
|
5590
5708
|
async control(intent, retry, lifetime) {
|
|
5591
|
-
const
|
|
5592
|
-
if (
|
|
5709
|
+
const command2 = intent.command;
|
|
5710
|
+
if (command2.kind !== "stop" && command2.kind !== "resume")
|
|
5593
5711
|
throw new HarnessRefusal("unsupported_command");
|
|
5594
|
-
const requireLive = lifetime.check(
|
|
5595
|
-
const binding = this.bindings.get(
|
|
5596
|
-
if (
|
|
5597
|
-
return stopUnstarted(this.journal,
|
|
5598
|
-
if (!binding || (
|
|
5712
|
+
const requireLive = lifetime.check(command2);
|
|
5713
|
+
const binding = this.bindings.get(command2.action_id);
|
|
5714
|
+
if (command2.kind === "stop" && !command2.session_ref && !binding)
|
|
5715
|
+
return stopUnstarted(this.journal, command2);
|
|
5716
|
+
if (!binding || (command2.session_ref ?? binding.ref) !== binding.ref)
|
|
5599
5717
|
throw new HarnessRefusal("session_not_found");
|
|
5600
5718
|
const folder = binding.folder;
|
|
5601
5719
|
if (!folder) throw new HarnessRefusal("repository_not_registered");
|
|
5602
5720
|
const driver = this.drivers.get(binding.harness);
|
|
5603
5721
|
const session = await findSession(driver, binding.ref, folder, requireLive);
|
|
5604
|
-
if (
|
|
5722
|
+
if (command2.kind === "stop")
|
|
5605
5723
|
return {
|
|
5606
5724
|
update: this.update(
|
|
5607
5725
|
binding.harness,
|
|
5608
|
-
|
|
5726
|
+
command2.action_id,
|
|
5609
5727
|
session.id,
|
|
5610
5728
|
await stopUntilSettled(driver, session, folder, requireLive, this.stopSettleMs)
|
|
5611
5729
|
),
|
|
@@ -5629,7 +5747,7 @@ var Commands = class {
|
|
|
5629
5747
|
});
|
|
5630
5748
|
const update = this.update(
|
|
5631
5749
|
binding.harness,
|
|
5632
|
-
|
|
5750
|
+
command2.action_id,
|
|
5633
5751
|
session.id,
|
|
5634
5752
|
"starting",
|
|
5635
5753
|
ref === session.id ? void 0 : ref
|
|
@@ -5642,18 +5760,18 @@ var Commands = class {
|
|
|
5642
5760
|
}
|
|
5643
5761
|
/** A hub reconciliation also repairs receipts persisted by an older gateway. */
|
|
5644
5762
|
async reconcile(receipt) {
|
|
5645
|
-
const
|
|
5646
|
-
if (!
|
|
5647
|
-
if (
|
|
5763
|
+
const entry2 = this.journal.entries.get(receipt.command_id);
|
|
5764
|
+
if (!entry2) return;
|
|
5765
|
+
if (entry2.command.action_id !== receipt.action_id)
|
|
5648
5766
|
throw new Error("Receipt identity conflict");
|
|
5649
5767
|
this.resolutions.set(receipt.command_id, receipt);
|
|
5650
|
-
await this.journal.append({ ...
|
|
5768
|
+
await this.journal.append({ ...entry2, receipt });
|
|
5651
5769
|
this.resolutions.delete(receipt.command_id);
|
|
5652
5770
|
}
|
|
5653
5771
|
async retire(actionId) {
|
|
5654
|
-
for (const
|
|
5655
|
-
if (
|
|
5656
|
-
this.resolutions.delete(
|
|
5772
|
+
for (const entry2 of this.journal.entries.values())
|
|
5773
|
+
if (entry2.command.action_id === actionId)
|
|
5774
|
+
this.resolutions.delete(entry2.command.command_id);
|
|
5657
5775
|
this.lifetimes.retire(actionId);
|
|
5658
5776
|
await this.journal.retire(actionId);
|
|
5659
5777
|
this.bindings.delete(actionId);
|
|
@@ -5665,8 +5783,8 @@ var Commands = class {
|
|
|
5665
5783
|
/** Replay every binding's latest receipt before polling, including terminal sessions. */
|
|
5666
5784
|
durableReceipts() {
|
|
5667
5785
|
const latest = /* @__PURE__ */ new Map();
|
|
5668
|
-
for (const
|
|
5669
|
-
latest.set(
|
|
5786
|
+
for (const entry2 of this.journal.entries.values())
|
|
5787
|
+
latest.set(entry2.command.action_id, entry2);
|
|
5670
5788
|
const receipts = [];
|
|
5671
5789
|
for (const action of this.bindings.keys()) {
|
|
5672
5790
|
const receipt = latest.get(action)?.receipt;
|
|
@@ -5679,7 +5797,7 @@ var Commands = class {
|
|
|
5679
5797
|
}
|
|
5680
5798
|
/** Unfinished durable operations are retried locally, even without hub redelivery. */
|
|
5681
5799
|
get pendingIntents() {
|
|
5682
|
-
return [...this.journal.entries.values()].filter((
|
|
5800
|
+
return [...this.journal.entries.values()].filter((entry2) => entry2.receipt === null);
|
|
5683
5801
|
}
|
|
5684
5802
|
get hasLiveBindings() {
|
|
5685
5803
|
return [...this.bindings.values()].some(
|
|
@@ -5758,6 +5876,62 @@ function identity(path) {
|
|
|
5758
5876
|
return stat5 === void 0 ? "absent" : `${stat5.ino}:${stat5.mtimeNs}:${stat5.size}`;
|
|
5759
5877
|
}
|
|
5760
5878
|
|
|
5879
|
+
// src/connection-state.ts
|
|
5880
|
+
var START = {
|
|
5881
|
+
instruction: "Start the gateway now and at login",
|
|
5882
|
+
command: "tsp-gateway start"
|
|
5883
|
+
};
|
|
5884
|
+
var CONNECT = {
|
|
5885
|
+
instruction: "Connect this computer again",
|
|
5886
|
+
command: "tsp-gateway connect"
|
|
5887
|
+
};
|
|
5888
|
+
var CONNECTION = {
|
|
5889
|
+
connected: { message: "Connected", text: "Connected to TSP", mark: "pass" },
|
|
5890
|
+
starting: { message: "Starting", text: "Starting", mark: "wait" },
|
|
5891
|
+
reconnecting: { message: "Reconnecting", text: "Reconnecting to TSP", mark: "wait" },
|
|
5892
|
+
waiting: {
|
|
5893
|
+
message: "Waiting for the network or TSP. Retrying\u2026",
|
|
5894
|
+
text: "Waiting for the network or TSP. Retrying\u2026",
|
|
5895
|
+
mark: "wait"
|
|
5896
|
+
},
|
|
5897
|
+
notRunning: { message: "Not running", text: "Not running", mark: "fail", next: START },
|
|
5898
|
+
stopped: { message: "Stopped", text: "Not running", mark: "fail", next: START },
|
|
5899
|
+
refreshFailed: {
|
|
5900
|
+
message: "Token refresh failed. Run tsp-gateway connect again.",
|
|
5901
|
+
text: "TSP no longer accepts this computer's credential",
|
|
5902
|
+
mark: "fail",
|
|
5903
|
+
next: CONNECT
|
|
5904
|
+
},
|
|
5905
|
+
tokenRejected: {
|
|
5906
|
+
message: "Token rejected after refresh. Run tsp-gateway connect again.",
|
|
5907
|
+
text: "TSP rejected this computer's credential",
|
|
5908
|
+
mark: "fail",
|
|
5909
|
+
next: CONNECT
|
|
5910
|
+
},
|
|
5911
|
+
accessEnded: {
|
|
5912
|
+
message: "Machine access ended. Run tsp-gateway connect again.",
|
|
5913
|
+
text: "This computer's access to TSP ended",
|
|
5914
|
+
mark: "fail",
|
|
5915
|
+
next: CONNECT
|
|
5916
|
+
},
|
|
5917
|
+
outdated: {
|
|
5918
|
+
message: "This gateway is outdated. Run npx @treestructuredplanning/gateway@latest update.",
|
|
5919
|
+
text: "This gateway is outdated",
|
|
5920
|
+
mark: "fail",
|
|
5921
|
+
next: {
|
|
5922
|
+
instruction: "Update it",
|
|
5923
|
+
command: "npx -y @treestructuredplanning/gateway@latest update"
|
|
5924
|
+
}
|
|
5925
|
+
}
|
|
5926
|
+
};
|
|
5927
|
+
function connectionState(message) {
|
|
5928
|
+
return Object.values(CONNECTION).find((state) => state.message === message) ?? {
|
|
5929
|
+
message,
|
|
5930
|
+
text: message.replace(/\.+$/, ""),
|
|
5931
|
+
mark: "fail"
|
|
5932
|
+
};
|
|
5933
|
+
}
|
|
5934
|
+
|
|
5761
5935
|
// src/launch-permits.ts
|
|
5762
5936
|
var LaunchPermits = class {
|
|
5763
5937
|
constructor(send, active, timeout) {
|
|
@@ -5766,7 +5940,7 @@ var LaunchPermits = class {
|
|
|
5766
5940
|
this.timeout = timeout;
|
|
5767
5941
|
}
|
|
5768
5942
|
pending = null;
|
|
5769
|
-
accept(
|
|
5943
|
+
accept(command2, remainingMs) {
|
|
5770
5944
|
return new Promise((resolve13) => {
|
|
5771
5945
|
if (!this.active() || remainingMs <= 0) {
|
|
5772
5946
|
resolve13(false);
|
|
@@ -5780,8 +5954,8 @@ var LaunchPermits = class {
|
|
|
5780
5954
|
Math.max(1, Math.min(2e4, remainingMs))
|
|
5781
5955
|
);
|
|
5782
5956
|
this.pending = {
|
|
5783
|
-
action:
|
|
5784
|
-
command:
|
|
5957
|
+
action: command2.action_id,
|
|
5958
|
+
command: command2.command_id,
|
|
5785
5959
|
resolve: (decision) => {
|
|
5786
5960
|
clearTimeout(timer);
|
|
5787
5961
|
this.pending = null;
|
|
@@ -5791,8 +5965,8 @@ var LaunchPermits = class {
|
|
|
5791
5965
|
this.send({
|
|
5792
5966
|
kind: "claim",
|
|
5793
5967
|
protocol_version: GATEWAY_PROTOCOL_VERSION,
|
|
5794
|
-
command_id:
|
|
5795
|
-
action_id:
|
|
5968
|
+
command_id: command2.command_id,
|
|
5969
|
+
action_id: command2.action_id
|
|
5796
5970
|
});
|
|
5797
5971
|
});
|
|
5798
5972
|
}
|
|
@@ -5858,21 +6032,21 @@ function transportSender(socket, isActive) {
|
|
|
5858
6032
|
};
|
|
5859
6033
|
}
|
|
5860
6034
|
function commandProcessor(commands, permits, retries, send) {
|
|
5861
|
-
return async (
|
|
5862
|
-
if (!retries.ready(
|
|
6035
|
+
return async (command2) => {
|
|
6036
|
+
if (!retries.ready(command2.command_id)) return;
|
|
5863
6037
|
let results;
|
|
5864
6038
|
try {
|
|
5865
6039
|
results = await commands.process(
|
|
5866
|
-
|
|
6040
|
+
command2,
|
|
5867
6041
|
(operation, remainingMs) => permits.accept(operation, remainingMs)
|
|
5868
6042
|
);
|
|
5869
6043
|
} catch {
|
|
5870
6044
|
console.error(
|
|
5871
|
-
`TSP gateway command pending: kind=${
|
|
6045
|
+
`TSP gateway command pending: kind=${command2.kind} command_id=${command2.command_id} action_id=${command2.action_id}`
|
|
5872
6046
|
);
|
|
5873
6047
|
return;
|
|
5874
6048
|
} finally {
|
|
5875
|
-
retries.defer(
|
|
6049
|
+
retries.defer(command2);
|
|
5876
6050
|
}
|
|
5877
6051
|
for (const result of results) send(result);
|
|
5878
6052
|
};
|
|
@@ -6004,7 +6178,7 @@ async function serve(options, socket, setup, refreshDue) {
|
|
|
6004
6178
|
ready = true;
|
|
6005
6179
|
readyAt = now();
|
|
6006
6180
|
await polling.poll();
|
|
6007
|
-
await status(true,
|
|
6181
|
+
await status(true, CONNECTION.connected.message);
|
|
6008
6182
|
});
|
|
6009
6183
|
});
|
|
6010
6184
|
socket.addEventListener("message", (event) => {
|
|
@@ -6091,9 +6265,9 @@ async function json(url, init) {
|
|
|
6091
6265
|
return await response.json();
|
|
6092
6266
|
}
|
|
6093
6267
|
function requiredText(value, key) {
|
|
6094
|
-
const
|
|
6095
|
-
if (typeof
|
|
6096
|
-
return
|
|
6268
|
+
const text5 = isObject(value) ? field(value, key) : null;
|
|
6269
|
+
if (typeof text5 !== "string" || !text5) throw new Error("Invalid OAuth response");
|
|
6270
|
+
return text5;
|
|
6097
6271
|
}
|
|
6098
6272
|
async function discover(origin) {
|
|
6099
6273
|
const value = await json(`${validateOrigin(origin)}/.well-known/oauth-authorization-server`);
|
|
@@ -6200,10 +6374,12 @@ async function pair(origin, store, openBrowser, report = () => {
|
|
|
6200
6374
|
code_challenge: createHash2("sha256").update(verifier).digest("base64url"),
|
|
6201
6375
|
code_challenge_method: "S256"
|
|
6202
6376
|
}).toString();
|
|
6203
|
-
report(
|
|
6204
|
-
|
|
6377
|
+
report([
|
|
6378
|
+
marked("next", "Approve pairing in your browser. If it doesn't open, visit:"),
|
|
6379
|
+
command(url.href, 2)
|
|
6380
|
+
]);
|
|
6205
6381
|
await openBrowser(url.href);
|
|
6206
|
-
report("Waiting for approval (up to 3 minutes)\u2026");
|
|
6382
|
+
report([marked("wait", "Waiting for approval (up to 3 minutes)\u2026")]);
|
|
6207
6383
|
const tokens = await tokenExchange(
|
|
6208
6384
|
endpoints.token,
|
|
6209
6385
|
new URLSearchParams({
|
|
@@ -6304,8 +6480,8 @@ var IntentRetries = class {
|
|
|
6304
6480
|
this.commands = commands;
|
|
6305
6481
|
this.now = now;
|
|
6306
6482
|
this.random = random;
|
|
6307
|
-
for (const
|
|
6308
|
-
this.schedule(
|
|
6483
|
+
for (const entry2 of commands.pendingIntents)
|
|
6484
|
+
this.schedule(entry2.command.command_id, entry2.attempts);
|
|
6309
6485
|
}
|
|
6310
6486
|
retryAt = /* @__PURE__ */ new Map();
|
|
6311
6487
|
unjournaled = /* @__PURE__ */ new Map();
|
|
@@ -6322,17 +6498,17 @@ var IntentRetries = class {
|
|
|
6322
6498
|
ready(commandId) {
|
|
6323
6499
|
return this.now() >= (this.retryAt.get(commandId) ?? -Infinity);
|
|
6324
6500
|
}
|
|
6325
|
-
defer(
|
|
6326
|
-
const id =
|
|
6327
|
-
const
|
|
6328
|
-
if (
|
|
6501
|
+
defer(command2) {
|
|
6502
|
+
const id = command2.command_id;
|
|
6503
|
+
const entry2 = this.commands.journalEntry(id);
|
|
6504
|
+
if (entry2) {
|
|
6329
6505
|
this.unjournaled.delete(id);
|
|
6330
|
-
if (
|
|
6506
|
+
if (entry2.receipt === null) this.schedule(id, entry2.attempts);
|
|
6331
6507
|
else this.retryAt.delete(id);
|
|
6332
6508
|
return;
|
|
6333
6509
|
}
|
|
6334
6510
|
const attempts = (this.unjournaled.get(id)?.attempts ?? 0) + 1;
|
|
6335
|
-
this.unjournaled.set(id, { command, attempts });
|
|
6511
|
+
this.unjournaled.set(id, { command: command2, attempts });
|
|
6336
6512
|
this.schedule(id, attempts);
|
|
6337
6513
|
}
|
|
6338
6514
|
/** A retired action is withdrawn by the hub: its unjournaled commands must never run. */
|
|
@@ -6344,17 +6520,17 @@ var IntentRetries = class {
|
|
|
6344
6520
|
}
|
|
6345
6521
|
}
|
|
6346
6522
|
async retryPending(process2, isActive) {
|
|
6347
|
-
for (const
|
|
6523
|
+
for (const command2 of this.pending) {
|
|
6348
6524
|
if (!isActive()) break;
|
|
6349
|
-
await process2(
|
|
6525
|
+
await process2(command2);
|
|
6350
6526
|
}
|
|
6351
6527
|
}
|
|
6352
6528
|
get pending() {
|
|
6353
6529
|
const commands = [
|
|
6354
|
-
...this.commands.pendingIntents.map((
|
|
6530
|
+
...this.commands.pendingIntents.map((entry2) => entry2.command),
|
|
6355
6531
|
...[...this.unjournaled.values()].map((held) => held.command)
|
|
6356
6532
|
];
|
|
6357
|
-
const ids = new Set(commands.map((
|
|
6533
|
+
const ids = new Set(commands.map((command2) => command2.command_id));
|
|
6358
6534
|
for (const id of this.retryAt.keys()) if (!ids.has(id)) this.retryAt.delete(id);
|
|
6359
6535
|
return commands;
|
|
6360
6536
|
}
|
|
@@ -6440,7 +6616,7 @@ async function reconnectLoop(options, handover) {
|
|
|
6440
6616
|
if (step === "halt") return;
|
|
6441
6617
|
if (step === "exit") break;
|
|
6442
6618
|
}
|
|
6443
|
-
await state.status(false,
|
|
6619
|
+
await state.status(false, CONNECTION.stopped.message);
|
|
6444
6620
|
}
|
|
6445
6621
|
async function accessToken(options, state, handover) {
|
|
6446
6622
|
try {
|
|
@@ -6449,11 +6625,10 @@ async function accessToken(options, state, handover) {
|
|
|
6449
6625
|
if (options.signal.aborted) return "exit";
|
|
6450
6626
|
if (error instanceof TokenAccessDenied) {
|
|
6451
6627
|
await handover.predecessor?.retire();
|
|
6452
|
-
await state.status(false,
|
|
6628
|
+
await state.status(false, CONNECTION.refreshFailed.message);
|
|
6453
6629
|
return "halt";
|
|
6454
6630
|
}
|
|
6455
|
-
if (!handover.predecessor)
|
|
6456
|
-
await state.status(false, "Waiting for the network or TSP. Retrying\u2026");
|
|
6631
|
+
if (!handover.predecessor) await state.status(false, CONNECTION.waiting.message);
|
|
6457
6632
|
await state.backoff();
|
|
6458
6633
|
return "retry";
|
|
6459
6634
|
}
|
|
@@ -6470,29 +6645,23 @@ async function afterClose(options, state, result, handover) {
|
|
|
6470
6645
|
);
|
|
6471
6646
|
if (options.signal.aborted) return "exit";
|
|
6472
6647
|
if (recovery === "outdated") {
|
|
6473
|
-
await state.status(
|
|
6474
|
-
false,
|
|
6475
|
-
"This gateway is outdated. Run npx @treestructuredplanning/gateway@latest update."
|
|
6476
|
-
);
|
|
6648
|
+
await state.status(false, CONNECTION.outdated.message);
|
|
6477
6649
|
await state.pause(OUTDATED_RETRY_MS);
|
|
6478
6650
|
return "retry";
|
|
6479
6651
|
}
|
|
6480
6652
|
if (recovery === "terminal") {
|
|
6481
|
-
await state.status(false,
|
|
6653
|
+
await state.status(false, CONNECTION.accessEnded.message);
|
|
6482
6654
|
return "halt";
|
|
6483
6655
|
}
|
|
6484
6656
|
if (recovery === "token") {
|
|
6485
6657
|
if (state.rejectedToken) {
|
|
6486
|
-
await state.status(
|
|
6487
|
-
false,
|
|
6488
|
-
"Token rejected after refresh. Run tsp-gateway connect again."
|
|
6489
|
-
);
|
|
6658
|
+
await state.status(false, CONNECTION.tokenRejected.message);
|
|
6490
6659
|
return "halt";
|
|
6491
6660
|
}
|
|
6492
6661
|
state.rejectedToken = true;
|
|
6493
6662
|
state.force = true;
|
|
6494
6663
|
}
|
|
6495
|
-
if (!handover.predecessor?.open()) await state.status(false,
|
|
6664
|
+
if (!handover.predecessor?.open()) await state.status(false, CONNECTION.reconnecting.message);
|
|
6496
6665
|
await state.backoff();
|
|
6497
6666
|
return "retry";
|
|
6498
6667
|
}
|
|
@@ -6620,9 +6789,9 @@ var GatewayStatus = class {
|
|
|
6620
6789
|
};
|
|
6621
6790
|
async function daemonConnection(statusPath, since = 0) {
|
|
6622
6791
|
try {
|
|
6623
|
-
const [
|
|
6792
|
+
const [text5, info] = await Promise.all([readFile6(statusPath, "utf8"), stat4(statusPath)]);
|
|
6624
6793
|
if (info.mtimeMs < since) return null;
|
|
6625
|
-
const status = parseJson(
|
|
6794
|
+
const status = parseJson(text5);
|
|
6626
6795
|
if (!isObject(status)) return null;
|
|
6627
6796
|
const pid = field(status, "pid"), message = field(status, "message");
|
|
6628
6797
|
return typeof pid === "number" && pidAlive(pid) && typeof message === "string" ? message : null;
|
|
@@ -6838,12 +7007,12 @@ function keychainOptions(platform = process.platform) {
|
|
|
6838
7007
|
return platform === "linux" ? { linux: { store: "secret-service" } } : {};
|
|
6839
7008
|
}
|
|
6840
7009
|
function keychain(account) {
|
|
6841
|
-
const
|
|
7010
|
+
const entry2 = new AsyncEntry("com.treestructuredplanning.gateway", account, keychainOptions());
|
|
6842
7011
|
return {
|
|
6843
|
-
get: () =>
|
|
6844
|
-
set: (token) =>
|
|
7012
|
+
get: () => entry2.getPassword(),
|
|
7013
|
+
set: (token) => entry2.setPassword(token),
|
|
6845
7014
|
delete: async () => {
|
|
6846
|
-
await
|
|
7015
|
+
await entry2.deletePassword();
|
|
6847
7016
|
}
|
|
6848
7017
|
};
|
|
6849
7018
|
}
|
|
@@ -6878,7 +7047,7 @@ async function addRepository(host, config, folder) {
|
|
|
6878
7047
|
return saveRepository(host, config, await registerFolder(folder, host.env));
|
|
6879
7048
|
}
|
|
6880
7049
|
async function installLoginItem(host, config, refresh = "always") {
|
|
6881
|
-
if (!config.pairing) throw
|
|
7050
|
+
if (!config.pairing) throw notConnected();
|
|
6882
7051
|
const path = await captureLoginPath(host.env, host.platform, config.launch);
|
|
6883
7052
|
const spec = {
|
|
6884
7053
|
node: host.node,
|
|
@@ -6895,13 +7064,20 @@ async function installLoginItem(host, config, refresh = "always") {
|
|
|
6895
7064
|
await install(spec, host.platform, host.home);
|
|
6896
7065
|
return "installed";
|
|
6897
7066
|
}
|
|
7067
|
+
function notConnected() {
|
|
7068
|
+
return new ActionableError("This computer isn't connected to TSP yet.", {
|
|
7069
|
+
instruction: "Connect it",
|
|
7070
|
+
command: "tsp-gateway connect"
|
|
7071
|
+
});
|
|
7072
|
+
}
|
|
6898
7073
|
var PACKAGE_INSTALL_TIMEOUT_MS = 6e5;
|
|
6899
7074
|
async function updateGateway(host, config, run2 = execute) {
|
|
6900
|
-
if (!config.pairing) throw
|
|
7075
|
+
if (!config.pairing) throw notConnected();
|
|
6901
7076
|
let latest = host;
|
|
6902
7077
|
const npm = host.platform === "win32" ? host.node : "npm";
|
|
6903
7078
|
const npmArgs = host.platform === "win32" ? [join11(dirname10(host.node), "node_modules", "npm", "bin", "npm-cli.js")] : [];
|
|
6904
7079
|
if (!host.entry.split(/[\\/]/).includes("_npx")) {
|
|
7080
|
+
host.report([marked("wait", "Installing the latest gateway with npm\u2026")]);
|
|
6905
7081
|
const installed = await run2(
|
|
6906
7082
|
npm,
|
|
6907
7083
|
[...npmArgs, "install", "--global", "@treestructuredplanning/gateway@latest"],
|
|
@@ -6921,6 +7097,7 @@ async function updateGateway(host, config, run2 = execute) {
|
|
|
6921
7097
|
latest = { ...host, entry: join11(folder, "dist", "cli.js"), version };
|
|
6922
7098
|
}
|
|
6923
7099
|
await installLoginItem(latest, config);
|
|
7100
|
+
return latest.version;
|
|
6924
7101
|
}
|
|
6925
7102
|
async function removeLoginItem(host) {
|
|
6926
7103
|
return await uninstall(host.paths.state, host.platform, host.home) ? "removed" : "absent";
|
|
@@ -6988,7 +7165,7 @@ async function folderSetups(drivers, config, repository, executor) {
|
|
|
6988
7165
|
if (found.length === 0) {
|
|
6989
7166
|
const required = here.map((row) => ({
|
|
6990
7167
|
harness: row.harness,
|
|
6991
|
-
|
|
7168
|
+
...drivers.get(row.harness).installStep
|
|
6992
7169
|
}));
|
|
6993
7170
|
setups.push({ slug, ready: [], required, optional: [] });
|
|
6994
7171
|
continue;
|
|
@@ -6998,8 +7175,7 @@ async function folderSetups(drivers, config, repository, executor) {
|
|
|
6998
7175
|
for (const row of found) {
|
|
6999
7176
|
const driver = drivers.get(row.harness);
|
|
7000
7177
|
const own = [];
|
|
7001
|
-
if (row.signed_in !== true)
|
|
7002
|
-
own.push({ harness: row.harness, instruction: driver.signInInstruction });
|
|
7178
|
+
if (row.signed_in !== true) own.push({ harness: row.harness, ...driver.signInStep });
|
|
7003
7179
|
const folder = folders[slug];
|
|
7004
7180
|
if (folder && trustIsStep(row.trust, driver))
|
|
7005
7181
|
own.push({ harness: row.harness, ...driver.repositorySetup(folder) });
|
|
@@ -7015,7 +7191,7 @@ async function folderSetups(drivers, config, repository, executor) {
|
|
|
7015
7191
|
const registered2 = config.repositories[setup.slug];
|
|
7016
7192
|
if (!registered2) return setup;
|
|
7017
7193
|
const root = await previewWorktreeRoot(executor, registered2.folder, config);
|
|
7018
|
-
return { ...setup,
|
|
7194
|
+
return { ...setup, worktree: worktreeView(registered2.folder, root) };
|
|
7019
7195
|
})
|
|
7020
7196
|
);
|
|
7021
7197
|
}
|
|
@@ -7031,65 +7207,136 @@ var REASONS = {
|
|
|
7031
7207
|
"configured direct": "chosen in your launch settings",
|
|
7032
7208
|
"Windows uses direct spawn": "as Windows does"
|
|
7033
7209
|
};
|
|
7210
|
+
var CONNECT_HERE = {
|
|
7211
|
+
instruction: "Run this inside a clone of a GitHub repository to register it",
|
|
7212
|
+
command: "tsp-gateway connect"
|
|
7213
|
+
};
|
|
7034
7214
|
function list(names) {
|
|
7035
7215
|
return names.length < 3 ? names.join(" and ") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
7036
7216
|
}
|
|
7037
|
-
function lowerFirst(
|
|
7038
|
-
return
|
|
7217
|
+
function lowerFirst(value) {
|
|
7218
|
+
return value.charAt(0).toLowerCase() + value.slice(1);
|
|
7039
7219
|
}
|
|
7040
|
-
function
|
|
7041
|
-
return
|
|
7220
|
+
function stepTarget(step) {
|
|
7221
|
+
return step.command ?? step.link;
|
|
7042
7222
|
}
|
|
7043
|
-
function
|
|
7223
|
+
function stepSentence(step, lead) {
|
|
7224
|
+
const sentence = `${lead}, ${lowerFirst(step.instruction)}`;
|
|
7225
|
+
return stepTarget(step) ? sentence.replace(/\.+$/, ":") : sentence;
|
|
7226
|
+
}
|
|
7227
|
+
function stepLines(steps, kind, name, depth) {
|
|
7044
7228
|
return steps.flatMap((step) => {
|
|
7045
|
-
const
|
|
7046
|
-
|
|
7229
|
+
const sentence = kind === "required" ? marked("next", stepSentence(step, `To build with ${name(step.harness)}`), depth) : note(
|
|
7230
|
+
stepSentence(step, `Optional: to also build with ${name(step.harness)}`),
|
|
7231
|
+
depth
|
|
7232
|
+
);
|
|
7233
|
+
const target = stepTarget(step);
|
|
7234
|
+
return target ? [sentence, command(target, depth + 2)] : [sentence];
|
|
7047
7235
|
});
|
|
7048
7236
|
}
|
|
7049
|
-
function setupLines(setups, name) {
|
|
7237
|
+
function setupLines(setups, name, depth = 1) {
|
|
7050
7238
|
return setups.flatMap((setup) => {
|
|
7051
7239
|
const label2 = setup.slug || "This computer";
|
|
7052
7240
|
return [
|
|
7053
|
-
setup.ready.length > 0 ?
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
|
|
7058
|
-
|
|
7059
|
-
|
|
7060
|
-
)
|
|
7241
|
+
setup.ready.length > 0 ? marked(
|
|
7242
|
+
"pass",
|
|
7243
|
+
`${label2}: ready to build with ${list(setup.ready.map(name))}`,
|
|
7244
|
+
depth
|
|
7245
|
+
) : marked("fail", `${label2}: not ready to build yet`, depth),
|
|
7246
|
+
...setup.worktree ? worktreeLines(setup.worktree, depth + 1) : [],
|
|
7247
|
+
...stepLines(setup.required, "required", name, depth + 1),
|
|
7248
|
+
...stepLines(setup.optional, "optional", name, depth + 1)
|
|
7061
7249
|
];
|
|
7062
7250
|
});
|
|
7063
7251
|
}
|
|
7064
7252
|
function registeredLines(registered2, drivers) {
|
|
7065
7253
|
return [
|
|
7066
|
-
`Registered ${registered2.slug}
|
|
7254
|
+
marked("pass", `Registered ${registered2.slug}`),
|
|
7255
|
+
note("The running gateway picks up the change automatically.", 1),
|
|
7067
7256
|
...stepLines(
|
|
7068
7257
|
drivers.repositorySetups(registered2.folder),
|
|
7069
|
-
|
|
7070
|
-
drivers.displayName
|
|
7258
|
+
"required",
|
|
7259
|
+
drivers.displayName,
|
|
7260
|
+
1
|
|
7261
|
+
),
|
|
7262
|
+
...nextLines(
|
|
7263
|
+
{ instruction: "Start the gateway now and at login", command: "tsp-gateway start" },
|
|
7264
|
+
1
|
|
7071
7265
|
)
|
|
7072
7266
|
];
|
|
7073
7267
|
}
|
|
7074
|
-
function
|
|
7075
|
-
|
|
7268
|
+
function gatewayLines(view) {
|
|
7269
|
+
const lines = [heading(`Gateway ${view.version}`)];
|
|
7270
|
+
if (view.machineId === null)
|
|
7271
|
+
return [
|
|
7272
|
+
...lines,
|
|
7273
|
+
marked("fail", "Not paired", 1),
|
|
7274
|
+
...nextLines({ instruction: "Pair this computer", command: "tsp-gateway connect" }, 2)
|
|
7275
|
+
];
|
|
7276
|
+
const current = connectionState(view.connection);
|
|
7277
|
+
const last = view.lastMessage !== null && view.lastMessage !== view.connection ? connectionState(view.lastMessage) : null;
|
|
7278
|
+
const next = current.mark === "fail" && last?.next ? last.next : current.next;
|
|
7279
|
+
return [
|
|
7280
|
+
...lines,
|
|
7281
|
+
marked("pass", `Paired as ${view.machineId}`, 1),
|
|
7282
|
+
marked(current.mark, current.text, 1),
|
|
7283
|
+
...last ? [note(`Last report: ${last.text}`, 2)] : [],
|
|
7284
|
+
...next ? nextLines(next, 2) : []
|
|
7285
|
+
];
|
|
7286
|
+
}
|
|
7287
|
+
function verdictLines(view, setups) {
|
|
7288
|
+
const connection = connectionState(view.connection).mark;
|
|
7289
|
+
const registered2 = setups.filter((setup) => setup.slug !== "");
|
|
7290
|
+
const ready = registered2.filter((setup) => setup.ready.length > 0).map((setup) => setup.slug);
|
|
7291
|
+
if (view.machineId === null || connection === "fail" || registered2.length > 0 && !ready.length)
|
|
7292
|
+
return [marked("fail", "Not ready to build yet. Follow the \u2192 steps above.")];
|
|
7293
|
+
if (registered2.length === 0)
|
|
7294
|
+
return [
|
|
7295
|
+
marked("fail", "No repository folder is registered yet."),
|
|
7296
|
+
...nextLines(CONNECT_HERE, 1)
|
|
7297
|
+
];
|
|
7298
|
+
if (connection === "wait")
|
|
7299
|
+
return [
|
|
7300
|
+
marked(
|
|
7301
|
+
"wait",
|
|
7302
|
+
`Ready to build in ${list(ready)} once the gateway connects. Check with:`
|
|
7303
|
+
),
|
|
7304
|
+
command("tsp-gateway status", 2)
|
|
7305
|
+
];
|
|
7306
|
+
return [marked("pass", `Ready to build in ${list(ready)}.`)];
|
|
7307
|
+
}
|
|
7308
|
+
function folderSection(setups, name) {
|
|
7309
|
+
return [blank, heading("Folders"), ...setupLines(setups, name)];
|
|
7076
7310
|
}
|
|
7077
7311
|
function connectLines(view, setups, name) {
|
|
7078
7312
|
return [
|
|
7079
|
-
|
|
7080
|
-
...
|
|
7081
|
-
|
|
7313
|
+
...gatewayLines(view),
|
|
7314
|
+
...folderSection(setups, name),
|
|
7315
|
+
blank,
|
|
7316
|
+
...verdictLines(view, setups),
|
|
7317
|
+
note(
|
|
7318
|
+
"tsp-gateway stop, start and update manage the background gateway. Pairing and folders stay."
|
|
7319
|
+
)
|
|
7082
7320
|
];
|
|
7083
7321
|
}
|
|
7084
7322
|
function statusLines(view, setups, name) {
|
|
7085
7323
|
const reason = REASONS[view.launch.reason] ?? view.launch.reason;
|
|
7086
|
-
const how = view.launch.effective_mode === "login-shell" && view.launch.shell !== null ? `Sessions start through your login shell, ${view.launch.shell} (${reason}).` : `Sessions start without a login shell (${reason}).`;
|
|
7087
7324
|
return [
|
|
7088
|
-
|
|
7089
|
-
...
|
|
7090
|
-
|
|
7091
|
-
|
|
7092
|
-
|
|
7325
|
+
...gatewayLines(view),
|
|
7326
|
+
...folderSection(setups, name),
|
|
7327
|
+
blank,
|
|
7328
|
+
heading("Sessions"),
|
|
7329
|
+
text4(
|
|
7330
|
+
view.launch.effective_mode === "login-shell" && view.launch.shell !== null ? `Start through your login shell, ${view.launch.shell} (${reason})` : `Start without a login shell (${reason})`,
|
|
7331
|
+
1
|
|
7332
|
+
),
|
|
7333
|
+
...view.launch.wrapper === null ? [] : [text4(`Wrapper: ${view.launch.wrapper}`, 1)],
|
|
7334
|
+
text4(
|
|
7335
|
+
view.reporting === "off" ? "Activity reporting off: TSP sees only each session's state" : "Activity reporting on: TSP sees each session's kind of work and its counts of files edited and commands run",
|
|
7336
|
+
1
|
|
7337
|
+
),
|
|
7338
|
+
blank,
|
|
7339
|
+
...verdictLines(view, setups)
|
|
7093
7340
|
];
|
|
7094
7341
|
}
|
|
7095
7342
|
|
|
@@ -7140,6 +7387,20 @@ export {
|
|
|
7140
7387
|
CheckoutPreparer,
|
|
7141
7388
|
previewWorktreeRoot,
|
|
7142
7389
|
checkoutReport,
|
|
7390
|
+
heading,
|
|
7391
|
+
marked,
|
|
7392
|
+
text4 as text,
|
|
7393
|
+
note,
|
|
7394
|
+
command,
|
|
7395
|
+
entry,
|
|
7396
|
+
blank,
|
|
7397
|
+
nextLines,
|
|
7398
|
+
colorEnabled,
|
|
7399
|
+
renderLines,
|
|
7400
|
+
writeLines,
|
|
7401
|
+
ActionableError,
|
|
7402
|
+
UsageError,
|
|
7403
|
+
errorLines,
|
|
7143
7404
|
printWorktreeRoots,
|
|
7144
7405
|
connectWorktreeArgs,
|
|
7145
7406
|
recordConnectRoot,
|
|
@@ -7150,6 +7411,8 @@ export {
|
|
|
7150
7411
|
UNREADABLE_SESSION_POLLS,
|
|
7151
7412
|
Commands,
|
|
7152
7413
|
watchConfig,
|
|
7414
|
+
CONNECTION,
|
|
7415
|
+
connectionState,
|
|
7153
7416
|
LaunchPermits,
|
|
7154
7417
|
HANDOVER_MS,
|
|
7155
7418
|
REFRESH_LEAD_MS,
|
|
@@ -7174,6 +7437,7 @@ export {
|
|
|
7174
7437
|
keychain,
|
|
7175
7438
|
addRepository,
|
|
7176
7439
|
installLoginItem,
|
|
7440
|
+
notConnected,
|
|
7177
7441
|
updateGateway,
|
|
7178
7442
|
removeLoginItem,
|
|
7179
7443
|
connect,
|
|
@@ -7184,4 +7448,4 @@ export {
|
|
|
7184
7448
|
connectLines,
|
|
7185
7449
|
statusLines
|
|
7186
7450
|
};
|
|
7187
|
-
//# sourceMappingURL=shared-
|
|
7451
|
+
//# sourceMappingURL=shared-SSP3A5QQ.js.map
|