inplan 0.1.28 → 0.1.29
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/app/main/index.cjs
CHANGED
|
@@ -218,7 +218,9 @@ var FsControlChannel = class {
|
|
|
218
218
|
if (!fs.existsSync(this.paths.waitLockPath)) return Promise.resolve(false);
|
|
219
219
|
return Promise.resolve(fs.readFileSync(this.paths.waitLockPath, "utf8").trim() !== token);
|
|
220
220
|
}
|
|
221
|
-
|
|
221
|
+
// `sinceMs` is ignored: liveness here is "is the editor PROCESS alive", which flips to false the
|
|
222
|
+
// instant the window closes — there's no lingering-heartbeat TTL window to disambiguate.
|
|
223
|
+
presence(_sinceMs) {
|
|
222
224
|
const log = readLog(this.paths.logPath);
|
|
223
225
|
for (let i = log.length - 1; i >= 0; i--) {
|
|
224
226
|
if (log[i].type === LogEventType.EditorPid) {
|
|
@@ -7092,6 +7092,7 @@ var MemoryControlChannel = class {
|
|
|
7092
7092
|
cursor = 0;
|
|
7093
7093
|
lockToken = null;
|
|
7094
7094
|
present = false;
|
|
7095
|
+
presentAt = 0;
|
|
7095
7096
|
listeners = /* @__PURE__ */ new Set();
|
|
7096
7097
|
append(event) {
|
|
7097
7098
|
const seq = this.log.length ? this.log[this.log.length - 1].seq + 1 : 1;
|
|
@@ -7129,12 +7130,14 @@ var MemoryControlChannel = class {
|
|
|
7129
7130
|
isSuperseded(token) {
|
|
7130
7131
|
return Promise.resolve(this.lockToken !== null && this.lockToken !== token);
|
|
7131
7132
|
}
|
|
7132
|
-
presence() {
|
|
7133
|
-
return Promise.resolve(this.present);
|
|
7133
|
+
presence(sinceMs) {
|
|
7134
|
+
return Promise.resolve(this.present && (sinceMs === void 0 || this.presentAt > sinceMs));
|
|
7134
7135
|
}
|
|
7135
|
-
/** Test hook: simulate the editor being present/absent.
|
|
7136
|
-
|
|
7136
|
+
/** Test hook: simulate the editor being present/absent. `at` (epoch ms, default now) stamps when
|
|
7137
|
+
* the heartbeat was written, so a `presence(sinceMs)` freshness check can be exercised. */
|
|
7138
|
+
setPresent(present, at = Date.now()) {
|
|
7137
7139
|
this.present = present;
|
|
7140
|
+
if (present) this.presentAt = at;
|
|
7138
7141
|
}
|
|
7139
7142
|
};
|
|
7140
7143
|
var MemoryDocumentStore = class {
|
package/app/renderer/index.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
content="default-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self' inplan-plugin:; img-src 'self' file: https:; connect-src 'self' inplan-plugin: ws://127.0.0.1:* ws://localhost:*; frame-src https://inplan.ai http://127.0.0.1:* http://localhost:*"
|
|
22
22
|
/>
|
|
23
23
|
<title>inplan</title>
|
|
24
|
-
<script type="module" crossorigin src="./assets/index-
|
|
24
|
+
<script type="module" crossorigin src="./assets/index-B2UMwEBL.js"></script>
|
|
25
25
|
<link rel="stylesheet" crossorigin href="./assets/index-BsT_GmrR.css">
|
|
26
26
|
</head>
|
|
27
27
|
<body>
|
package/bin/cli.js
CHANGED
|
@@ -9,7 +9,7 @@ import { homedir as homedir7 } from "os";
|
|
|
9
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
|
-
// ../core/dist/chunk-
|
|
12
|
+
// ../core/dist/chunk-BS76FGIJ.js
|
|
13
13
|
function isReply(c) {
|
|
14
14
|
return c.parentId !== void 0;
|
|
15
15
|
}
|
|
@@ -372,7 +372,9 @@ var FsControlChannel = class {
|
|
|
372
372
|
if (!existsSync2(this.paths.waitLockPath)) return Promise.resolve(false);
|
|
373
373
|
return Promise.resolve(readFileSync2(this.paths.waitLockPath, "utf8").trim() !== token);
|
|
374
374
|
}
|
|
375
|
-
|
|
375
|
+
// `sinceMs` is ignored: liveness here is "is the editor PROCESS alive", which flips to false the
|
|
376
|
+
// instant the window closes — there's no lingering-heartbeat TTL window to disambiguate.
|
|
377
|
+
presence(_sinceMs) {
|
|
376
378
|
const log = readLog(this.paths.logPath);
|
|
377
379
|
for (let i = log.length - 1; i >= 0; i--) {
|
|
378
380
|
if (log[i].type === LogEventType.EditorPid) {
|
|
@@ -745,12 +747,13 @@ var SupabaseControlChannel = class {
|
|
|
745
747
|
const current = data?.token;
|
|
746
748
|
return current != null && current !== token;
|
|
747
749
|
}
|
|
748
|
-
async presence() {
|
|
750
|
+
async presence(sinceMs) {
|
|
749
751
|
const { data, error } = await this.db.from("editor_presence").select("last_seen").eq("doc_id", this.docId).maybeSingle();
|
|
750
752
|
if (error) throw new Error(`presence failed: ${error.message}`);
|
|
751
753
|
const lastSeen = data?.last_seen;
|
|
752
754
|
if (!lastSeen) return false;
|
|
753
|
-
|
|
755
|
+
const lastSeenMs = new Date(lastSeen).getTime();
|
|
756
|
+
return sinceMs !== void 0 ? lastSeenMs > sinceMs : Date.now() - lastSeenMs < PRESENCE_TTL_MS;
|
|
754
757
|
}
|
|
755
758
|
};
|
|
756
759
|
function rowToEntry(r) {
|
|
@@ -1038,7 +1041,7 @@ function liveRemoteBackend(docId, consumerId = "cli-agent") {
|
|
|
1038
1041
|
setCursor: async (s) => (await need()).channel.setCursor(s),
|
|
1039
1042
|
claimLock: async (t) => (await need()).channel.claimLock(t),
|
|
1040
1043
|
isSuperseded: async (t) => (await need()).channel.isSuperseded(t),
|
|
1041
|
-
presence: async () => (await need()).channel.presence()
|
|
1044
|
+
presence: async (sinceMs) => (await need()).channel.presence(sinceMs)
|
|
1042
1045
|
};
|
|
1043
1046
|
const store = {
|
|
1044
1047
|
loadDoc: async () => (await need()).store.loadDoc(),
|
|
@@ -1711,9 +1714,58 @@ var defaultActionable = (e) => e.actor === "user";
|
|
|
1711
1714
|
function wakePredicate(wake) {
|
|
1712
1715
|
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;
|
|
1713
1716
|
}
|
|
1717
|
+
var REOPEN_GRACE_MS = 3 * 6e4;
|
|
1718
|
+
async function awaitReopen(channel, cursor, opts = {}) {
|
|
1719
|
+
const graceMs = opts.graceMs ?? REOPEN_GRACE_MS;
|
|
1720
|
+
const pollMs = opts.pollMs ?? 2e3;
|
|
1721
|
+
const now = opts.now ?? Date.now;
|
|
1722
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
1723
|
+
const deadline = now() + graceMs;
|
|
1724
|
+
const graceStart = now();
|
|
1725
|
+
const budget = () => Math.max(1, Math.min(opts.probeTimeoutMs ?? 1e4, deadline - now()));
|
|
1726
|
+
const supersede = inFlightGate();
|
|
1727
|
+
const reads = inFlightGate();
|
|
1728
|
+
const presences = inFlightGate();
|
|
1729
|
+
let probeCursor = cursor;
|
|
1730
|
+
const seen = [];
|
|
1731
|
+
while (now() < deadline) {
|
|
1732
|
+
if (opts.token && !supersede.busy()) {
|
|
1733
|
+
try {
|
|
1734
|
+
if (await supersede.run(() => channel.isSuperseded(opts.token), budget())) return { kind: "superseded" };
|
|
1735
|
+
} catch {
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
if (!reads.busy()) {
|
|
1739
|
+
try {
|
|
1740
|
+
const { entries, cursor: readCursor } = await reads.run(() => channel.readSince(probeCursor), budget());
|
|
1741
|
+
probeCursor = readCursor;
|
|
1742
|
+
seen.push(...entries);
|
|
1743
|
+
const closed = entries.find((e) => {
|
|
1744
|
+
if (e.type !== LogEventType.SessionClosed) return false;
|
|
1745
|
+
const reason = e.payload?.reason;
|
|
1746
|
+
return reason !== void 0 && reason !== "window_closed";
|
|
1747
|
+
});
|
|
1748
|
+
if (closed) {
|
|
1749
|
+
const reason = closed.payload?.reason ?? "completed";
|
|
1750
|
+
return { kind: "completed", cursor: readCursor, entries: seen, reason };
|
|
1751
|
+
}
|
|
1752
|
+
if (entries.some((e) => e.actor === "user" && e.type !== LogEventType.SessionClosed)) return { kind: "reopened" };
|
|
1753
|
+
} catch {
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
if (!presences.busy()) {
|
|
1757
|
+
try {
|
|
1758
|
+
if (await presences.run(() => channel.presence(graceStart), budget())) return { kind: "reopened" };
|
|
1759
|
+
} catch {
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
await sleep(Math.max(1, Math.min(pollMs, deadline - now())));
|
|
1763
|
+
}
|
|
1764
|
+
return { kind: "expired" };
|
|
1765
|
+
}
|
|
1714
1766
|
function waitForActions(opts) {
|
|
1715
|
-
const
|
|
1716
|
-
const
|
|
1767
|
+
const debounceMs = opts.debounceMs ?? 3e3;
|
|
1768
|
+
const pollMs = opts.pollMs ?? 200;
|
|
1717
1769
|
const isActionable = opts.isActionable ?? defaultActionable;
|
|
1718
1770
|
const watchEditor = opts.watchEditor ?? true;
|
|
1719
1771
|
const errorGraceMs = opts.errorGraceMs ?? DEFAULT_ERROR_GRACE_MS;
|
|
@@ -1782,7 +1834,7 @@ function waitForActions(opts) {
|
|
|
1782
1834
|
if (entries.some(isActionable)) {
|
|
1783
1835
|
if (entries.length !== lastCount) {
|
|
1784
1836
|
lastCount = entries.length;
|
|
1785
|
-
deadline = Date.now() +
|
|
1837
|
+
deadline = Date.now() + debounceMs;
|
|
1786
1838
|
} else if (deadline !== null && Date.now() >= deadline) {
|
|
1787
1839
|
finish({ entries, cursor });
|
|
1788
1840
|
}
|
|
@@ -1798,7 +1850,7 @@ function waitForActions(opts) {
|
|
|
1798
1850
|
busy = false;
|
|
1799
1851
|
}
|
|
1800
1852
|
};
|
|
1801
|
-
const timer = setInterval(() => void tick(),
|
|
1853
|
+
const timer = setInterval(() => void tick(), pollMs);
|
|
1802
1854
|
opts.signal?.addEventListener("abort", onAbort);
|
|
1803
1855
|
void tick();
|
|
1804
1856
|
});
|
|
@@ -1909,8 +1961,6 @@ function getFlag(args, name) {
|
|
|
1909
1961
|
function hasFlag(args, name) {
|
|
1910
1962
|
return args.includes(`--${name}`);
|
|
1911
1963
|
}
|
|
1912
|
-
var debounceMs = Number(process.env.INPLAN_DEBOUNCE_MS ?? 3e3);
|
|
1913
|
-
var pollMs = Number(process.env.INPLAN_POLL_MS ?? 200);
|
|
1914
1964
|
function electronDistRel(platform) {
|
|
1915
1965
|
if (platform === "win32") return "electron.exe";
|
|
1916
1966
|
if (platform === "darwin") return join10("Electron.app", "Contents", "MacOS", "Electron");
|
|
@@ -2126,65 +2176,99 @@ async function waitCycle(backend, explicitCursor, confirmed, model, gate = null)
|
|
|
2126
2176
|
process.exit(0);
|
|
2127
2177
|
});
|
|
2128
2178
|
}
|
|
2129
|
-
const
|
|
2130
|
-
const
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2179
|
+
const debounceMs = Number(process.env.INPLAN_DEBOUNCE_MS ?? 3e3);
|
|
2180
|
+
const pollMs = Number(process.env.INPLAN_POLL_MS ?? 200);
|
|
2181
|
+
let waitCursor = cursor;
|
|
2182
|
+
let historyForMode = history;
|
|
2183
|
+
for (; ; ) {
|
|
2184
|
+
const mode = modeFrom(historyForMode);
|
|
2185
|
+
const isActionable = wakePredicate(mode.wake);
|
|
2186
|
+
const result = await waitForActions({ channel, cursor: waitCursor, debounceMs, pollMs, isActionable, token: lockToken });
|
|
2187
|
+
if (result.failed) {
|
|
2188
|
+
backend.logExit("poll_failed");
|
|
2189
|
+
process.stderr.write(`inplan: lost contact with the document (${result.failed.message}).
|
|
2135
2190
|
If your session expired, run \`inplan login\` and re-attach.
|
|
2136
2191
|
`);
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2192
|
+
output({ status: "wait_failed", message: result.failed.message });
|
|
2193
|
+
exitAfterFlush(EXIT_WAIT_FAILED);
|
|
2194
|
+
return "exiting";
|
|
2195
|
+
}
|
|
2196
|
+
if (result.superseded) {
|
|
2197
|
+
backend.logExit("superseded");
|
|
2198
|
+
output({ status: "superseded" });
|
|
2199
|
+
return "ok";
|
|
2200
|
+
}
|
|
2201
|
+
if (backend.onSaveLocally && result.entries.some((e) => e.type === LogEventType.SaveLocallyRequested)) {
|
|
2202
|
+
backend.logExit("save_locally");
|
|
2203
|
+
await backend.onSaveLocally();
|
|
2204
|
+
return "ok";
|
|
2205
|
+
}
|
|
2206
|
+
await channel.setCursor(result.cursor);
|
|
2207
|
+
const navEntry = result.entries.find((e) => e.type === LogEventType.NavigatedTo);
|
|
2208
|
+
if (navEntry) {
|
|
2209
|
+
const path = navEntry.payload?.path;
|
|
2210
|
+
backend.logExit("navigated");
|
|
2211
|
+
output({ status: "navigated", ...path ? { path } : {}, cursor: result.cursor, closed: false });
|
|
2212
|
+
return "ok";
|
|
2213
|
+
}
|
|
2214
|
+
const closeEntry = [...result.entries].reverse().find((e) => e.type === LogEventType.SessionClosed);
|
|
2215
|
+
if (closeEntry && (closeEntry.payload?.reason ?? "completed") === "window_closed") {
|
|
2216
|
+
if (result.entries.some((e) => e.seq > closeEntry.seq && e.actor === "user" && e.type !== LogEventType.SessionClosed)) {
|
|
2217
|
+
process.stderr.write("inplan: the editor closed and is already active again \u2014 resuming the wait.\n");
|
|
2218
|
+
waitCursor = closeEntry.seq;
|
|
2219
|
+
historyForMode = await backend.history();
|
|
2220
|
+
continue;
|
|
2221
|
+
}
|
|
2222
|
+
process.stderr.write("inplan: the editor closed \u2014 often just a page reload. Watching for it to come back\u2026\n");
|
|
2223
|
+
const reopen = await awaitReopen(channel, result.cursor, { token: lockToken });
|
|
2224
|
+
if (reopen.kind === "superseded") {
|
|
2225
|
+
backend.logExit("superseded");
|
|
2226
|
+
output({ status: "superseded" });
|
|
2227
|
+
return "ok";
|
|
2228
|
+
}
|
|
2229
|
+
if (reopen.kind === "completed") {
|
|
2230
|
+
await channel.setCursor(reopen.cursor);
|
|
2231
|
+
backend.logExit(reopen.reason);
|
|
2232
|
+
output({ status: "closed", reason: reopen.reason, cursor: reopen.cursor, closed: true, entries: [...result.entries, ...reopen.entries] });
|
|
2233
|
+
return "ok";
|
|
2234
|
+
}
|
|
2235
|
+
if (reopen.kind === "reopened") {
|
|
2236
|
+
process.stderr.write("inplan: the editor is back \u2014 resuming the wait.\n");
|
|
2237
|
+
waitCursor = result.cursor;
|
|
2238
|
+
historyForMode = await backend.history();
|
|
2239
|
+
continue;
|
|
2240
|
+
}
|
|
2241
|
+
process.stderr.write("inplan: the editor did not come back \u2014 treating the session as closed.\n");
|
|
2242
|
+
}
|
|
2243
|
+
let status;
|
|
2244
|
+
let reason;
|
|
2245
|
+
if (closeEntry) {
|
|
2246
|
+
status = "closed";
|
|
2247
|
+
reason = closeEntry.payload?.reason ?? "completed";
|
|
2248
|
+
} else if (result.editorGone) {
|
|
2249
|
+
status = "closed";
|
|
2250
|
+
reason = "crashed_or_killed";
|
|
2251
|
+
} else {
|
|
2252
|
+
status = mode.locksEditor ? "your_turn" : "activity";
|
|
2253
|
+
}
|
|
2254
|
+
backend.logExit(`status:${status}${reason ? `/${reason}` : ""}`);
|
|
2255
|
+
output({
|
|
2256
|
+
status,
|
|
2257
|
+
mode: mode.cadence,
|
|
2258
|
+
humanLocked: status === "your_turn",
|
|
2259
|
+
// Materialized current settings (global file + this session's settings_changed),
|
|
2260
|
+
// so the agent always has them without scanning the log history.
|
|
2261
|
+
settings: settingsFromEntries(historyForMode),
|
|
2262
|
+
// The canonical name the agent should author comments under (model-qualified
|
|
2263
|
+
// when --model was passed), so presence + authorship stay consistent.
|
|
2264
|
+
agentAuthor: agentAuthorFor(model),
|
|
2265
|
+
...reason ? { reason } : {},
|
|
2266
|
+
cursor: result.cursor,
|
|
2267
|
+
closed: status === "closed",
|
|
2268
|
+
entries: result.entries
|
|
2269
|
+
});
|
|
2157
2270
|
return "ok";
|
|
2158
2271
|
}
|
|
2159
|
-
const closeEntry = result.entries.find((e) => e.type === LogEventType.SessionClosed);
|
|
2160
|
-
let status;
|
|
2161
|
-
let reason;
|
|
2162
|
-
if (closeEntry) {
|
|
2163
|
-
status = "closed";
|
|
2164
|
-
reason = closeEntry.payload?.reason ?? "completed";
|
|
2165
|
-
} else if (result.editorGone) {
|
|
2166
|
-
status = "closed";
|
|
2167
|
-
reason = "crashed_or_killed";
|
|
2168
|
-
} else {
|
|
2169
|
-
status = mode.locksEditor ? "your_turn" : "activity";
|
|
2170
|
-
}
|
|
2171
|
-
backend.logExit(`status:${status}${reason ? `/${reason}` : ""}`);
|
|
2172
|
-
output({
|
|
2173
|
-
status,
|
|
2174
|
-
mode: mode.cadence,
|
|
2175
|
-
humanLocked: status === "your_turn",
|
|
2176
|
-
// Materialized current settings (global file + this session's settings_changed),
|
|
2177
|
-
// so the agent always has them without scanning the log history.
|
|
2178
|
-
settings: settingsFromEntries(history),
|
|
2179
|
-
// The canonical name the agent should author comments under (model-qualified
|
|
2180
|
-
// when --model was passed), so presence + authorship stay consistent.
|
|
2181
|
-
agentAuthor: agentAuthorFor(model),
|
|
2182
|
-
...reason ? { reason } : {},
|
|
2183
|
-
cursor: result.cursor,
|
|
2184
|
-
closed: status === "closed",
|
|
2185
|
-
entries: result.entries
|
|
2186
|
-
});
|
|
2187
|
-
return "ok";
|
|
2188
2272
|
}
|
|
2189
2273
|
async function doLogin(args) {
|
|
2190
2274
|
const url = getFlag(args, "url") ?? process.env.INPLAN_SUPABASE_URL;
|
|
@@ -2308,8 +2392,17 @@ If it didn't open, paste that URL into your browser.
|
|
|
2308
2392
|
function printLoginNudge() {
|
|
2309
2393
|
process.stderr.write("inplan: still waiting \u2014 the browser may not have opened. Open the sign-in URL above manually to continue.\n");
|
|
2310
2394
|
}
|
|
2395
|
+
var AGENT_ENV_VARS = ["CLAUDECODE", "CODEX_SANDBOX", "PI_CODING_AGENT", "INPLAN_AGENT"];
|
|
2396
|
+
var AGENT_ENV_PREFIXES = ["CLAUDE_CODE_"];
|
|
2311
2397
|
function isKnownAgentEnv(env = process.env) {
|
|
2312
|
-
return Boolean(env
|
|
2398
|
+
return AGENT_ENV_VARS.some((k) => Boolean(env[k])) || Object.keys(env).some((k) => AGENT_ENV_PREFIXES.some((p) => k.startsWith(p)));
|
|
2399
|
+
}
|
|
2400
|
+
function scrubAgentEnv(env) {
|
|
2401
|
+
const out = { ...env };
|
|
2402
|
+
for (const k of Object.keys(out)) {
|
|
2403
|
+
if (AGENT_ENV_VARS.includes(k) || AGENT_ENV_PREFIXES.some((p) => k.startsWith(p))) delete out[k];
|
|
2404
|
+
}
|
|
2405
|
+
return out;
|
|
2313
2406
|
}
|
|
2314
2407
|
async function pendingLoginExit() {
|
|
2315
2408
|
let url;
|
|
@@ -3340,6 +3433,8 @@ if (isProgramEntry()) {
|
|
|
3340
3433
|
});
|
|
3341
3434
|
}
|
|
3342
3435
|
export {
|
|
3436
|
+
AGENT_ENV_PREFIXES,
|
|
3437
|
+
AGENT_ENV_VARS,
|
|
3343
3438
|
EXIT_LOGIN_PENDING,
|
|
3344
3439
|
EXIT_PLUGIN_UNAVAILABLE,
|
|
3345
3440
|
EXIT_UPGRADE_REQUIRED,
|
|
@@ -3352,6 +3447,8 @@ export {
|
|
|
3352
3447
|
explainNoGate,
|
|
3353
3448
|
isKnownAgentEnv,
|
|
3354
3449
|
notesFromHook,
|
|
3450
|
+
scrubAgentEnv,
|
|
3355
3451
|
shellQuote,
|
|
3356
|
-
transcriptTextBlocks
|
|
3452
|
+
transcriptTextBlocks,
|
|
3453
|
+
waitCycle
|
|
3357
3454
|
};
|