inplan 0.2.0 → 0.2.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/bin/cli.js +215 -29
- package/package.json +1 -1
- package/skill/SKILL.md +13 -2
package/bin/cli.js
CHANGED
|
@@ -1156,22 +1156,48 @@ async function reuseCached(auth, skewS = ACCESS_SKEW_S) {
|
|
|
1156
1156
|
return error || !data.session ? null : { db, session: data.session };
|
|
1157
1157
|
}
|
|
1158
1158
|
var LIVE_REFRESH_SKEW_S = 10 * 60;
|
|
1159
|
-
|
|
1159
|
+
var REJECTING_STATUSES = /* @__PURE__ */ new Set([400, 401, 403]);
|
|
1160
|
+
function isSpentRefreshToken(error) {
|
|
1161
|
+
const e = error ?? {};
|
|
1162
|
+
if (e.code === "refresh_token_already_used") return true;
|
|
1163
|
+
return typeof e.message === "string" && /already used/i.test(e.message);
|
|
1164
|
+
}
|
|
1165
|
+
function authFailureKind(error) {
|
|
1166
|
+
const status = error?.status;
|
|
1167
|
+
const rejected = typeof status === "number" && REJECTING_STATUSES.has(status);
|
|
1168
|
+
if (!rejected) return { reason: "inconclusive", cause: "unspecified" };
|
|
1169
|
+
return { reason: "rejected", cause: isSpentRefreshToken(error) ? "refresh-token-spent" : "unspecified" };
|
|
1170
|
+
}
|
|
1171
|
+
async function authedSession(skewS = ACCESS_SKEW_S, onFailure) {
|
|
1160
1172
|
const cached = loadAuth();
|
|
1161
|
-
if (!cached)
|
|
1173
|
+
if (!cached) {
|
|
1174
|
+
onFailure?.("inconclusive");
|
|
1175
|
+
return null;
|
|
1176
|
+
}
|
|
1162
1177
|
const reused = await reuseCached(cached, skewS);
|
|
1163
1178
|
if (reused) return reused;
|
|
1164
1179
|
const locked = await withAuthLock(async ({ stillMine }) => {
|
|
1165
1180
|
const auth = loadAuth();
|
|
1166
|
-
if (!auth)
|
|
1181
|
+
if (!auth) {
|
|
1182
|
+
onFailure?.("inconclusive");
|
|
1183
|
+
return null;
|
|
1184
|
+
}
|
|
1167
1185
|
const fresh = await reuseCached(auth, skewS);
|
|
1168
1186
|
if (fresh) return fresh;
|
|
1169
|
-
if (!stillMine())
|
|
1187
|
+
if (!stillMine()) {
|
|
1188
|
+
onFailure?.("inconclusive");
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1170
1191
|
const db = newClient(auth);
|
|
1171
1192
|
const { data, error } = await db.auth.refreshSession({ refresh_token: auth.refreshToken });
|
|
1172
|
-
if (error || !data.session)
|
|
1193
|
+
if (error || !data.session) {
|
|
1194
|
+
const graded = error ? authFailureKind(error) : { reason: "inconclusive", cause: "unspecified" };
|
|
1195
|
+
onFailure?.(graded.reason, graded.cause);
|
|
1196
|
+
return null;
|
|
1197
|
+
}
|
|
1173
1198
|
if (!data.session.refresh_token) {
|
|
1174
1199
|
process.stderr.write("inplan: refresh returned no new refresh token; keeping the stored one and retrying rather than persisting a possibly-spent token\n");
|
|
1200
|
+
onFailure?.("inconclusive");
|
|
1175
1201
|
return null;
|
|
1176
1202
|
}
|
|
1177
1203
|
saveAuth({
|
|
@@ -1184,7 +1210,18 @@ async function authedSession(skewS = ACCESS_SKEW_S) {
|
|
|
1184
1210
|
return { db, session: data.session };
|
|
1185
1211
|
});
|
|
1186
1212
|
if (locked.acquired) return locked.value;
|
|
1187
|
-
|
|
1213
|
+
const contended = await reuseCached(loadAuth() ?? cached, 0);
|
|
1214
|
+
if (!contended) onFailure?.("inconclusive");
|
|
1215
|
+
return contended;
|
|
1216
|
+
}
|
|
1217
|
+
async function verifyCachedAccessToken() {
|
|
1218
|
+
const auth = loadAuth();
|
|
1219
|
+
if (!auth) return "absent";
|
|
1220
|
+
const bound = await reuseCached(auth);
|
|
1221
|
+
if (!bound) return "absent";
|
|
1222
|
+
const { data, error } = await bound.db.auth.getUser(auth.accessToken);
|
|
1223
|
+
if (!error && data?.user) return "ok";
|
|
1224
|
+
return error ? authFailureKind(error).reason : "inconclusive";
|
|
1188
1225
|
}
|
|
1189
1226
|
async function currentUser() {
|
|
1190
1227
|
const s = await authedSession();
|
|
@@ -1476,19 +1513,36 @@ async function createLoginSession(opts = {}) {
|
|
|
1476
1513
|
}
|
|
1477
1514
|
var LoginSessionExpiredError = class extends Error {
|
|
1478
1515
|
};
|
|
1516
|
+
var BrowserDidNotOpenError = class extends Error {
|
|
1517
|
+
};
|
|
1518
|
+
function pollRequestBudgetMs(nowMs, deadline, openAckDeadline) {
|
|
1519
|
+
const budgets = [REQUEST_TIMEOUT_MS, deadline - nowMs];
|
|
1520
|
+
if (openAckDeadline !== void 0) budgets.push(openAckDeadline - nowMs);
|
|
1521
|
+
return Math.max(1, Math.min(...budgets));
|
|
1522
|
+
}
|
|
1523
|
+
function launchAwareSignal(budgetMs, launchSignal) {
|
|
1524
|
+
const budget = AbortSignal.timeout(budgetMs);
|
|
1525
|
+
return launchSignal ? AbortSignal.any([budget, launchSignal]) : budget;
|
|
1526
|
+
}
|
|
1479
1527
|
async function pollLoginSession(pending, opts = {}) {
|
|
1480
1528
|
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
1481
1529
|
const now = opts.now ?? Date.now;
|
|
1482
1530
|
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
1483
1531
|
const deadline = now() + (opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
1484
1532
|
const nudgeAt = now() + NUDGE_MS;
|
|
1533
|
+
const openAckDeadline = opts.openAckMs === void 0 ? void 0 : now() + opts.openAckMs;
|
|
1485
1534
|
let nudged = false;
|
|
1486
1535
|
let sawOpened = false;
|
|
1536
|
+
const launchDead = () => !sawOpened && Boolean(opts.launchSignal?.aborted);
|
|
1487
1537
|
while (true) {
|
|
1488
1538
|
if (!nudged && !sawOpened && now() >= nudgeAt) {
|
|
1489
1539
|
nudged = true;
|
|
1490
1540
|
opts.onNudge?.();
|
|
1491
1541
|
}
|
|
1542
|
+
if (launchDead()) throw new BrowserDidNotOpenError("the browser could not be launched");
|
|
1543
|
+
if (openAckDeadline !== void 0 && !sawOpened && now() >= openAckDeadline) {
|
|
1544
|
+
throw new BrowserDidNotOpenError("the browser did not open");
|
|
1545
|
+
}
|
|
1492
1546
|
if (now() >= pending.expiresAt) {
|
|
1493
1547
|
await clearPendingLoginFor(pending.sessionId);
|
|
1494
1548
|
throw new LoginSessionExpiredError("the sign-in link expired \u2014 run the command again for a fresh one");
|
|
@@ -1501,11 +1555,26 @@ async function pollLoginSession(pending, opts = {}) {
|
|
|
1501
1555
|
// The poll credential rides a header (never a URL, so never an access log) — see
|
|
1502
1556
|
// PendingLogin.pollToken: the session id alone must not read or destroy the handoff.
|
|
1503
1557
|
headers: { "x-inplan-poll-token": pending.pollToken },
|
|
1504
|
-
// Capped to the REMAINING deadline
|
|
1505
|
-
//
|
|
1506
|
-
|
|
1558
|
+
// Capped to the REMAINING deadline — and to the openAck deadline when one is set: an
|
|
1559
|
+
// in-flight request must not let either budget overrun by a whole request-timeout. Without
|
|
1560
|
+
// the second cap a stalled poll could burn the full REQUEST_TIMEOUT_MS (plus a POLL_MS
|
|
1561
|
+
// sleep) before the loop ever re-checks a 6-second ack window.
|
|
1562
|
+
// Cut the request short on a launch failure too, not just on the budget: the opener reports
|
|
1563
|
+
// asynchronously, so without this a report landing mid-request would sit behind a stalled
|
|
1564
|
+
// connection for the whole budget before the loop could act on it.
|
|
1565
|
+
// BOTH extra bounds fall away once the page has acked. The ack window has done its job — and
|
|
1566
|
+
// an AbortSignal stays aborted forever, so a launch signal that has already fired would make
|
|
1567
|
+
// AbortSignal.any born-aborted for every remaining request: each one dies before it leaves,
|
|
1568
|
+
// `launchDead()` rightly declines to throw (the page acked), so the loop sleeps and retries
|
|
1569
|
+
// into the same instant abort until the foreground deadline. A login that was about to
|
|
1570
|
+
// complete would end as "login timed out" instead.
|
|
1571
|
+
signal: launchAwareSignal(
|
|
1572
|
+
pollRequestBudgetMs(now(), deadline, sawOpened ? void 0 : openAckDeadline),
|
|
1573
|
+
sawOpened ? void 0 : opts.launchSignal
|
|
1574
|
+
)
|
|
1507
1575
|
});
|
|
1508
1576
|
} catch {
|
|
1577
|
+
if (launchDead()) throw new BrowserDidNotOpenError("the browser could not be launched");
|
|
1509
1578
|
await sleep(POLL_MS);
|
|
1510
1579
|
continue;
|
|
1511
1580
|
}
|
|
@@ -1543,15 +1612,24 @@ async function rendezvousLogin(opts = {}) {
|
|
|
1543
1612
|
(opts.open ?? openInBrowser)(pending.url);
|
|
1544
1613
|
return pollLoginSession(pending, opts);
|
|
1545
1614
|
}
|
|
1546
|
-
function openInBrowser(url) {
|
|
1615
|
+
function openInBrowser(url, onLaunchFailure) {
|
|
1547
1616
|
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
1548
1617
|
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
1618
|
+
let reported = false;
|
|
1619
|
+
const failed = (kind) => {
|
|
1620
|
+
if (reported) return;
|
|
1621
|
+
reported = true;
|
|
1622
|
+
onLaunchFailure?.(kind);
|
|
1623
|
+
};
|
|
1549
1624
|
try {
|
|
1550
1625
|
const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
|
|
1551
|
-
child.on("error", () =>
|
|
1626
|
+
child.on("error", () => failed("no-opener"));
|
|
1627
|
+
child.on("exit", (code) => {
|
|
1628
|
+
if (code !== 0) failed("opener-declined");
|
|
1552
1629
|
});
|
|
1553
1630
|
child.unref();
|
|
1554
1631
|
} catch {
|
|
1632
|
+
failed("no-opener");
|
|
1555
1633
|
}
|
|
1556
1634
|
}
|
|
1557
1635
|
async function unsealHandoff(privateKeyPkcs8, sealed) {
|
|
@@ -1573,7 +1651,14 @@ async function unsealHandoff(privateKeyPkcs8, sealed) {
|
|
|
1573
1651
|
if (typeof parsed.url !== "string" || typeof parsed.anon !== "string" || typeof parsed.refresh !== "string") {
|
|
1574
1652
|
throw new Error("sign-in handoff was malformed");
|
|
1575
1653
|
}
|
|
1576
|
-
|
|
1654
|
+
const cached = typeof parsed.access === "string" && typeof parsed.expiresAt === "number" ? { accessToken: parsed.access, expiresAt: parsed.expiresAt } : {};
|
|
1655
|
+
return {
|
|
1656
|
+
url: parsed.url,
|
|
1657
|
+
anonKey: parsed.anon,
|
|
1658
|
+
refreshToken: parsed.refresh,
|
|
1659
|
+
...parsed.email ? { email: parsed.email } : {},
|
|
1660
|
+
...cached
|
|
1661
|
+
};
|
|
1577
1662
|
}
|
|
1578
1663
|
|
|
1579
1664
|
// src/cliProfile.ts
|
|
@@ -2247,6 +2332,7 @@ function wakePredicate(wake) {
|
|
|
2247
2332
|
return wake === "any-action" ? (e) => e.actor === "user" && e.type !== LogEventType.SettingsChanged : (e) => e.type === LogEventType.TurnEnded || e.type === LogEventType.SessionClosed || e.type === LogEventType.SaveLocallyRequested || e.type === LogEventType.NavigatedTo;
|
|
2248
2333
|
}
|
|
2249
2334
|
var REOPEN_GRACE_MS = 3 * 6e4;
|
|
2335
|
+
var PRESENCE_GONE_GRACE_MS = 9e4;
|
|
2250
2336
|
async function awaitReopen(channel, cursor, opts = {}) {
|
|
2251
2337
|
const graceMs = opts.graceMs ?? REOPEN_GRACE_MS;
|
|
2252
2338
|
const pollMs = opts.pollMs ?? 2e3;
|
|
@@ -2300,6 +2386,7 @@ function waitForActions(opts) {
|
|
|
2300
2386
|
const pollMs = opts.pollMs ?? 200;
|
|
2301
2387
|
const isActionable = opts.isActionable ?? defaultActionable;
|
|
2302
2388
|
const watchEditor = opts.watchEditor ?? true;
|
|
2389
|
+
const presenceGoneGraceMs = opts.presenceGoneGraceMs ?? PRESENCE_GONE_GRACE_MS;
|
|
2303
2390
|
const errorGraceMs = opts.errorGraceMs ?? DEFAULT_ERROR_GRACE_MS;
|
|
2304
2391
|
const pollTimeoutMs = opts.pollTimeoutMs ?? DEFAULT_POLL_TIMEOUT_MS;
|
|
2305
2392
|
const now = opts.now ?? Date.now;
|
|
@@ -2308,6 +2395,7 @@ function waitForActions(opts) {
|
|
|
2308
2395
|
let deadline = null;
|
|
2309
2396
|
let lastCount = -1;
|
|
2310
2397
|
let sawEditorAlive = false;
|
|
2398
|
+
let goneSince = null;
|
|
2311
2399
|
let busy = false;
|
|
2312
2400
|
let done = false;
|
|
2313
2401
|
let failingSince = null;
|
|
@@ -2357,10 +2445,16 @@ function waitForActions(opts) {
|
|
|
2357
2445
|
if (!presences.busy()) alive = await presences.run(() => ch.presence(), pollTimeoutMs);
|
|
2358
2446
|
} catch {
|
|
2359
2447
|
}
|
|
2360
|
-
if (alive === true)
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2448
|
+
if (alive === true) {
|
|
2449
|
+
sawEditorAlive = true;
|
|
2450
|
+
goneSince = null;
|
|
2451
|
+
} else if (alive === false && sawEditorAlive) {
|
|
2452
|
+
const at = now();
|
|
2453
|
+
goneSince ??= at;
|
|
2454
|
+
if (at - goneSince >= presenceGoneGraceMs) {
|
|
2455
|
+
finish({ entries, cursor, editorGone: true });
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2364
2458
|
}
|
|
2365
2459
|
}
|
|
2366
2460
|
if (entries.some(isActionable)) {
|
|
@@ -2664,6 +2758,12 @@ function logWaitExit(p, reason) {
|
|
|
2664
2758
|
} catch {
|
|
2665
2759
|
}
|
|
2666
2760
|
}
|
|
2761
|
+
function resolveWaitStatus(input) {
|
|
2762
|
+
if (input.closeReason !== null) return { status: "closed", reason: input.closeReason };
|
|
2763
|
+
if (input.editorGone && !input.hasActionable) return { status: "closed", reason: "crashed_or_killed" };
|
|
2764
|
+
if (input.editorGone) return { status: input.locksEditor ? "your_turn" : "activity", editorGone: true };
|
|
2765
|
+
return { status: input.locksEditor ? "your_turn" : "activity" };
|
|
2766
|
+
}
|
|
2667
2767
|
async function waitCycle(backend, explicitCursor, confirmed, model, gate = null) {
|
|
2668
2768
|
const { channel, store } = backend;
|
|
2669
2769
|
const history = await backend.history();
|
|
@@ -2804,17 +2904,12 @@ async function waitCycle(backend, explicitCursor, confirmed, model, gate = null)
|
|
|
2804
2904
|
}
|
|
2805
2905
|
process.stderr.write("inplan: the editor did not come back \u2014 treating the session as closed.\n");
|
|
2806
2906
|
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
}
|
|
2813
|
-
status = "closed";
|
|
2814
|
-
reason = "crashed_or_killed";
|
|
2815
|
-
} else {
|
|
2816
|
-
status = mode.locksEditor ? "your_turn" : "activity";
|
|
2817
|
-
}
|
|
2907
|
+
const { status, reason, editorGone } = resolveWaitStatus({
|
|
2908
|
+
closeReason: closeEntry ? closeEntry.payload?.reason ?? "completed" : null,
|
|
2909
|
+
editorGone: result.editorGone === true,
|
|
2910
|
+
hasActionable: result.entries.some(isActionable),
|
|
2911
|
+
locksEditor: mode.locksEditor
|
|
2912
|
+
});
|
|
2818
2913
|
backend.logExit(`status:${status}${reason ? `/${reason}` : ""}`);
|
|
2819
2914
|
output({
|
|
2820
2915
|
status,
|
|
@@ -2827,6 +2922,12 @@ async function waitCycle(backend, explicitCursor, confirmed, model, gate = null)
|
|
|
2827
2922
|
// when --model was passed), so presence + authorship stay consistent.
|
|
2828
2923
|
agentAuthor: agentAuthorFor(model),
|
|
2829
2924
|
...reason ? { reason } : {},
|
|
2925
|
+
// The human handed the turn back and THEN left. Surfaced because the handoff status
|
|
2926
|
+
// deliberately outranks the departure, and dropping the departure entirely would strand the
|
|
2927
|
+
// agent: a fresh `wait` starts with `sawEditorAlive` false, so an editor that is already gone
|
|
2928
|
+
// never flips it and that wait would block instead of reporting the closure. Act on the
|
|
2929
|
+
// handoff, then stop — do not wait again.
|
|
2930
|
+
...editorGone ? { editorGone: true } : {},
|
|
2830
2931
|
// The landing signal for a parked Review-mode edit (#88): pending_review means the push
|
|
2831
2932
|
// REACHED the store and awaits the human — the canonical is unchanged by design. Absent
|
|
2832
2933
|
// when the turn applied directly (or made no body change).
|
|
@@ -2869,6 +2970,7 @@ async function doLogin(args) {
|
|
|
2869
2970
|
`);
|
|
2870
2971
|
const auth = await pollLoginSession(pending, { onNudge: printLoginNudge });
|
|
2871
2972
|
saveAuth(auth);
|
|
2973
|
+
await primeSessionOrFail();
|
|
2872
2974
|
await persistCloudIdentity();
|
|
2873
2975
|
output({ status: "logged_in", url: auth.url, ...auth.email ? { email: auth.email } : {} });
|
|
2874
2976
|
return;
|
|
@@ -2880,6 +2982,38 @@ async function doLogin(args) {
|
|
|
2880
2982
|
}
|
|
2881
2983
|
}
|
|
2882
2984
|
}
|
|
2985
|
+
if (canAttemptBrowserLaunch()) {
|
|
2986
|
+
let minted;
|
|
2987
|
+
try {
|
|
2988
|
+
minted = await createLoginSession();
|
|
2989
|
+
const launch = new AbortController();
|
|
2990
|
+
openInBrowser(minted.url, (kind) => {
|
|
2991
|
+
if (kind === "no-opener") launch.abort();
|
|
2992
|
+
});
|
|
2993
|
+
const auth = await pollLoginSession(minted, {
|
|
2994
|
+
openAckMs: OPEN_ACK_MS,
|
|
2995
|
+
launchSignal: launch.signal,
|
|
2996
|
+
onNudge: printLoginNudge
|
|
2997
|
+
});
|
|
2998
|
+
saveAuth(auth);
|
|
2999
|
+
await primeSessionOrFail();
|
|
3000
|
+
await persistCloudIdentity();
|
|
3001
|
+
output({ status: "logged_in", url: auth.url, ...auth.email ? { email: auth.email } : {} });
|
|
3002
|
+
return;
|
|
3003
|
+
} catch (e) {
|
|
3004
|
+
if (e instanceof BrowserDidNotOpenError) {
|
|
3005
|
+
await pendingLoginExit(minted);
|
|
3006
|
+
process.exit(1);
|
|
3007
|
+
}
|
|
3008
|
+
if (e instanceof LoginSessionExpiredError) {
|
|
3009
|
+
await pendingLoginExit();
|
|
3010
|
+
process.exit(1);
|
|
3011
|
+
}
|
|
3012
|
+
process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
|
|
3013
|
+
`);
|
|
3014
|
+
process.exit(1);
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
2883
3017
|
await pendingLoginExit();
|
|
2884
3018
|
process.exit(1);
|
|
2885
3019
|
}
|
|
@@ -2895,6 +3029,7 @@ async function doLogin(args) {
|
|
|
2895
3029
|
// INPLAN_NO_BROWSER: never launch one — the printed URL is the flow
|
|
2896
3030
|
}) : await defaultRendezvousLogin();
|
|
2897
3031
|
saveAuth(auth);
|
|
3032
|
+
await primeSessionOrFail();
|
|
2898
3033
|
await persistCloudIdentity();
|
|
2899
3034
|
output({ status: "logged_in", url: auth.url, ...auth.email ? { email: auth.email } : {} });
|
|
2900
3035
|
} catch (e) {
|
|
@@ -2903,6 +3038,55 @@ async function doLogin(args) {
|
|
|
2903
3038
|
process.exit(1);
|
|
2904
3039
|
}
|
|
2905
3040
|
}
|
|
3041
|
+
var OPEN_ACK_MS = 2e4;
|
|
3042
|
+
function canAttemptBrowserLaunch() {
|
|
3043
|
+
return !process.env.CI && !process.env.INPLAN_NO_BROWSER;
|
|
3044
|
+
}
|
|
3045
|
+
async function primeSessionOrFail(retryDelayMs = 750) {
|
|
3046
|
+
const refused = (what) => {
|
|
3047
|
+
clearAuth();
|
|
3048
|
+
process.stderr.write(
|
|
3049
|
+
`inplan login: signed in, but the server rejected the credential the browser handed over \u2014 ${what}
|
|
3050
|
+
Sign in again. If this repeats, the browser session is rotating the token before the CLI
|
|
3051
|
+
can claim it, and the sign-in page needs to hand over an unused token (or an access token).
|
|
3052
|
+
`
|
|
3053
|
+
);
|
|
3054
|
+
process.exit(1);
|
|
3055
|
+
};
|
|
3056
|
+
const unproven = () => {
|
|
3057
|
+
process.stderr.write(
|
|
3058
|
+
"inplan login: signed in, but the credential could not be verified \u2014 the check did not get an\n answer from the server (network, an outage, or another `inplan` holding the refresh lock).\n The credential is KEPT, not discarded: run the command again, or `inplan whoami` to check.\n"
|
|
3059
|
+
);
|
|
3060
|
+
process.exit(1);
|
|
3061
|
+
};
|
|
3062
|
+
const withOneRetry = async (check) => {
|
|
3063
|
+
const first = await check();
|
|
3064
|
+
if (first !== "inconclusive") return first;
|
|
3065
|
+
await new Promise((r) => setTimeout(r, retryDelayMs));
|
|
3066
|
+
return check();
|
|
3067
|
+
};
|
|
3068
|
+
const cached = await withOneRetry(verifyCachedAccessToken);
|
|
3069
|
+
if (cached === "ok") return;
|
|
3070
|
+
if (cached === "rejected") refused("its access token was not accepted.");
|
|
3071
|
+
if (cached === "inconclusive") unproven();
|
|
3072
|
+
const FORCE_REFRESH_SKEW_S = 10 * 365 * 24 * 3600;
|
|
3073
|
+
const forceRefresh = async () => {
|
|
3074
|
+
const before = loadAuth()?.refreshToken;
|
|
3075
|
+
let refusal = "inconclusive";
|
|
3076
|
+
const session = await authedSession(FORCE_REFRESH_SKEW_S, (reason, cause) => {
|
|
3077
|
+
refusal = reason === "inconclusive" ? "inconclusive" : cause === "refresh-token-spent" ? "rejected-spent" : "rejected-other";
|
|
3078
|
+
});
|
|
3079
|
+
if (!session) return refusal;
|
|
3080
|
+
return loadAuth()?.refreshToken !== before ? "ok" : "inconclusive";
|
|
3081
|
+
};
|
|
3082
|
+
const refreshed = await withOneRetry(forceRefresh);
|
|
3083
|
+
if (refreshed === "ok") return;
|
|
3084
|
+
if (refreshed === "rejected-spent") refused("its refresh token had already been spent, so it could never have been used.");
|
|
3085
|
+
if (refreshed === "rejected-other") {
|
|
3086
|
+
refused("the server refused it \u2014 the token may be invalid or revoked, or this deployment's anon key may no longer match.");
|
|
3087
|
+
}
|
|
3088
|
+
unproven();
|
|
3089
|
+
}
|
|
2906
3090
|
async function persistCloudIdentity() {
|
|
2907
3091
|
try {
|
|
2908
3092
|
const user = await currentUser();
|
|
@@ -2978,11 +3162,11 @@ function scrubAgentEnv(env) {
|
|
|
2978
3162
|
}
|
|
2979
3163
|
return out;
|
|
2980
3164
|
}
|
|
2981
|
-
async function pendingLoginExit() {
|
|
3165
|
+
async function pendingLoginExit(existing) {
|
|
2982
3166
|
let url;
|
|
2983
3167
|
let expiresInSec;
|
|
2984
3168
|
try {
|
|
2985
|
-
const pending = await createLoginSession();
|
|
3169
|
+
const pending = existing ?? await createLoginSession();
|
|
2986
3170
|
url = pending.url;
|
|
2987
3171
|
expiresInSec = Math.max(0, Math.floor((pending.expiresAt - Date.now()) / 1e3));
|
|
2988
3172
|
} catch (e) {
|
|
@@ -4312,6 +4496,8 @@ export {
|
|
|
4312
4496
|
explainNoGate,
|
|
4313
4497
|
isKnownAgentEnv,
|
|
4314
4498
|
notesFromHook,
|
|
4499
|
+
primeSessionOrFail,
|
|
4500
|
+
resolveWaitStatus,
|
|
4315
4501
|
scrubAgentEnv,
|
|
4316
4502
|
shellQuote,
|
|
4317
4503
|
transcriptTextBlocks,
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -268,6 +268,13 @@ the plan, then call `wait`.** Do not pass `--cursor` and do not hand-manage it.
|
|
|
268
268
|
building what the document specifies (it's no longer a planning doc — act on it).
|
|
269
269
|
- `window_closed` — they just closed the editor; **stop** and take no further action.
|
|
270
270
|
- `crashed_or_killed` — the editor vanished with no close log; surface this to the human.
|
|
271
|
+
Only reported once the absence has persisted (a heartbeat that merely stalled — a
|
|
272
|
+
backgrounded tab, a network blip — is not a departure), and never in place of work you
|
|
273
|
+
were waiting for: if the human handed the turn back and *then* left, you get that
|
|
274
|
+
handoff (`your_turn` / `activity`) with **`editorGone: true`** alongside it. Treat that
|
|
275
|
+
flag as the closure: do the work the handoff describes, then **stop**. Do not call `wait`
|
|
276
|
+
again — the editor is already gone, so the next wait has nothing to see it leave and will
|
|
277
|
+
block rather than report it.
|
|
271
278
|
- `superseded` — a newer `wait` took over this document (only one waiter runs at
|
|
272
279
|
a time). This one stepped down; **do nothing** — the live waiter is in charge.
|
|
273
280
|
- `navigated` — the human followed an in-window link to a **different document**;
|
|
@@ -302,13 +309,17 @@ the plan, then call `wait`.** Do not pass `--cursor` and do not hand-manage it.
|
|
|
302
309
|
inplan wait <name>.plan.md
|
|
303
310
|
|
|
304
311
|
`your_turn` and `activity` are **not** stop conditions — you always loop back
|
|
305
|
-
and keep waiting.
|
|
312
|
+
and keep waiting. Two things end the loop: `status: closed`, or a handoff that
|
|
313
|
+
also carries `editorGone: true` (the human handed the turn back and then left —
|
|
314
|
+
finish that turn's work, then stop; see `crashed_or_killed` above for why a
|
|
315
|
+
further `wait` would block instead of reporting the closure).
|
|
306
316
|
|
|
307
317
|
6. When you believe the plan is ready, signal it (the human still decides):
|
|
308
318
|
|
|
309
319
|
inplan signal <name>.plan.md --done
|
|
310
320
|
|
|
311
|
-
Then wait again
|
|
321
|
+
Then wait again, and stop on the same two conditions as step 5: `status: closed`,
|
|
322
|
+
or a handoff carrying `editorGone: true`.
|
|
312
323
|
|
|
313
324
|
## Keeping the human informed
|
|
314
325
|
|