inplan 0.1.27 → 0.1.28
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 +503 -252
- package/package.json +1 -1
- package/skill/SKILL.md +16 -0
package/bin/cli.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
import { execFileSync as execFileSync2, spawn as spawn3, spawnSync } from "child_process";
|
|
5
5
|
import { createHash as createHash4 } from "crypto";
|
|
6
6
|
import { createRequire } from "module";
|
|
7
|
-
import { appendFileSync as appendFileSync2, copyFileSync, existsSync as
|
|
8
|
-
import { homedir as
|
|
9
|
-
import { basename as basename3, dirname as
|
|
7
|
+
import { appendFileSync as appendFileSync2, copyFileSync, existsSync as existsSync10, mkdirSync as mkdirSync9, readdirSync as readdirSync2, readFileSync as readFileSync10, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statSync as statSync4, writeFileSync as writeFileSync9 } from "fs";
|
|
8
|
+
import { homedir as homedir7 } from "os";
|
|
9
|
+
import { basename as basename3, dirname as dirname10, isAbsolute as isAbsolute2, join as join10, relative as relative4, resolve as resolve3 } from "path";
|
|
10
10
|
import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
|
|
11
11
|
|
|
12
12
|
// ../core/dist/chunk-2A42CIA7.js
|
|
@@ -512,7 +512,7 @@ function writeStatus(statusPath, status) {
|
|
|
512
512
|
writeFileSync4(statusPath, `${JSON.stringify(status, null, 2)}
|
|
513
513
|
`);
|
|
514
514
|
}
|
|
515
|
-
var PLUGIN_PUBLIC_KEY =
|
|
515
|
+
var PLUGIN_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAVP11te5E7xzNJ4reKg0+mAnrr91gcyD1bMr43Homq98=\n-----END PUBLIC KEY-----\n";
|
|
516
516
|
function verifyLease(token, publicKeyPem = PLUGIN_PUBLIC_KEY, now = Date.now()) {
|
|
517
517
|
try {
|
|
518
518
|
if (!publicKeyPem || typeof token !== "string") return null;
|
|
@@ -1054,115 +1054,289 @@ function liveRemoteBackend(docId, consumerId = "cli-agent") {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
|
|
1056
1056
|
// src/cliLogin.ts
|
|
1057
|
-
import { createServer } from "http";
|
|
1058
1057
|
import { spawn } from "child_process";
|
|
1059
|
-
import {
|
|
1058
|
+
import { webcrypto } from "crypto";
|
|
1059
|
+
import { chmodSync as chmodSync2, existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync7, rmdirSync, statSync as statSync3, unlinkSync as unlinkSync2, writeFileSync as writeFileSync6 } from "fs";
|
|
1060
|
+
import { homedir as homedir5 } from "os";
|
|
1061
|
+
import { dirname as dirname6, join as join7 } from "path";
|
|
1062
|
+
|
|
1063
|
+
// src/pluginGate.ts
|
|
1064
|
+
import { homedir as homedir4 } from "os";
|
|
1065
|
+
import { join as join6 } from "path";
|
|
1066
|
+
import { pathToFileURL } from "url";
|
|
1067
|
+
var DEFAULT_HUB_URL = "wss://inplan-collab.fly.dev";
|
|
1068
|
+
var resolveHubUrl = () => process.env.INPLAN_PLUGIN_URL || process.env.INPLAN_COLLAB_URL || DEFAULT_HUB_URL;
|
|
1069
|
+
var hubHttpBase = () => resolveHubUrl().replace(/^ws/, "http").replace(/\/+$/, "");
|
|
1070
|
+
var PLUGIN_HTTP = hubHttpBase();
|
|
1071
|
+
var defaultCacheDir = () => join6(process.env.INPLAN_HOME || join6(homedir4(), ".inplan"), "plugin-cache");
|
|
1072
|
+
var defaultDeps = {
|
|
1073
|
+
resolve: resolvePluginOutcome,
|
|
1074
|
+
importCli: (p) => import(pathToFileURL(p).href)
|
|
1075
|
+
};
|
|
1076
|
+
async function loadPluginGateOutcome(session, options, deps = defaultDeps) {
|
|
1077
|
+
try {
|
|
1078
|
+
const { plugin, reason } = await deps.resolve({
|
|
1079
|
+
apiBase: options.apiBase ?? PLUGIN_HTTP,
|
|
1080
|
+
token: options.token,
|
|
1081
|
+
cacheDir: options.cacheDir ?? defaultCacheDir(),
|
|
1082
|
+
// Forward whenever DEFINED, not whenever truthy: an explicit `""` means "nothing can be
|
|
1083
|
+
// verified" and must reach the resolver, which then refuses without a network call. Dropping
|
|
1084
|
+
// it would silently substitute the baked-in key and verify against something the caller
|
|
1085
|
+
// deliberately disabled.
|
|
1086
|
+
...options.publicKey !== void 0 ? { publicKey: options.publicKey } : {}
|
|
1087
|
+
});
|
|
1088
|
+
if (!plugin) return { gate: null, reason };
|
|
1089
|
+
const cliName = plugin.entries.cli;
|
|
1090
|
+
const cliPath = cliName ? plugin.files[cliName] : void 0;
|
|
1091
|
+
if (!cliPath) return { gate: null, reason: "unavailable" };
|
|
1092
|
+
const cli = await deps.importCli(cliPath);
|
|
1093
|
+
return { gate: cli.gate(session), reason: null };
|
|
1094
|
+
} catch {
|
|
1095
|
+
return { gate: null, reason: "unavailable" };
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
async function loadPluginGate(session, options, deps = defaultDeps) {
|
|
1099
|
+
try {
|
|
1100
|
+
return (await loadPluginGateOutcome(session, options, deps)).gate;
|
|
1101
|
+
} catch {
|
|
1102
|
+
return null;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
// src/cliLogin.ts
|
|
1107
|
+
var subtle = webcrypto.subtle;
|
|
1060
1108
|
var DEFAULT_WEB_ORIGIN = process.env.INPLAN_WEB_URL || "https://inplan.ai";
|
|
1109
|
+
var HKDF_INFO = "inplan cli-login v1";
|
|
1061
1110
|
var DEFAULT_TIMEOUT_MS = 3 * 6e4;
|
|
1062
|
-
var
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1111
|
+
var POLL_MS = 2e3;
|
|
1112
|
+
var NUDGE_MS = 3e4;
|
|
1113
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
1114
|
+
function loginApiBase() {
|
|
1115
|
+
return hubHttpBase();
|
|
1116
|
+
}
|
|
1117
|
+
function pendingLoginPath() {
|
|
1118
|
+
const base2 = process.env.INPLAN_HOME || join7(homedir5(), ".inplan");
|
|
1119
|
+
return join7(base2, "login-pending.json");
|
|
1120
|
+
}
|
|
1121
|
+
function clearPendingLogin() {
|
|
1066
1122
|
try {
|
|
1067
|
-
|
|
1068
|
-
child.on("error", () => {
|
|
1069
|
-
});
|
|
1070
|
-
child.unref();
|
|
1123
|
+
unlinkSync2(pendingLoginPath());
|
|
1071
1124
|
} catch {
|
|
1072
1125
|
}
|
|
1073
1126
|
}
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1127
|
+
var LOCK_WAIT_MS2 = 2e3;
|
|
1128
|
+
var LOCK_RETRY_MS = 25;
|
|
1129
|
+
var LOCK_STALE_MS2 = 5e3;
|
|
1130
|
+
async function withSidecarLock(fn) {
|
|
1131
|
+
const lock = pendingLoginPath() + ".lock";
|
|
1132
|
+
const deadline = Date.now() + LOCK_WAIT_MS2;
|
|
1133
|
+
for (; ; ) {
|
|
1134
|
+
try {
|
|
1135
|
+
mkdirSync6(lock, { recursive: false });
|
|
1136
|
+
break;
|
|
1137
|
+
} catch (e) {
|
|
1138
|
+
if (e.code !== "EEXIST") throw e;
|
|
1139
|
+
try {
|
|
1140
|
+
if (Date.now() - statSync3(lock).mtimeMs > LOCK_STALE_MS2) rmdirSync(lock);
|
|
1141
|
+
} catch {
|
|
1142
|
+
}
|
|
1143
|
+
if (Date.now() > deadline) throw new Error("could not acquire the login lock \u2014 another inplan process is holding it");
|
|
1144
|
+
await new Promise((r) => setTimeout(r, LOCK_RETRY_MS));
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
try {
|
|
1148
|
+
return await fn();
|
|
1149
|
+
} finally {
|
|
1150
|
+
try {
|
|
1151
|
+
rmdirSync(lock);
|
|
1152
|
+
} catch {
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
async function clearPendingLoginFor(sessionId) {
|
|
1157
|
+
await withSidecarLock(() => {
|
|
1158
|
+
const path = pendingLoginPath();
|
|
1159
|
+
try {
|
|
1160
|
+
const p = JSON.parse(readFileSync7(path, "utf8"));
|
|
1161
|
+
if (p.sessionId !== sessionId) return;
|
|
1162
|
+
} catch {
|
|
1163
|
+
}
|
|
1164
|
+
clearPendingLogin();
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
function loadPendingLoginLocked(now) {
|
|
1168
|
+
const path = pendingLoginPath();
|
|
1169
|
+
if (!existsSync8(path)) return null;
|
|
1170
|
+
try {
|
|
1171
|
+
const p = JSON.parse(readFileSync7(path, "utf8"));
|
|
1172
|
+
if (typeof p.sessionId !== "string" || typeof p.privateKeyPkcs8 !== "string" || typeof p.pollToken !== "string" || typeof p.url !== "string" || typeof p.apiBase !== "string" || typeof p.expiresAt !== "number" || p.expiresAt <= now) {
|
|
1173
|
+
clearPendingLogin();
|
|
1174
|
+
return null;
|
|
1175
|
+
}
|
|
1176
|
+
return p;
|
|
1177
|
+
} catch {
|
|
1178
|
+
clearPendingLogin();
|
|
1179
|
+
return null;
|
|
1180
|
+
}
|
|
1078
1181
|
}
|
|
1079
|
-
function
|
|
1182
|
+
function loadPendingLogin(now = Date.now()) {
|
|
1183
|
+
return withSidecarLock(() => loadPendingLoginLocked(now));
|
|
1184
|
+
}
|
|
1185
|
+
async function createLoginSession(opts = {}) {
|
|
1186
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
1187
|
+
const now = opts.now ?? Date.now;
|
|
1188
|
+
const existing = await loadPendingLogin(now());
|
|
1189
|
+
if (existing) return existing;
|
|
1190
|
+
const apiBase = opts.apiBase ?? loginApiBase();
|
|
1080
1191
|
const webOrigin = (opts.webOrigin ?? DEFAULT_WEB_ORIGIN).replace(/\/$/, "");
|
|
1081
|
-
const
|
|
1082
|
-
const
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1192
|
+
const keys = await subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
|
|
1193
|
+
const pub = Buffer.from(await subtle.exportKey("spki", keys.publicKey)).toString("base64");
|
|
1194
|
+
const priv = Buffer.from(await subtle.exportKey("pkcs8", keys.privateKey)).toString("base64");
|
|
1195
|
+
const res = await fetchImpl(`${apiBase}/api/v1/cli-login`, { method: "POST", signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) });
|
|
1196
|
+
if (!res.ok) throw new Error(`could not start a sign-in session (HTTP ${res.status})`);
|
|
1197
|
+
const { sessionId, pollToken, expiresInSec } = await res.json();
|
|
1198
|
+
if (typeof sessionId !== "string" || !sessionId || typeof pollToken !== "string" || !pollToken) {
|
|
1199
|
+
throw new Error("could not start a sign-in session (bad response)");
|
|
1200
|
+
}
|
|
1201
|
+
const pending = {
|
|
1202
|
+
sessionId,
|
|
1203
|
+
privateKeyPkcs8: priv,
|
|
1204
|
+
pollToken,
|
|
1205
|
+
// `pub` rides the URL FRAGMENT so it never reaches server access logs (a log reader holding
|
|
1206
|
+
// session + pub could complete the session for their own account); the page reads it from
|
|
1207
|
+
// location.hash. Public key or not, keep the whole capability out of logs.
|
|
1208
|
+
url: `${webOrigin}/cli-auth?session=${encodeURIComponent(sessionId)}#pub=${encodeURIComponent(pub)}`,
|
|
1209
|
+
apiBase,
|
|
1210
|
+
// Guard against a bogus server TTL: NaN/Infinity/negative would make expiresAt a past
|
|
1211
|
+
// timestamp — or one that NEVER expires (NaN compares false forever), leaving a dead sidecar
|
|
1212
|
+
// that every later invocation resumes until the server 404s.
|
|
1213
|
+
expiresAt: now() + (Number.isFinite(expiresInSec) && expiresInSec > 0 ? expiresInSec : 600) * 1e3
|
|
1214
|
+
};
|
|
1215
|
+
const path = pendingLoginPath();
|
|
1216
|
+
mkdirSync6(dirname6(path), { recursive: true });
|
|
1217
|
+
return withSidecarLock(() => {
|
|
1218
|
+
const winner = loadPendingLoginLocked(now());
|
|
1219
|
+
if (winner) return winner;
|
|
1220
|
+
writeFileSync6(path, JSON.stringify(pending, null, 2), { mode: 384 });
|
|
1221
|
+
chmodSync2(path, 384);
|
|
1222
|
+
return pending;
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
var LoginSessionExpiredError = class extends Error {
|
|
1226
|
+
};
|
|
1227
|
+
async function pollLoginSession(pending, opts = {}) {
|
|
1228
|
+
const fetchImpl = opts.fetchImpl ?? fetch;
|
|
1229
|
+
const now = opts.now ?? Date.now;
|
|
1230
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
1231
|
+
const deadline = now() + (opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
1232
|
+
const nudgeAt = now() + NUDGE_MS;
|
|
1233
|
+
let nudged = false;
|
|
1234
|
+
let sawOpened = false;
|
|
1235
|
+
while (true) {
|
|
1236
|
+
if (!nudged && !sawOpened && now() >= nudgeAt) {
|
|
1237
|
+
nudged = true;
|
|
1238
|
+
opts.onNudge?.();
|
|
1239
|
+
}
|
|
1240
|
+
if (now() >= pending.expiresAt) {
|
|
1241
|
+
await clearPendingLoginFor(pending.sessionId);
|
|
1242
|
+
throw new LoginSessionExpiredError("the sign-in link expired \u2014 run the command again for a fresh one");
|
|
1243
|
+
}
|
|
1244
|
+
if (now() >= deadline) throw new Error("login timed out \u2014 no response from the browser");
|
|
1245
|
+
let res;
|
|
1246
|
+
try {
|
|
1247
|
+
res = await fetchImpl(`${pending.apiBase}/api/v1/cli-login/${encodeURIComponent(pending.sessionId)}`, {
|
|
1248
|
+
method: "GET",
|
|
1249
|
+
// The poll credential rides a header (never a URL, so never an access log) — see
|
|
1250
|
+
// PendingLogin.pollToken: the session id alone must not read or destroy the handoff.
|
|
1251
|
+
headers: { "x-inplan-poll-token": pending.pollToken },
|
|
1252
|
+
// Capped to the REMAINING deadline: an in-flight request must not let the foreground
|
|
1253
|
+
// wait overrun its budget by a whole request-timeout.
|
|
1254
|
+
signal: AbortSignal.timeout(Math.max(1, Math.min(REQUEST_TIMEOUT_MS, deadline - now())))
|
|
1119
1255
|
});
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1256
|
+
} catch {
|
|
1257
|
+
await sleep(POLL_MS);
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
if (res.status === 404) {
|
|
1261
|
+
await clearPendingLoginFor(pending.sessionId);
|
|
1262
|
+
throw new LoginSessionExpiredError("the sign-in link expired \u2014 run the command again for a fresh one");
|
|
1263
|
+
}
|
|
1264
|
+
if (res.ok) {
|
|
1265
|
+
let body;
|
|
1266
|
+
try {
|
|
1267
|
+
body = await res.json();
|
|
1268
|
+
} catch {
|
|
1269
|
+
await sleep(POLL_MS);
|
|
1270
|
+
continue;
|
|
1271
|
+
}
|
|
1272
|
+
if (body.status === "completed" && body.epk && body.iv && body.ct) {
|
|
1273
|
+
let auth;
|
|
1126
1274
|
try {
|
|
1127
|
-
|
|
1275
|
+
auth = await unsealHandoff(pending.privateKeyPkcs8, { epk: body.epk, iv: body.iv, ct: body.ct });
|
|
1128
1276
|
} catch {
|
|
1129
|
-
|
|
1130
|
-
|
|
1277
|
+
await clearPendingLoginFor(pending.sessionId);
|
|
1278
|
+
throw new LoginSessionExpiredError("the sign-in handoff could not be read \u2014 run the command again for a fresh link");
|
|
1131
1279
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1280
|
+
await clearPendingLoginFor(pending.sessionId);
|
|
1281
|
+
return auth;
|
|
1282
|
+
}
|
|
1283
|
+
if (body.status === "opened" || body.status === "completed") sawOpened = true;
|
|
1284
|
+
}
|
|
1285
|
+
await sleep(POLL_MS);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
async function rendezvousLogin(opts = {}) {
|
|
1289
|
+
const pending = await createLoginSession(opts);
|
|
1290
|
+
opts.onUrl?.(pending.url);
|
|
1291
|
+
(opts.open ?? openInBrowser)(pending.url);
|
|
1292
|
+
return pollLoginSession(pending, opts);
|
|
1293
|
+
}
|
|
1294
|
+
function openInBrowser(url) {
|
|
1295
|
+
const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
|
|
1296
|
+
const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
|
|
1297
|
+
try {
|
|
1298
|
+
const child = spawn(cmd, args, { detached: true, stdio: "ignore" });
|
|
1299
|
+
child.on("error", () => {
|
|
1149
1300
|
});
|
|
1150
|
-
|
|
1301
|
+
child.unref();
|
|
1302
|
+
} catch {
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
async function unsealHandoff(privateKeyPkcs8, sealed) {
|
|
1306
|
+
const privateKey = await subtle.importKey("pkcs8", Buffer.from(privateKeyPkcs8, "base64"), { name: "ECDH", namedCurve: "P-256" }, false, [
|
|
1307
|
+
"deriveBits"
|
|
1308
|
+
]);
|
|
1309
|
+
const epk = await subtle.importKey("spki", Buffer.from(sealed.epk, "base64"), { name: "ECDH", namedCurve: "P-256" }, false, []);
|
|
1310
|
+
const shared = await subtle.deriveBits({ name: "ECDH", public: epk }, privateKey, 256);
|
|
1311
|
+
const hkdfKey = await subtle.importKey("raw", shared, "HKDF", false, ["deriveKey"]);
|
|
1312
|
+
const aes = await subtle.deriveKey(
|
|
1313
|
+
{ name: "HKDF", hash: "SHA-256", salt: new Uint8Array(0), info: new TextEncoder().encode(HKDF_INFO) },
|
|
1314
|
+
hkdfKey,
|
|
1315
|
+
{ name: "AES-GCM", length: 256 },
|
|
1316
|
+
false,
|
|
1317
|
+
["decrypt"]
|
|
1318
|
+
);
|
|
1319
|
+
const pt = await subtle.decrypt({ name: "AES-GCM", iv: Buffer.from(sealed.iv, "base64") }, aes, Buffer.from(sealed.ct, "base64"));
|
|
1320
|
+
const parsed = JSON.parse(new TextDecoder().decode(pt));
|
|
1321
|
+
if (typeof parsed.url !== "string" || typeof parsed.anon !== "string" || typeof parsed.refresh !== "string") {
|
|
1322
|
+
throw new Error("sign-in handoff was malformed");
|
|
1323
|
+
}
|
|
1324
|
+
return { url: parsed.url, anonKey: parsed.anon, refreshToken: parsed.refresh, ...parsed.email ? { email: parsed.email } : {} };
|
|
1151
1325
|
}
|
|
1152
1326
|
|
|
1153
1327
|
// src/cliProfile.ts
|
|
1154
|
-
import { existsSync as
|
|
1155
|
-
import { homedir as
|
|
1156
|
-
import { dirname as
|
|
1328
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
1329
|
+
import { homedir as homedir6 } from "os";
|
|
1330
|
+
import { dirname as dirname7, join as join8 } from "path";
|
|
1157
1331
|
function profilePath() {
|
|
1158
|
-
const base2 = process.env.INPLAN_HOME ||
|
|
1159
|
-
return
|
|
1332
|
+
const base2 = process.env.INPLAN_HOME || join8(homedir6(), ".inplan");
|
|
1333
|
+
return join8(base2, "profile.json");
|
|
1160
1334
|
}
|
|
1161
1335
|
function readLocalProfile() {
|
|
1162
1336
|
const p = profilePath();
|
|
1163
|
-
if (!
|
|
1337
|
+
if (!existsSync9(p)) return null;
|
|
1164
1338
|
try {
|
|
1165
|
-
const raw = JSON.parse(
|
|
1339
|
+
const raw = JSON.parse(readFileSync8(p, "utf8"));
|
|
1166
1340
|
if (typeof raw.name !== "string" || raw.name.trim() === "") return null;
|
|
1167
1341
|
const source = raw.source === "cloud" || raw.source === "git" ? raw.source : "manual";
|
|
1168
1342
|
return { name: raw.name.trim(), ...raw.email ? { email: raw.email } : {}, source };
|
|
@@ -1172,8 +1346,8 @@ function readLocalProfile() {
|
|
|
1172
1346
|
}
|
|
1173
1347
|
function writeLocalProfile(p) {
|
|
1174
1348
|
const path = profilePath();
|
|
1175
|
-
|
|
1176
|
-
|
|
1349
|
+
mkdirSync7(dirname7(path), { recursive: true });
|
|
1350
|
+
writeFileSync7(path, `${JSON.stringify(p, null, 2)}
|
|
1177
1351
|
`);
|
|
1178
1352
|
}
|
|
1179
1353
|
function setManualProfile(name, email) {
|
|
@@ -1198,7 +1372,7 @@ async function resolveIdentity(file) {
|
|
|
1198
1372
|
}
|
|
1199
1373
|
}
|
|
1200
1374
|
if (file) {
|
|
1201
|
-
const git = gitIdentity(
|
|
1375
|
+
const git = gitIdentity(dirname7(file));
|
|
1202
1376
|
if (git) {
|
|
1203
1377
|
const prof = fromParts(git, "git");
|
|
1204
1378
|
if (prof) {
|
|
@@ -1429,48 +1603,6 @@ function addComment(currentText, input) {
|
|
|
1429
1603
|
return { text: serialize(next), comment };
|
|
1430
1604
|
}
|
|
1431
1605
|
|
|
1432
|
-
// src/pluginGate.ts
|
|
1433
|
-
import { homedir as homedir5 } from "os";
|
|
1434
|
-
import { join as join7 } from "path";
|
|
1435
|
-
import { pathToFileURL } from "url";
|
|
1436
|
-
var DEFAULT_HUB_URL = "wss://inplan-collab.fly.dev";
|
|
1437
|
-
var resolveHubUrl = () => process.env.INPLAN_PLUGIN_URL || process.env.INPLAN_COLLAB_URL || DEFAULT_HUB_URL;
|
|
1438
|
-
var PLUGIN_HTTP = resolveHubUrl().replace(/^ws/, "http");
|
|
1439
|
-
var defaultCacheDir = () => join7(process.env.INPLAN_HOME || join7(homedir5(), ".inplan"), "plugin-cache");
|
|
1440
|
-
var defaultDeps = {
|
|
1441
|
-
resolve: resolvePluginOutcome,
|
|
1442
|
-
importCli: (p) => import(pathToFileURL(p).href)
|
|
1443
|
-
};
|
|
1444
|
-
async function loadPluginGateOutcome(session, options, deps = defaultDeps) {
|
|
1445
|
-
try {
|
|
1446
|
-
const { plugin, reason } = await deps.resolve({
|
|
1447
|
-
apiBase: options.apiBase ?? PLUGIN_HTTP,
|
|
1448
|
-
token: options.token,
|
|
1449
|
-
cacheDir: options.cacheDir ?? defaultCacheDir(),
|
|
1450
|
-
// Forward whenever DEFINED, not whenever truthy: an explicit `""` means "nothing can be
|
|
1451
|
-
// verified" and must reach the resolver, which then refuses without a network call. Dropping
|
|
1452
|
-
// it would silently substitute the baked-in key and verify against something the caller
|
|
1453
|
-
// deliberately disabled.
|
|
1454
|
-
...options.publicKey !== void 0 ? { publicKey: options.publicKey } : {}
|
|
1455
|
-
});
|
|
1456
|
-
if (!plugin) return { gate: null, reason };
|
|
1457
|
-
const cliName = plugin.entries.cli;
|
|
1458
|
-
const cliPath = cliName ? plugin.files[cliName] : void 0;
|
|
1459
|
-
if (!cliPath) return { gate: null, reason: "unavailable" };
|
|
1460
|
-
const cli = await deps.importCli(cliPath);
|
|
1461
|
-
return { gate: cli.gate(session), reason: null };
|
|
1462
|
-
} catch {
|
|
1463
|
-
return { gate: null, reason: "unavailable" };
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
async function loadPluginGate(session, options, deps = defaultDeps) {
|
|
1467
|
-
try {
|
|
1468
|
-
return (await loadPluginGateOutcome(session, options, deps)).gate;
|
|
1469
|
-
} catch {
|
|
1470
|
-
return null;
|
|
1471
|
-
}
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
1606
|
// src/liveSync.ts
|
|
1475
1607
|
function shouldHydrateWorkFile(o) {
|
|
1476
1608
|
if (!o.exists) return true;
|
|
@@ -1673,19 +1805,19 @@ function waitForActions(opts) {
|
|
|
1673
1805
|
}
|
|
1674
1806
|
|
|
1675
1807
|
// src/version.ts
|
|
1676
|
-
import { readFileSync as
|
|
1677
|
-
import { dirname as
|
|
1808
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
1809
|
+
import { dirname as dirname8, join as join9 } from "path";
|
|
1678
1810
|
import { fileURLToPath } from "url";
|
|
1679
1811
|
function versionFromDir(moduleDir) {
|
|
1680
1812
|
try {
|
|
1681
|
-
const pkg = JSON.parse(
|
|
1813
|
+
const pkg = JSON.parse(readFileSync9(join9(moduleDir, "..", "package.json"), "utf8"));
|
|
1682
1814
|
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
|
|
1683
1815
|
} catch {
|
|
1684
1816
|
return "0.0.0";
|
|
1685
1817
|
}
|
|
1686
1818
|
}
|
|
1687
1819
|
function versionFromModule(moduleUrl) {
|
|
1688
|
-
return versionFromDir(
|
|
1820
|
+
return versionFromDir(dirname8(fileURLToPath(moduleUrl)));
|
|
1689
1821
|
}
|
|
1690
1822
|
|
|
1691
1823
|
// src/relayActivity.ts
|
|
@@ -1706,12 +1838,12 @@ function toolActivityText(toolName, toolInput) {
|
|
|
1706
1838
|
}
|
|
1707
1839
|
|
|
1708
1840
|
// src/ensureDoc.ts
|
|
1709
|
-
import { mkdirSync as
|
|
1710
|
-
import { dirname as
|
|
1841
|
+
import { mkdirSync as mkdirSync8, writeFileSync as writeFileSync8 } from "fs";
|
|
1842
|
+
import { dirname as dirname9 } from "path";
|
|
1711
1843
|
function ensureDocFile(file) {
|
|
1712
|
-
|
|
1844
|
+
mkdirSync8(dirname9(file), { recursive: true });
|
|
1713
1845
|
try {
|
|
1714
|
-
|
|
1846
|
+
writeFileSync8(file, "", { flag: "wx" });
|
|
1715
1847
|
return true;
|
|
1716
1848
|
} catch (err) {
|
|
1717
1849
|
if (err.code === "EEXIST") return false;
|
|
@@ -1781,18 +1913,18 @@ var debounceMs = Number(process.env.INPLAN_DEBOUNCE_MS ?? 3e3);
|
|
|
1781
1913
|
var pollMs = Number(process.env.INPLAN_POLL_MS ?? 200);
|
|
1782
1914
|
function electronDistRel(platform) {
|
|
1783
1915
|
if (platform === "win32") return "electron.exe";
|
|
1784
|
-
if (platform === "darwin") return
|
|
1916
|
+
if (platform === "darwin") return join10("Electron.app", "Contents", "MacOS", "Electron");
|
|
1785
1917
|
return "electron";
|
|
1786
1918
|
}
|
|
1787
1919
|
function electronBinaryFromDisk(reqUrl) {
|
|
1788
1920
|
try {
|
|
1789
|
-
const pkgDir =
|
|
1921
|
+
const pkgDir = dirname10(createRequire(reqUrl).resolve("electron/package.json"));
|
|
1790
1922
|
const rel = electronDistRel(process.platform);
|
|
1791
|
-
const bin =
|
|
1792
|
-
if (!
|
|
1923
|
+
const bin = join10(pkgDir, "dist", rel);
|
|
1924
|
+
if (!existsSync10(bin)) return null;
|
|
1793
1925
|
try {
|
|
1794
|
-
const pathFile =
|
|
1795
|
-
if (!
|
|
1926
|
+
const pathFile = join10(pkgDir, "path.txt");
|
|
1927
|
+
if (!existsSync10(pathFile)) writeFileSync9(pathFile, rel);
|
|
1796
1928
|
} catch {
|
|
1797
1929
|
}
|
|
1798
1930
|
return bin;
|
|
@@ -1801,9 +1933,9 @@ function electronBinaryFromDisk(reqUrl) {
|
|
|
1801
1933
|
}
|
|
1802
1934
|
}
|
|
1803
1935
|
function electronCacheDir() {
|
|
1804
|
-
if (process.platform === "win32") return
|
|
1805
|
-
if (process.platform === "darwin") return
|
|
1806
|
-
return
|
|
1936
|
+
if (process.platform === "win32") return join10(process.env.LOCALAPPDATA ?? join10(homedir7(), "AppData", "Local"), "electron", "Cache");
|
|
1937
|
+
if (process.platform === "darwin") return join10(homedir7(), "Library", "Caches", "electron");
|
|
1938
|
+
return join10(process.env.XDG_CACHE_HOME ?? join10(homedir7(), ".cache"), "electron");
|
|
1807
1939
|
}
|
|
1808
1940
|
function cachedElectronZip(version, platform, arch) {
|
|
1809
1941
|
const root = electronCacheDir();
|
|
@@ -1811,9 +1943,9 @@ function cachedElectronZip(version, platform, arch) {
|
|
|
1811
1943
|
try {
|
|
1812
1944
|
let best = null;
|
|
1813
1945
|
for (const sub of readdirSync2(root)) {
|
|
1814
|
-
const f =
|
|
1815
|
-
if (!
|
|
1816
|
-
const mtime =
|
|
1946
|
+
const f = join10(root, sub, want);
|
|
1947
|
+
if (!existsSync10(f)) continue;
|
|
1948
|
+
const mtime = statSync4(f).mtimeMs;
|
|
1817
1949
|
if (!best || mtime > best.mtime) best = { file: f, mtime };
|
|
1818
1950
|
}
|
|
1819
1951
|
return best?.file ?? null;
|
|
@@ -1832,17 +1964,17 @@ function expandArchiveWindows(zipPath, destDir) {
|
|
|
1832
1964
|
function autoInstallElectron(reqUrl) {
|
|
1833
1965
|
if (process.env.INPLAN_NO_ELECTRON_DOWNLOAD === "1") return false;
|
|
1834
1966
|
try {
|
|
1835
|
-
const pkgDir =
|
|
1836
|
-
const installJs =
|
|
1837
|
-
if (!
|
|
1967
|
+
const pkgDir = dirname10(createRequire(reqUrl).resolve("electron/package.json"));
|
|
1968
|
+
const installJs = join10(pkgDir, "install.js");
|
|
1969
|
+
if (!existsSync10(installJs)) return false;
|
|
1838
1970
|
process.stderr.write("[inplan] editor runtime missing \u2014 retrying the download \u2026\n");
|
|
1839
1971
|
execFileSync2(process.execPath, [installJs], { cwd: pkgDir, stdio: "inherit", env: process.env });
|
|
1840
1972
|
if (electronBinaryFromDisk(reqUrl) !== null) return true;
|
|
1841
1973
|
if (process.platform === "win32") {
|
|
1842
|
-
const { version } = JSON.parse(
|
|
1974
|
+
const { version } = JSON.parse(readFileSync10(join10(pkgDir, "package.json"), "utf8"));
|
|
1843
1975
|
const zip = cachedElectronZip(version, "win32", process.env.npm_config_arch || process.arch);
|
|
1844
|
-
if (zip && expandArchiveWindows(zip,
|
|
1845
|
-
|
|
1976
|
+
if (zip && expandArchiveWindows(zip, join10(pkgDir, "dist"))) {
|
|
1977
|
+
writeFileSync9(join10(pkgDir, "path.txt"), "electron.exe");
|
|
1846
1978
|
}
|
|
1847
1979
|
}
|
|
1848
1980
|
return electronBinaryFromDisk(reqUrl) !== null;
|
|
@@ -1851,12 +1983,12 @@ function autoInstallElectron(reqUrl) {
|
|
|
1851
1983
|
}
|
|
1852
1984
|
}
|
|
1853
1985
|
function resolveBundledApp() {
|
|
1854
|
-
const here =
|
|
1855
|
-
const appMain =
|
|
1856
|
-
if (!
|
|
1986
|
+
const here = dirname10(fileURLToPath2(import.meta.url));
|
|
1987
|
+
const appMain = join10(here, "..", "app", "main", "index.cjs");
|
|
1988
|
+
if (!existsSync10(appMain)) return { appMain: null };
|
|
1857
1989
|
try {
|
|
1858
1990
|
const electron = createRequire(import.meta.url)("electron");
|
|
1859
|
-
if (typeof electron === "string" && electron &&
|
|
1991
|
+
if (typeof electron === "string" && electron && existsSync10(electron)) return { electron, appMain };
|
|
1860
1992
|
} catch {
|
|
1861
1993
|
}
|
|
1862
1994
|
const onDisk = electronBinaryFromDisk(import.meta.url);
|
|
@@ -1891,7 +2023,7 @@ function spawnApp(file) {
|
|
|
1891
2023
|
process.stderr.write("[inplan] no bundled editor (running from source?) \u2014 set INPLAN_APP_CMD to your editor; running headless\n");
|
|
1892
2024
|
} else {
|
|
1893
2025
|
trackCli("editor_launch_failed", telemetryOn, { reason: "electron_unavailable" });
|
|
1894
|
-
const root = resolve3(
|
|
2026
|
+
const root = resolve3(dirname10(bundled.appMain), "..", "..");
|
|
1895
2027
|
process.stderr.write(
|
|
1896
2028
|
`[inplan] the bundled editor's Electron runtime is unavailable: ${bundled.error}
|
|
1897
2029
|
\u2192 re-download the binary: npm rebuild electron --prefix "${root}"
|
|
@@ -1929,7 +2061,7 @@ function maxSeqFrom(entries) {
|
|
|
1929
2061
|
}
|
|
1930
2062
|
function fsBackend(file) {
|
|
1931
2063
|
const p = docPaths(file);
|
|
1932
|
-
|
|
2064
|
+
mkdirSync9(p.controlDir, { recursive: true });
|
|
1933
2065
|
return {
|
|
1934
2066
|
channel: new FsControlChannel(p),
|
|
1935
2067
|
store: new FsDocumentStore(p),
|
|
@@ -2065,8 +2197,45 @@ async function doLogin(args) {
|
|
|
2065
2197
|
output({ status: "logged_in", url, ...email ? { email } : {} });
|
|
2066
2198
|
return;
|
|
2067
2199
|
}
|
|
2200
|
+
if (loginOptOut(args)) {
|
|
2201
|
+
process.stderr.write("inplan login: non-interactive environment \u2014 pass --url/--anon/--refresh (or the matching INPLAN_* env vars).\n");
|
|
2202
|
+
process.exit(1);
|
|
2203
|
+
}
|
|
2204
|
+
const noBrowserHuman = !canInteractiveLogin(args) && Boolean(process.env.INPLAN_NO_BROWSER) && Boolean(process.stdin.isTTY && process.stdout.isTTY) && !process.env.CI && !isKnownAgentEnv();
|
|
2205
|
+
if (!canInteractiveLogin(args) && !noBrowserHuman || isKnownAgentEnv()) {
|
|
2206
|
+
const pending = await loadPendingLogin();
|
|
2207
|
+
if (pending) {
|
|
2208
|
+
try {
|
|
2209
|
+
process.stderr.write(`inplan: waiting for the pending browser sign-in to finish\u2026
|
|
2210
|
+
${pending.url}
|
|
2211
|
+
`);
|
|
2212
|
+
const auth = await pollLoginSession(pending, { onNudge: printLoginNudge });
|
|
2213
|
+
saveAuth(auth);
|
|
2214
|
+
await persistCloudIdentity();
|
|
2215
|
+
output({ status: "logged_in", url: auth.url, ...auth.email ? { email: auth.email } : {} });
|
|
2216
|
+
return;
|
|
2217
|
+
} catch (e) {
|
|
2218
|
+
if (!(e instanceof LoginSessionExpiredError)) {
|
|
2219
|
+
process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
|
|
2220
|
+
`);
|
|
2221
|
+
process.exit(1);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
await pendingLoginExit();
|
|
2226
|
+
process.exit(1);
|
|
2227
|
+
}
|
|
2228
|
+
clearPendingLogin();
|
|
2068
2229
|
try {
|
|
2069
|
-
const auth = await
|
|
2230
|
+
const auth = noBrowserHuman ? await rendezvousLogin({
|
|
2231
|
+
onUrl: (u) => process.stderr.write(`Open this URL in your browser to sign in:
|
|
2232
|
+
${u}
|
|
2233
|
+
`),
|
|
2234
|
+
onNudge: printLoginNudge,
|
|
2235
|
+
open: () => {
|
|
2236
|
+
}
|
|
2237
|
+
// INPLAN_NO_BROWSER: never launch one — the printed URL is the flow
|
|
2238
|
+
}) : await defaultRendezvousLogin();
|
|
2070
2239
|
saveAuth(auth);
|
|
2071
2240
|
await persistCloudIdentity();
|
|
2072
2241
|
output({ status: "logged_in", url: auth.url, ...auth.email ? { email: auth.email } : {} });
|
|
@@ -2089,39 +2258,119 @@ function canInteractiveLogin(args) {
|
|
|
2089
2258
|
if (process.env.CI || process.env.INPLAN_NO_BROWSER) return false;
|
|
2090
2259
|
return Boolean(process.stdin.isTTY && process.stdout.isTTY);
|
|
2091
2260
|
}
|
|
2092
|
-
async function ensureLoggedIn(args, login =
|
|
2261
|
+
async function ensureLoggedIn(args, login = defaultRendezvousLogin, pendingExit = pendingLoginExit, pollPending = (p) => pollLoginSession(p, { onNudge: printLoginNudge })) {
|
|
2093
2262
|
if (loadAuth()) return true;
|
|
2094
|
-
if (
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
} catch (e) {
|
|
2101
|
-
process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
|
|
2263
|
+
if (loginOptOut(args)) return false;
|
|
2264
|
+
const pending = await loadPendingLogin();
|
|
2265
|
+
if (pending) {
|
|
2266
|
+
try {
|
|
2267
|
+
process.stderr.write(`inplan: waiting for the pending browser sign-in to finish\u2026
|
|
2268
|
+
${pending.url}
|
|
2102
2269
|
`);
|
|
2103
|
-
|
|
2270
|
+
saveAuth(await pollPending(pending));
|
|
2271
|
+
await persistCloudIdentity();
|
|
2272
|
+
return true;
|
|
2273
|
+
} catch (e) {
|
|
2274
|
+
if (!(e instanceof LoginSessionExpiredError)) {
|
|
2275
|
+
process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
|
|
2276
|
+
`);
|
|
2277
|
+
return false;
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
if (canInteractiveLogin(args) && !isKnownAgentEnv()) {
|
|
2282
|
+
try {
|
|
2283
|
+
process.stderr.write("inplan: not signed in \u2014 opening your browser to sign in\u2026\n");
|
|
2284
|
+
saveAuth(await login());
|
|
2285
|
+
await persistCloudIdentity();
|
|
2286
|
+
return true;
|
|
2287
|
+
} catch (e) {
|
|
2288
|
+
process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
|
|
2289
|
+
`);
|
|
2290
|
+
return false;
|
|
2291
|
+
}
|
|
2104
2292
|
}
|
|
2293
|
+
await pendingExit();
|
|
2294
|
+
return false;
|
|
2105
2295
|
}
|
|
2106
|
-
function
|
|
2107
|
-
return
|
|
2296
|
+
function loginOptOut(args) {
|
|
2297
|
+
return hasFlag(args, "no-login") || Boolean(process.env.CI);
|
|
2298
|
+
}
|
|
2299
|
+
function defaultRendezvousLogin() {
|
|
2300
|
+
return rendezvousLogin({
|
|
2301
|
+
onUrl: (u) => process.stderr.write(`Opening your browser to sign in:
|
|
2108
2302
|
${u}
|
|
2109
2303
|
If it didn't open, paste that URL into your browser.
|
|
2110
|
-
`)
|
|
2304
|
+
`),
|
|
2305
|
+
onNudge: printLoginNudge
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2308
|
+
function printLoginNudge() {
|
|
2309
|
+
process.stderr.write("inplan: still waiting \u2014 the browser may not have opened. Open the sign-in URL above manually to continue.\n");
|
|
2310
|
+
}
|
|
2311
|
+
function isKnownAgentEnv(env = process.env) {
|
|
2312
|
+
return Boolean(env.CLAUDECODE) || Object.keys(env).some((k) => k.startsWith("CLAUDE_CODE_"));
|
|
2313
|
+
}
|
|
2314
|
+
async function pendingLoginExit() {
|
|
2315
|
+
let url;
|
|
2316
|
+
let expiresInSec;
|
|
2317
|
+
try {
|
|
2318
|
+
const pending = await createLoginSession();
|
|
2319
|
+
url = pending.url;
|
|
2320
|
+
expiresInSec = Math.max(0, Math.floor((pending.expiresAt - Date.now()) / 1e3));
|
|
2321
|
+
} catch (e) {
|
|
2322
|
+
process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
|
|
2323
|
+
`);
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
const quoted = (a) => {
|
|
2327
|
+
if (/^[A-Za-z0-9_@%+=:,.\/-]+$/.test(a)) return a;
|
|
2328
|
+
return process.platform === "win32" ? `"${a.replaceAll('"', '""')}"` : shellQuote(a);
|
|
2329
|
+
};
|
|
2330
|
+
const argsSansCredentials = [];
|
|
2331
|
+
const skipValueOf = /* @__PURE__ */ new Set(["--refresh", "--anon", "--url"]);
|
|
2332
|
+
const argv = process.argv.slice(2);
|
|
2333
|
+
for (let i = 0; i < argv.length; i++) {
|
|
2334
|
+
const a = argv[i];
|
|
2335
|
+
if (skipValueOf.has(a)) {
|
|
2336
|
+
if (i + 1 < argv.length && !argv[i + 1].startsWith("--")) i++;
|
|
2337
|
+
continue;
|
|
2338
|
+
}
|
|
2339
|
+
if ([...skipValueOf].some((f) => a.startsWith(`${f}=`))) continue;
|
|
2340
|
+
argsSansCredentials.push(a);
|
|
2341
|
+
}
|
|
2342
|
+
const entry = process.argv[1] ?? "";
|
|
2343
|
+
const invokedAsInplan = entry.split(/[\\/]/).pop()?.replace(/\.(cmd|ps1)$/i, "") === "inplan";
|
|
2344
|
+
const argv0 = invokedAsInplan ? ["inplan"] : [quoted(process.execPath), quoted(entry)];
|
|
2345
|
+
const resume = [...argv0, ...argsSansCredentials.map(quoted)].join(" ");
|
|
2346
|
+
process.stderr.write(
|
|
2347
|
+
`inplan: sign-in required.
|
|
2348
|
+
ACTION (human): open this URL in a browser and sign in:
|
|
2349
|
+
${url}
|
|
2350
|
+
NEXT STEP (coding agent): show that URL to the human, then immediately RE-RUN the
|
|
2351
|
+
command you just ran (\`${resume}\`) \u2014 it waits for the sign-in to finish, then continues.
|
|
2352
|
+
The link expires in ${Math.max(1, Math.round(expiresInSec / 60))} minutes.
|
|
2353
|
+
`
|
|
2354
|
+
);
|
|
2355
|
+
output({ status: "login_required", url, resume, expiresInSec });
|
|
2356
|
+
exitAfterFlush(EXIT_LOGIN_PENDING);
|
|
2357
|
+
await new Promise(() => {
|
|
2358
|
+
});
|
|
2111
2359
|
}
|
|
2112
2360
|
function stalenessCache() {
|
|
2113
|
-
const path =
|
|
2361
|
+
const path = join10(sidecarRoot(), ".update-check.json");
|
|
2114
2362
|
return {
|
|
2115
|
-
readCache: () =>
|
|
2363
|
+
readCache: () => existsSync10(path) ? readFileSync10(path, "utf8") : null,
|
|
2116
2364
|
writeCache: (v) => {
|
|
2117
|
-
|
|
2118
|
-
|
|
2365
|
+
mkdirSync9(dirname10(path), { recursive: true });
|
|
2366
|
+
writeFileSync9(path, v);
|
|
2119
2367
|
}
|
|
2120
2368
|
};
|
|
2121
2369
|
}
|
|
2122
2370
|
var EXIT_UPGRADE_REQUIRED = 4;
|
|
2123
2371
|
var EXIT_PLUGIN_UNAVAILABLE = 5;
|
|
2124
2372
|
var EXIT_WAIT_FAILED = 6;
|
|
2373
|
+
var EXIT_LOGIN_PENDING = 7;
|
|
2125
2374
|
function shellQuote(path) {
|
|
2126
2375
|
return "'" + path.replaceAll("'", "'\\''") + "'";
|
|
2127
2376
|
}
|
|
@@ -2188,12 +2437,12 @@ async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile,
|
|
|
2188
2437
|
}
|
|
2189
2438
|
const presence = announcePresence(docId, backend.token, model);
|
|
2190
2439
|
try {
|
|
2191
|
-
const workFile =
|
|
2440
|
+
const workFile = join10(sidecarRoot(), "remote", `${docId}.plan.md`);
|
|
2192
2441
|
const pendingPath = `${workFile}.pending`;
|
|
2193
2442
|
const hashPath = `${workFile}.synced`;
|
|
2194
|
-
|
|
2195
|
-
const readIf = (p) =>
|
|
2196
|
-
const recordSynced = (content) =>
|
|
2443
|
+
mkdirSync9(dirname10(workFile), { recursive: true });
|
|
2444
|
+
const readIf = (p) => existsSync10(p) ? readFileSync10(p, "utf8") : null;
|
|
2445
|
+
const recordSynced = (content) => writeFileSync9(hashPath, hashBody(content));
|
|
2197
2446
|
let canonical = "";
|
|
2198
2447
|
try {
|
|
2199
2448
|
canonical = await gate.readCanonical();
|
|
@@ -2204,14 +2453,14 @@ async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile,
|
|
|
2204
2453
|
exitAfterFlush(EXIT_PLUGIN_UNAVAILABLE);
|
|
2205
2454
|
return;
|
|
2206
2455
|
}
|
|
2207
|
-
const exists =
|
|
2456
|
+
const exists = existsSync10(workFile);
|
|
2208
2457
|
if (shouldHydrateWorkFile({
|
|
2209
2458
|
exists,
|
|
2210
|
-
pending:
|
|
2211
|
-
currentHash: exists ? hashBody(
|
|
2459
|
+
pending: existsSync10(pendingPath),
|
|
2460
|
+
currentHash: exists ? hashBody(readFileSync10(workFile, "utf8")) : null,
|
|
2212
2461
|
syncedHash: readIf(hashPath)
|
|
2213
2462
|
})) {
|
|
2214
|
-
|
|
2463
|
+
writeFileSync9(workFile, canonical);
|
|
2215
2464
|
recordSynced(canonical);
|
|
2216
2465
|
}
|
|
2217
2466
|
const localStore = fsBackend(workFile).store;
|
|
@@ -2227,7 +2476,7 @@ async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile,
|
|
|
2227
2476
|
};
|
|
2228
2477
|
const onSaveLocallyGate = localFile ? async () => {
|
|
2229
2478
|
const body = await gate.readCanonical();
|
|
2230
|
-
|
|
2479
|
+
writeFileSync9(localFile, body);
|
|
2231
2480
|
writeStatus(docPaths(localFile).statusPath, { location: "local", originalPath: localFile, lastSyncedHash: hashBody(body) });
|
|
2232
2481
|
const pid = spawnApp(localFile);
|
|
2233
2482
|
output({ status: "moved_local", path: localFile, reopened: pid !== null });
|
|
@@ -2261,15 +2510,15 @@ async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile,
|
|
|
2261
2510
|
if (action === "stop") return;
|
|
2262
2511
|
if (action === "keep-local") {
|
|
2263
2512
|
if (pendingRequiresReplay({ readFailed: tracked.readFailed(), writeFailed: tracked.writeFailed() })) {
|
|
2264
|
-
|
|
2513
|
+
writeFileSync9(pendingPath, "1");
|
|
2265
2514
|
}
|
|
2266
2515
|
process.stderr.write("inplan: hub was unavailable this turn \u2014 keeping local edits (will sync next turn)\n");
|
|
2267
2516
|
} else {
|
|
2268
|
-
if (
|
|
2269
|
-
recordSynced(
|
|
2517
|
+
if (existsSync10(pendingPath)) rmSync2(pendingPath);
|
|
2518
|
+
recordSynced(readFileSync10(workFile, "utf8"));
|
|
2270
2519
|
try {
|
|
2271
2520
|
const fresh = await gate.readCanonical();
|
|
2272
|
-
|
|
2521
|
+
writeFileSync9(workFile, fresh);
|
|
2273
2522
|
recordSynced(fresh);
|
|
2274
2523
|
} catch {
|
|
2275
2524
|
}
|
|
@@ -2288,7 +2537,7 @@ function doPromote(file, args) {
|
|
|
2288
2537
|
process.stderr.write("usage: inplan promote <file> --cloud-doc <docId> [--locator org/repo/path]\n");
|
|
2289
2538
|
process.exit(64);
|
|
2290
2539
|
}
|
|
2291
|
-
const body =
|
|
2540
|
+
const body = existsSync10(file) ? readFileSync10(file, "utf8") : "";
|
|
2292
2541
|
const status = { location: "cloud", cloudDocId, originalPath: file, lastSyncedHash: hashBody(body) };
|
|
2293
2542
|
const locator = getFlag(args, "locator");
|
|
2294
2543
|
if (locator) {
|
|
@@ -2333,7 +2582,7 @@ async function doDemote(file, args) {
|
|
|
2333
2582
|
return;
|
|
2334
2583
|
}
|
|
2335
2584
|
const body = choice.use === "hub" ? hubBody : await backend.store.loadDoc();
|
|
2336
|
-
|
|
2585
|
+
writeFileSync9(dest, body);
|
|
2337
2586
|
writeStatus(p.statusPath, { location: "local", originalPath: dest, lastSyncedHash: hashBody(body) });
|
|
2338
2587
|
output({ status: "demoted", location: "local", path: dest, source: choice.use });
|
|
2339
2588
|
}
|
|
@@ -2368,16 +2617,16 @@ async function doToken() {
|
|
|
2368
2617
|
function bundledSkillPath() {
|
|
2369
2618
|
try {
|
|
2370
2619
|
const override = process.env.INPLAN_SKILL_SRC;
|
|
2371
|
-
if (override) return
|
|
2372
|
-
const p =
|
|
2373
|
-
return
|
|
2620
|
+
if (override) return existsSync10(override) ? override : null;
|
|
2621
|
+
const p = join10(dirname10(fileURLToPath2(import.meta.url)), "..", "skill", "SKILL.md");
|
|
2622
|
+
return existsSync10(p) ? p : null;
|
|
2374
2623
|
} catch {
|
|
2375
2624
|
return null;
|
|
2376
2625
|
}
|
|
2377
2626
|
}
|
|
2378
2627
|
function activeDocForCwd(cwd) {
|
|
2379
2628
|
const root = sidecarRoot();
|
|
2380
|
-
if (!
|
|
2629
|
+
if (!existsSync10(root)) return null;
|
|
2381
2630
|
const real = (p) => {
|
|
2382
2631
|
try {
|
|
2383
2632
|
return realpathSync(p);
|
|
@@ -2389,13 +2638,13 @@ function activeDocForCwd(cwd) {
|
|
|
2389
2638
|
let best = null;
|
|
2390
2639
|
for (const entry of readdirSync2(root)) {
|
|
2391
2640
|
try {
|
|
2392
|
-
const dir =
|
|
2393
|
-
const orig = readStatus(
|
|
2641
|
+
const dir = join10(root, entry);
|
|
2642
|
+
const orig = readStatus(join10(dir, "status.json")).originalPath;
|
|
2394
2643
|
if (!orig) continue;
|
|
2395
2644
|
const rel = relative4(base2, real(orig));
|
|
2396
2645
|
if (rel === "" || rel.startsWith("..") || isAbsolute2(rel)) continue;
|
|
2397
|
-
const logPath =
|
|
2398
|
-
const mtime =
|
|
2646
|
+
const logPath = join10(dir, "log.jsonl");
|
|
2647
|
+
const mtime = existsSync10(logPath) ? statSync4(logPath).mtimeMs : 0;
|
|
2399
2648
|
if (!best || mtime > best.mtime) best = { file: resolve3(orig), mtime };
|
|
2400
2649
|
} catch {
|
|
2401
2650
|
}
|
|
@@ -2404,11 +2653,11 @@ function activeDocForCwd(cwd) {
|
|
|
2404
2653
|
}
|
|
2405
2654
|
function relayCursorPath(sessionKey) {
|
|
2406
2655
|
const id = createHash4("sha1").update(sessionKey).digest("hex").slice(0, 16);
|
|
2407
|
-
return
|
|
2656
|
+
return join10(sidecarRoot(), ".relay-cursors", `${id}.json`);
|
|
2408
2657
|
}
|
|
2409
2658
|
function readRelayCursor(sessionKey) {
|
|
2410
2659
|
try {
|
|
2411
|
-
const v = JSON.parse(
|
|
2660
|
+
const v = JSON.parse(readFileSync10(relayCursorPath(sessionKey), "utf8"));
|
|
2412
2661
|
return typeof v.sent === "number" && v.sent >= 0 ? v.sent : 0;
|
|
2413
2662
|
} catch {
|
|
2414
2663
|
return 0;
|
|
@@ -2417,8 +2666,8 @@ function readRelayCursor(sessionKey) {
|
|
|
2417
2666
|
function writeRelayCursor(sessionKey, sent) {
|
|
2418
2667
|
try {
|
|
2419
2668
|
const p = relayCursorPath(sessionKey);
|
|
2420
|
-
|
|
2421
|
-
|
|
2669
|
+
mkdirSync9(dirname10(p), { recursive: true });
|
|
2670
|
+
writeFileSync9(p, JSON.stringify({ sent }) + "\n");
|
|
2422
2671
|
} catch {
|
|
2423
2672
|
}
|
|
2424
2673
|
}
|
|
@@ -2426,7 +2675,7 @@ function transcriptTextBlocks(path) {
|
|
|
2426
2675
|
const out = [];
|
|
2427
2676
|
let raw;
|
|
2428
2677
|
try {
|
|
2429
|
-
raw =
|
|
2678
|
+
raw = readFileSync10(path, "utf8");
|
|
2430
2679
|
} catch {
|
|
2431
2680
|
return out;
|
|
2432
2681
|
}
|
|
@@ -2471,7 +2720,7 @@ function notesFromHook(kind, stdin, argv) {
|
|
|
2471
2720
|
const p = parse2(stdin);
|
|
2472
2721
|
const transcript = str(p.transcript_path);
|
|
2473
2722
|
const sessionKey = str(p.session_id) || transcript;
|
|
2474
|
-
const blocks = transcript &&
|
|
2723
|
+
const blocks = transcript && existsSync10(transcript) && sessionKey ? transcriptTextBlocks(transcript) : [];
|
|
2475
2724
|
if (blocks.length > 0) {
|
|
2476
2725
|
const sent = readRelayCursor(sessionKey);
|
|
2477
2726
|
for (let i = Math.max(0, sent); i < blocks.length; i++) notes.push(blocks[i]);
|
|
@@ -2495,7 +2744,7 @@ async function relayText(file, text) {
|
|
|
2495
2744
|
await backend.channel.append({ actor: "agent", type: LogEventType.AgentMessage, payload: { text } });
|
|
2496
2745
|
} else if (route.kind === "local") {
|
|
2497
2746
|
const p = docPaths(file);
|
|
2498
|
-
|
|
2747
|
+
mkdirSync9(p.controlDir, { recursive: true });
|
|
2499
2748
|
await new FsControlChannel(p).append({ actor: "agent", type: LogEventType.AgentMessage, payload: { text } });
|
|
2500
2749
|
}
|
|
2501
2750
|
} catch {
|
|
@@ -2513,7 +2762,7 @@ async function doRelay(args) {
|
|
|
2513
2762
|
let stdin = "";
|
|
2514
2763
|
if (hook !== "codex-notify") {
|
|
2515
2764
|
try {
|
|
2516
|
-
stdin =
|
|
2765
|
+
stdin = readFileSync10(0, "utf8");
|
|
2517
2766
|
} catch {
|
|
2518
2767
|
}
|
|
2519
2768
|
}
|
|
@@ -2531,22 +2780,22 @@ async function doRelay(args) {
|
|
|
2531
2780
|
output({ status: "relayed", count: clean.length });
|
|
2532
2781
|
}
|
|
2533
2782
|
function skillTargets() {
|
|
2534
|
-
const home =
|
|
2783
|
+
const home = homedir7();
|
|
2535
2784
|
return [
|
|
2536
|
-
{ name: "Claude Code", root:
|
|
2537
|
-
{ name: "Pi", root:
|
|
2538
|
-
{ name: "Codex", root:
|
|
2785
|
+
{ name: "Claude Code", root: join10(home, ".claude"), target: join10(home, ".claude", "skills", "inplan", "SKILL.md") },
|
|
2786
|
+
{ name: "Pi", root: join10(home, ".pi", "agent"), target: join10(home, ".pi", "agent", "skills", "inplan", "SKILL.md") },
|
|
2787
|
+
{ name: "Codex", root: join10(home, ".codex"), target: join10(home, ".codex", "skills", "inplan", "SKILL.md") }
|
|
2539
2788
|
];
|
|
2540
2789
|
}
|
|
2541
2790
|
var SKILL_ALLOW = ["Bash(inplan *)", "Edit(**/*.plan.md)", "Read(~/.inplan/**)", "Edit(~/.inplan/**)"];
|
|
2542
2791
|
var SKILL_ALLOW_OBSOLETE = ["Write(**/*.plan.md)", "Write(~/.inplan/**)"];
|
|
2543
2792
|
var SKILL_DIRS = ["~/.inplan/"];
|
|
2544
2793
|
function grantClaudePermissions(claudeRoot) {
|
|
2545
|
-
const settingsPath =
|
|
2794
|
+
const settingsPath = join10(claudeRoot, "settings.json");
|
|
2546
2795
|
let settings = {};
|
|
2547
2796
|
try {
|
|
2548
|
-
if (
|
|
2549
|
-
const parsed = JSON.parse(
|
|
2797
|
+
if (existsSync10(settingsPath)) {
|
|
2798
|
+
const parsed = JSON.parse(readFileSync10(settingsPath, "utf8"));
|
|
2550
2799
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
|
|
2551
2800
|
settings = parsed;
|
|
2552
2801
|
}
|
|
@@ -2579,7 +2828,7 @@ function grantClaudePermissions(claudeRoot) {
|
|
|
2579
2828
|
settings.permissions = perms;
|
|
2580
2829
|
try {
|
|
2581
2830
|
const tmp = settingsPath + ".tmp";
|
|
2582
|
-
|
|
2831
|
+
writeFileSync9(tmp, JSON.stringify(settings, null, 2) + "\n");
|
|
2583
2832
|
renameSync2(tmp, settingsPath);
|
|
2584
2833
|
} catch {
|
|
2585
2834
|
return false;
|
|
@@ -2625,8 +2874,8 @@ function mergeRelayHooks(settings, entries) {
|
|
|
2625
2874
|
}
|
|
2626
2875
|
function readJsonObject(path) {
|
|
2627
2876
|
try {
|
|
2628
|
-
if (!
|
|
2629
|
-
const parsed = JSON.parse(
|
|
2877
|
+
if (!existsSync10(path)) return {};
|
|
2878
|
+
const parsed = JSON.parse(readFileSync10(path, "utf8"));
|
|
2630
2879
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
|
|
2631
2880
|
return parsed;
|
|
2632
2881
|
} catch {
|
|
@@ -2635,9 +2884,9 @@ function readJsonObject(path) {
|
|
|
2635
2884
|
}
|
|
2636
2885
|
function writeJsonAtomic(path, value) {
|
|
2637
2886
|
try {
|
|
2638
|
-
|
|
2887
|
+
mkdirSync9(dirname10(path), { recursive: true });
|
|
2639
2888
|
const tmp = path + ".tmp";
|
|
2640
|
-
|
|
2889
|
+
writeFileSync9(tmp, JSON.stringify(value, null, 2) + "\n");
|
|
2641
2890
|
renameSync2(tmp, path);
|
|
2642
2891
|
return true;
|
|
2643
2892
|
} catch {
|
|
@@ -2645,13 +2894,13 @@ function writeJsonAtomic(path, value) {
|
|
|
2645
2894
|
}
|
|
2646
2895
|
}
|
|
2647
2896
|
function installClaudeHooks(claudeRoot) {
|
|
2648
|
-
const path =
|
|
2897
|
+
const path = join10(claudeRoot, "settings.json");
|
|
2649
2898
|
const settings = readJsonObject(path);
|
|
2650
2899
|
if (!settings || !mergeRelayHooks(settings, CLAUDE_RELAY_HOOKS)) return false;
|
|
2651
2900
|
return writeJsonAtomic(path, settings);
|
|
2652
2901
|
}
|
|
2653
2902
|
function installCodexHooks(codexRoot) {
|
|
2654
|
-
const path =
|
|
2903
|
+
const path = join10(codexRoot, "hooks.json");
|
|
2655
2904
|
const cfg = readJsonObject(path);
|
|
2656
2905
|
if (!cfg || !mergeRelayHooks(cfg, CODEX_RELAY_HOOKS)) return false;
|
|
2657
2906
|
return writeJsonAtomic(path, cfg);
|
|
@@ -2701,16 +2950,16 @@ export default function (pi) {
|
|
|
2701
2950
|
}
|
|
2702
2951
|
`;
|
|
2703
2952
|
function installPiRelayExtension(piAgentRoot) {
|
|
2704
|
-
const path =
|
|
2953
|
+
const path = join10(piAgentRoot, "extensions", "inplan-relay.ts");
|
|
2705
2954
|
try {
|
|
2706
|
-
if (
|
|
2707
|
-
const cur =
|
|
2955
|
+
if (existsSync10(path)) {
|
|
2956
|
+
const cur = readFileSync10(path, "utf8");
|
|
2708
2957
|
if (cur === PI_RELAY_EXTENSION) return false;
|
|
2709
2958
|
if (!cur.startsWith(PI_RELAY_MARKER)) return false;
|
|
2710
2959
|
}
|
|
2711
|
-
|
|
2960
|
+
mkdirSync9(dirname10(path), { recursive: true });
|
|
2712
2961
|
const tmp = path + ".tmp";
|
|
2713
|
-
|
|
2962
|
+
writeFileSync9(tmp, PI_RELAY_EXTENSION);
|
|
2714
2963
|
renameSync2(tmp, path);
|
|
2715
2964
|
return true;
|
|
2716
2965
|
} catch {
|
|
@@ -2731,28 +2980,28 @@ function doInstallSkill(args) {
|
|
|
2731
2980
|
const installed = [];
|
|
2732
2981
|
for (const a of skillTargets()) {
|
|
2733
2982
|
try {
|
|
2734
|
-
if (!
|
|
2735
|
-
if (!
|
|
2736
|
-
|
|
2983
|
+
if (!existsSync10(a.root)) continue;
|
|
2984
|
+
if (!existsSync10(a.target)) {
|
|
2985
|
+
mkdirSync9(dirname10(a.target), { recursive: true });
|
|
2737
2986
|
copyFileSync(src, a.target);
|
|
2738
2987
|
installed.push(a.name);
|
|
2739
2988
|
process.stderr.write(`inplan: installed the inplan skill into ${a.name} (${a.target}). Set INPLAN_NO_SKILL_INSTALL=1 to skip.
|
|
2740
2989
|
`);
|
|
2741
2990
|
}
|
|
2742
2991
|
if (a.name === "Claude Code" && grantClaudePermissions(a.root)) {
|
|
2743
|
-
process.stderr.write(`inplan: granted scoped auto-approval (plan files + ~/.inplan + inplan CLI) in ${
|
|
2992
|
+
process.stderr.write(`inplan: granted scoped auto-approval (plan files + ~/.inplan + inplan CLI) in ${join10(a.root, "settings.json")}.
|
|
2744
2993
|
`);
|
|
2745
2994
|
}
|
|
2746
2995
|
if (a.name === "Claude Code" && installClaudeHooks(a.root)) {
|
|
2747
|
-
process.stderr.write(`inplan: configured the agent-console relay hooks in ${
|
|
2996
|
+
process.stderr.write(`inplan: configured the agent-console relay hooks in ${join10(a.root, "settings.json")}.
|
|
2748
2997
|
`);
|
|
2749
2998
|
}
|
|
2750
2999
|
if (a.name === "Codex" && installCodexHooks(a.root)) {
|
|
2751
|
-
process.stderr.write(`inplan: configured the agent-console relay hooks in ${
|
|
3000
|
+
process.stderr.write(`inplan: configured the agent-console relay hooks in ${join10(a.root, "hooks.json")}.
|
|
2752
3001
|
`);
|
|
2753
3002
|
}
|
|
2754
3003
|
if (a.name === "Pi" && installPiRelayExtension(a.root)) {
|
|
2755
|
-
process.stderr.write(`inplan: installed the agent-console relay extension in ${
|
|
3004
|
+
process.stderr.write(`inplan: installed the agent-console relay extension in ${join10(a.root, "extensions", "inplan-relay.ts")}.
|
|
2756
3005
|
`);
|
|
2757
3006
|
}
|
|
2758
3007
|
} catch {
|
|
@@ -2786,7 +3035,7 @@ async function doUpload(file, args) {
|
|
|
2786
3035
|
process.exit(1);
|
|
2787
3036
|
}
|
|
2788
3037
|
const org = orgOf(pick);
|
|
2789
|
-
const body =
|
|
3038
|
+
const body = existsSync10(file) ? readFileSync10(file, "utf8") : "";
|
|
2790
3039
|
const prov = gitProvenance(file);
|
|
2791
3040
|
const repo = getFlag(args, "repo") ?? prov.repo;
|
|
2792
3041
|
const path = getFlag(args, "path") ?? prov.path;
|
|
@@ -2847,8 +3096,8 @@ function routeFor(file, cmd, args) {
|
|
|
2847
3096
|
const status = readStatus(p.statusPath);
|
|
2848
3097
|
if (status.location !== "cloud" || !status.cloudDocId) return { kind: "local" };
|
|
2849
3098
|
const docId = status.cloudDocId;
|
|
2850
|
-
if (cmd === "signal" || cmd === "message" || !
|
|
2851
|
-
const local =
|
|
3099
|
+
if (cmd === "signal" || cmd === "message" || !existsSync10(file)) return { kind: "cloud", docId };
|
|
3100
|
+
const local = readFileSync10(file, "utf8");
|
|
2852
3101
|
const diverged = status.lastSyncedHash !== void 0 && hashBody(local) !== status.lastSyncedHash;
|
|
2853
3102
|
if (!diverged || hasFlag(args, "use-cloud")) return { kind: "cloud", docId };
|
|
2854
3103
|
if (hasFlag(args, "continue-locally")) {
|
|
@@ -2966,7 +3215,7 @@ async function main() {
|
|
|
2966
3215
|
}
|
|
2967
3216
|
if (cmd === "signal") {
|
|
2968
3217
|
const p = docPaths(file);
|
|
2969
|
-
|
|
3218
|
+
mkdirSync9(p.controlDir, { recursive: true });
|
|
2970
3219
|
const channel = new FsControlChannel(p);
|
|
2971
3220
|
if (hasFlag(args, "done")) {
|
|
2972
3221
|
await channel.append({ actor: "agent", type: LogEventType.AgentDoneSuggested });
|
|
@@ -2984,13 +3233,13 @@ async function main() {
|
|
|
2984
3233
|
process.exit(1);
|
|
2985
3234
|
}
|
|
2986
3235
|
const p = docPaths(file);
|
|
2987
|
-
|
|
3236
|
+
mkdirSync9(p.controlDir, { recursive: true });
|
|
2988
3237
|
const channel = new FsControlChannel(p);
|
|
2989
3238
|
await channel.append({ actor: "agent", type: LogEventType.AgentMessage, payload: { text } });
|
|
2990
3239
|
output({ status: "messaged" });
|
|
2991
3240
|
return;
|
|
2992
3241
|
}
|
|
2993
|
-
if (cmd !== "open" && !
|
|
3242
|
+
if (cmd !== "open" && !existsSync10(file)) {
|
|
2994
3243
|
process.stderr.write(`inplan ${cmd}: file not found: ${file}
|
|
2995
3244
|
`);
|
|
2996
3245
|
process.exit(1);
|
|
@@ -3016,7 +3265,7 @@ async function main() {
|
|
|
3016
3265
|
}
|
|
3017
3266
|
}
|
|
3018
3267
|
try {
|
|
3019
|
-
const currentText =
|
|
3268
|
+
const currentText = readFileSync10(file, "utf8");
|
|
3020
3269
|
const { text: nextText, comment } = addComment(currentText, {
|
|
3021
3270
|
text,
|
|
3022
3271
|
author: agentAuthorFor(model),
|
|
@@ -3026,7 +3275,7 @@ async function main() {
|
|
|
3026
3275
|
...question ? { question } : {},
|
|
3027
3276
|
mayResolve: hasFlag(args, "may-resolve")
|
|
3028
3277
|
});
|
|
3029
|
-
|
|
3278
|
+
writeFileSync9(file, nextText);
|
|
3030
3279
|
output({ status: "commented", id: comment.id, date: comment.date, author: comment.author });
|
|
3031
3280
|
} catch (err) {
|
|
3032
3281
|
if (err instanceof AddCommentError) {
|
|
@@ -3041,7 +3290,7 @@ async function main() {
|
|
|
3041
3290
|
if (cmd === "open") {
|
|
3042
3291
|
ensureDocFile(file);
|
|
3043
3292
|
const p = docPaths(file);
|
|
3044
|
-
|
|
3293
|
+
mkdirSync9(p.controlDir, { recursive: true });
|
|
3045
3294
|
const st = readStatus(p.statusPath);
|
|
3046
3295
|
if (st.location !== "cloud") writeStatus(p.statusPath, { ...st, location: "local", originalPath: file });
|
|
3047
3296
|
const existing = runningEditorPid(p.logPath);
|
|
@@ -3091,6 +3340,7 @@ if (isProgramEntry()) {
|
|
|
3091
3340
|
});
|
|
3092
3341
|
}
|
|
3093
3342
|
export {
|
|
3343
|
+
EXIT_LOGIN_PENDING,
|
|
3094
3344
|
EXIT_PLUGIN_UNAVAILABLE,
|
|
3095
3345
|
EXIT_UPGRADE_REQUIRED,
|
|
3096
3346
|
EXIT_WAIT_FAILED,
|
|
@@ -3100,6 +3350,7 @@ export {
|
|
|
3100
3350
|
ensureLoggedIn,
|
|
3101
3351
|
exitAfterFlush,
|
|
3102
3352
|
explainNoGate,
|
|
3353
|
+
isKnownAgentEnv,
|
|
3103
3354
|
notesFromHook,
|
|
3104
3355
|
shellQuote,
|
|
3105
3356
|
transcriptTextBlocks
|
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -47,6 +47,22 @@ produces the headless message above, immediately, without attempting recovery. T
|
|
|
47
47
|
works headless until a binary is present, but the human can't review in the GUI — surface the
|
|
48
48
|
fix to them and proceed.
|
|
49
49
|
|
|
50
|
+
## Signing in (cloud documents)
|
|
51
|
+
|
|
52
|
+
Any cloud command (`wait --remote`, `login`, …) may exit with code 7 and a JSON line:
|
|
53
|
+
`{"status":"login_required","url":…,"resume":…,"expiresInSec":…}`. Sign-in happens in the
|
|
54
|
+
human's browser — never try to open the URL yourself, fetch it, or ask the human for
|
|
55
|
+
credentials. Do exactly two things:
|
|
56
|
+
|
|
57
|
+
1. Show the `url` to the human and ask them to open it in a browser and sign in.
|
|
58
|
+
2. Immediately re-run the `resume` command (it is the command you just ran). It waits for the
|
|
59
|
+
sign-in to finish, then continues normally — you don't need to poll or sleep first.
|
|
60
|
+
|
|
61
|
+
The wait in step 2 is bounded (~3 minutes). If the human hasn't finished by then, the command
|
|
62
|
+
exits with a timeout message while the session is still valid — that is not a hard error: just
|
|
63
|
+
re-run the same command and it resumes the same sign-in. If the link itself expires
|
|
64
|
+
(`expiresInSec`, ~10 minutes), the re-run prints a fresh URL — repeat from 1.
|
|
65
|
+
|
|
50
66
|
## File convention
|
|
51
67
|
|
|
52
68
|
Save plans as `<name>.plan.md`. The `inplan` CLI keeps its own working files under
|