inplan 0.1.24 → 0.1.26

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.
@@ -43608,7 +43608,7 @@ var EN = {
43608
43608
  "agent.atLimit": "Usage limit reached — turns are paused until your plan resets or you upgrade",
43609
43609
  "agent.connection": "Agent connection",
43610
43610
  "agent.localCmdHint": "Paste this to your coding agent:",
43611
- "agent.localCmdBody": "Collaborate with me on my inplan plan. Check the CLI with `inplan --version` (if missing, install it: `npm i -g inplan`), sign in with `inplan login`, then run `{cmd}` and work with me through the comments.",
43611
+ "agent.localCmdBody": "Collaborate with me on my inplan plan. Check the CLI with `inplan --version` (if missing, install it: `npm i -g inplan`), sign in with `inplan login` if you haven't yet, then run `{cmd}` and work with me through the comments.",
43612
43612
  "agent.copy": "Copy",
43613
43613
  "agent.copied": "Copied",
43614
43614
  // comment rail
@@ -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-K0WqENF0.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-CJjtgrEi.js"></script>
25
25
  <link rel="stylesheet" crossorigin href="./assets/index-i6zzDOQL.css">
26
26
  </head>
27
27
  <body>
package/bin/cli.js CHANGED
@@ -4,7 +4,7 @@
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 existsSync9, mkdirSync as mkdirSync8, readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync, renameSync, statSync as statSync2, writeFileSync as writeFileSync8 } from "fs";
7
+ import { appendFileSync as appendFileSync2, copyFileSync, existsSync as existsSync9, mkdirSync as mkdirSync8, readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statSync as statSync3, writeFileSync as writeFileSync8 } from "fs";
8
8
  import { homedir as homedir6 } from "os";
9
9
  import { basename as basename3, dirname as dirname9, isAbsolute as isAbsolute2, join as join9, relative as relative4, resolve as resolve3 } from "path";
10
10
  import { fileURLToPath as fileURLToPath2, pathToFileURL as pathToFileURL2 } from "url";
@@ -669,7 +669,7 @@ function gitIdentity(dir, run = defaultRun) {
669
669
  }
670
670
 
671
671
  // src/cliAuth.ts
672
- import { chmodSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync4, rmSync, writeFileSync as writeFileSync3 } from "fs";
672
+ import { chmodSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync, rmSync, statSync as statSync2, utimesSync, writeFileSync as writeFileSync3 } from "fs";
673
673
  import { homedir as homedir3 } from "os";
674
674
  import { dirname as dirname5, join as join4 } from "path";
675
675
  import { createClient as createClient2 } from "@supabase/supabase-js";
@@ -824,7 +824,14 @@ function loadAuth() {
824
824
  try {
825
825
  const raw = JSON.parse(readFileSync4(path, "utf8"));
826
826
  if (typeof raw.url === "string" && typeof raw.anonKey === "string" && typeof raw.refreshToken === "string") {
827
- return { url: raw.url, anonKey: raw.anonKey, refreshToken: raw.refreshToken, ...raw.email ? { email: raw.email } : {} };
827
+ return {
828
+ url: raw.url,
829
+ anonKey: raw.anonKey,
830
+ refreshToken: raw.refreshToken,
831
+ ...raw.email ? { email: raw.email } : {},
832
+ ...typeof raw.accessToken === "string" ? { accessToken: raw.accessToken } : {},
833
+ ...typeof raw.expiresAt === "number" ? { expiresAt: raw.expiresAt } : {}
834
+ };
828
835
  }
829
836
  return null;
830
837
  } catch {
@@ -834,32 +841,120 @@ function loadAuth() {
834
841
  function saveAuth(auth) {
835
842
  const path = authPath();
836
843
  mkdirSync3(dirname5(path), { recursive: true });
837
- writeFileSync3(path, `${JSON.stringify(auth, null, 2)}
844
+ const tmp = `${path}.${process.pid}.tmp`;
845
+ writeFileSync3(tmp, `${JSON.stringify(auth, null, 2)}
838
846
  `, { mode: 384 });
839
847
  try {
840
- chmodSync(path, 384);
848
+ chmodSync(tmp, 384);
841
849
  } catch {
842
850
  }
851
+ renameSync(tmp, path);
843
852
  }
844
853
  function clearAuth() {
845
854
  const path = authPath();
846
855
  if (existsSync5(path)) rmSync(path, { force: true });
847
856
  }
848
- async function authedSession() {
849
- const auth = loadAuth();
850
- if (!auth) return null;
851
- const db = createClient2(auth.url, auth.anonKey, {
852
- auth: { persistSession: false, autoRefreshToken: true, detectSessionInUrl: false },
857
+ var LOCK_WAIT_MS = 1e4;
858
+ var LOCK_STALE_MS = 6e4;
859
+ function lockDir() {
860
+ return join4(process.env.INPLAN_HOME || join4(homedir3(), ".inplan"), "auth.lock");
861
+ }
862
+ function lockOwnerPath() {
863
+ return join4(lockDir(), "owner");
864
+ }
865
+ async function withAuthLock(fn, opts = {}) {
866
+ const lock = lockDir();
867
+ mkdirSync3(process.env.INPLAN_HOME || join4(homedir3(), ".inplan"), { recursive: true });
868
+ const token = `${process.pid}-${Date.now()}-${Math.floor(Math.random() * 1e9)}`;
869
+ const waitMs = opts.waitMs ?? LOCK_WAIT_MS;
870
+ const staleMs = opts.staleMs ?? LOCK_STALE_MS;
871
+ const deadline = Date.now() + waitMs;
872
+ let held = false;
873
+ while (Date.now() < deadline) {
874
+ try {
875
+ mkdirSync3(lock);
876
+ writeFileSync3(lockOwnerPath(), token);
877
+ held = true;
878
+ break;
879
+ } catch (e) {
880
+ if (e.code !== "EEXIST") throw e;
881
+ try {
882
+ if (Date.now() - statSync2(lock).mtimeMs > staleMs) {
883
+ const aside = `${lock}.stale-${token}`;
884
+ renameSync(lock, aside);
885
+ rmSync(aside, { recursive: true, force: true });
886
+ continue;
887
+ }
888
+ } catch {
889
+ continue;
890
+ }
891
+ await new Promise((r) => setTimeout(r, 40 + Math.floor(Math.random() * 40)));
892
+ }
893
+ }
894
+ if (!held) return { acquired: false };
895
+ const stillMine = () => {
896
+ try {
897
+ return readFileSync4(lockOwnerPath(), "utf8") === token;
898
+ } catch {
899
+ return false;
900
+ }
901
+ };
902
+ const beat = setInterval(() => {
903
+ try {
904
+ if (stillMine()) utimesSync(lock, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
905
+ } catch {
906
+ }
907
+ }, Math.max(1, Math.floor(staleMs / 3)));
908
+ if (typeof beat.unref === "function") beat.unref();
909
+ try {
910
+ return { acquired: true, value: await fn({ stillMine }) };
911
+ } finally {
912
+ clearInterval(beat);
913
+ try {
914
+ if (readFileSync4(lockOwnerPath(), "utf8") === token) rmSync(lock, { recursive: true, force: true });
915
+ } catch {
916
+ }
917
+ }
918
+ }
919
+ var ACCESS_SKEW_S = 120;
920
+ function newClient(auth) {
921
+ return createClient2(auth.url, auth.anonKey, {
922
+ auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
853
923
  realtime: realtimeTransport
854
924
  });
855
- const { data, error } = await db.auth.refreshSession({ refresh_token: auth.refreshToken });
856
- if (error || !data.session) return null;
857
- const rotated = data.session.refresh_token || auth.refreshToken;
858
- const email = data.session.user?.email ?? auth.email;
859
- if (rotated !== auth.refreshToken || email !== auth.email) {
860
- saveAuth({ ...auth, refreshToken: rotated, ...email ? { email } : {} });
861
- }
862
- return { db, session: data.session };
925
+ }
926
+ async function reuseCached(auth, skewS = ACCESS_SKEW_S) {
927
+ if (!auth.accessToken || !auth.expiresAt) return null;
928
+ if (auth.expiresAt - Math.floor(Date.now() / 1e3) <= skewS) return null;
929
+ const db = newClient(auth);
930
+ const { data, error } = await db.auth.setSession({ access_token: auth.accessToken, refresh_token: auth.refreshToken });
931
+ return error || !data.session ? null : { db, session: data.session };
932
+ }
933
+ async function authedSession() {
934
+ const cached = loadAuth();
935
+ if (!cached) return null;
936
+ const reused = await reuseCached(cached);
937
+ if (reused) return reused;
938
+ const locked = await withAuthLock(async ({ stillMine }) => {
939
+ const auth = loadAuth();
940
+ if (!auth) return null;
941
+ const fresh = await reuseCached(auth);
942
+ if (fresh) return fresh;
943
+ if (!stillMine()) return null;
944
+ const db = newClient(auth);
945
+ const { data, error } = await db.auth.refreshSession({ refresh_token: auth.refreshToken });
946
+ if (error || !data.session) return null;
947
+ saveAuth({
948
+ ...auth,
949
+ refreshToken: data.session.refresh_token || auth.refreshToken,
950
+ accessToken: data.session.access_token,
951
+ ...data.session.expires_at ? { expiresAt: data.session.expires_at } : {},
952
+ ...data.session.user?.email ? { email: data.session.user.email } : {}
953
+ });
954
+ return { db, session: data.session };
955
+ });
956
+ if (locked.acquired) return locked.value;
957
+ return reuseCached(loadAuth() ?? cached, 0);
863
958
  }
864
959
  async function currentUser() {
865
960
  const s = await authedSession();
@@ -882,6 +977,59 @@ async function remoteBackend(docId, consumerId = "cli-agent") {
882
977
  token: s.session.access_token
883
978
  };
884
979
  }
980
+ function liveRemoteBackend(docId, consumerId = "cli-agent") {
981
+ let inner = null;
982
+ let expiresAt = 0;
983
+ let inflight = null;
984
+ const fresh = async () => {
985
+ const now = Math.floor(Date.now() / 1e3);
986
+ if (inner && expiresAt - now > ACCESS_SKEW_S) return inner;
987
+ inflight ??= remoteBackend(docId, consumerId).then((b) => {
988
+ if (b) {
989
+ inner = b;
990
+ expiresAt = loadAuth()?.expiresAt ?? now + 300;
991
+ return b;
992
+ }
993
+ const stillLoggedIn = loadAuth() !== null;
994
+ if (stillLoggedIn && inner && expiresAt > Math.floor(Date.now() / 1e3)) return inner;
995
+ inner = null;
996
+ expiresAt = 0;
997
+ return null;
998
+ }).finally(() => {
999
+ inflight = null;
1000
+ });
1001
+ return inflight;
1002
+ };
1003
+ const need = async () => {
1004
+ const b = await fresh();
1005
+ if (!b) throw new Error("inplan: not logged in (or session expired) \u2014 run `inplan login`");
1006
+ return b;
1007
+ };
1008
+ const channel = {
1009
+ append: async (e, o) => (await need()).channel.append(e, o),
1010
+ readSince: async (c) => (await need()).channel.readSince(c),
1011
+ // The poll-based wait never subscribes; delegate best-effort to the current inner (a re-mint
1012
+ // doesn't migrate an active subscription — not needed on this path).
1013
+ subscribe: (cb) => inner?.channel.subscribe(cb) ?? (() => {
1014
+ }),
1015
+ getCursor: async () => (await need()).channel.getCursor(),
1016
+ setCursor: async (s) => (await need()).channel.setCursor(s),
1017
+ claimLock: async (t) => (await need()).channel.claimLock(t),
1018
+ isSuperseded: async (t) => (await need()).channel.isSuperseded(t),
1019
+ presence: async () => (await need()).channel.presence()
1020
+ };
1021
+ const store = {
1022
+ loadDoc: async () => (await need()).store.loadDoc(),
1023
+ saveDoc: async (c) => (await need()).store.saveDoc(c),
1024
+ getCanonical: async () => (await need()).store.getCanonical(),
1025
+ setCanonical: async (c) => (await need()).store.setCanonical(c),
1026
+ getProposed: async () => (await need()).store.getProposed(),
1027
+ setProposed: async (c) => (await need()).store.setProposed(c),
1028
+ clearProposed: async () => (await need()).store.clearProposed(),
1029
+ backup: async (c, m) => (await need()).store.backup(c, m)
1030
+ };
1031
+ return { channel, store, tokenNow: () => inner?.token ?? null };
1032
+ }
885
1033
 
886
1034
  // src/cliLogin.ts
887
1035
  import { createServer } from "http";
@@ -1232,7 +1380,9 @@ function addComment(currentText, input) {
1232
1380
  import { homedir as homedir5 } from "os";
1233
1381
  import { join as join7 } from "path";
1234
1382
  import { pathToFileURL } from "url";
1235
- var PLUGIN_HTTP = (process.env.INPLAN_PLUGIN_URL || "wss://inplan-collab.fly.dev").replace(/^ws/, "http");
1383
+ var DEFAULT_HUB_URL = "wss://inplan-collab.fly.dev";
1384
+ var resolveHubUrl = () => process.env.INPLAN_PLUGIN_URL || process.env.INPLAN_COLLAB_URL || DEFAULT_HUB_URL;
1385
+ var PLUGIN_HTTP = resolveHubUrl().replace(/^ws/, "http");
1236
1386
  var defaultCacheDir = () => join7(process.env.INPLAN_HOME || join7(homedir5(), ".inplan"), "plugin-cache");
1237
1387
  var defaultDeps = {
1238
1388
  resolve: resolveDesktopPlugin,
@@ -1256,11 +1406,49 @@ async function loadPluginGate(session, options, deps = defaultDeps) {
1256
1406
  }
1257
1407
  }
1258
1408
 
1409
+ // src/liveSync.ts
1410
+ function shouldHydrateWorkFile(o) {
1411
+ if (!o.exists) return true;
1412
+ if (o.pending) return false;
1413
+ return o.currentHash != null && o.currentHash === o.syncedHash;
1414
+ }
1415
+ function pendingRequiresReplay(o) {
1416
+ return o.writeFailed;
1417
+ }
1418
+ function trackGateDegradations(gate, localStore, onWriteError) {
1419
+ let readFailed = false;
1420
+ let writeFailed = false;
1421
+ return {
1422
+ readFailed: () => readFailed,
1423
+ writeFailed: () => writeFailed,
1424
+ gate: {
1425
+ readCanonical: async () => {
1426
+ try {
1427
+ return await gate.readCanonical();
1428
+ } catch (e) {
1429
+ readFailed = true;
1430
+ throw e;
1431
+ }
1432
+ },
1433
+ applyRevision: async (md) => {
1434
+ try {
1435
+ await gate.applyRevision(md);
1436
+ } catch (e) {
1437
+ writeFailed = true;
1438
+ onWriteError?.(String(e));
1439
+ await localStore.setCanonical(md);
1440
+ await localStore.saveDoc(md);
1441
+ }
1442
+ }
1443
+ }
1444
+ };
1445
+ }
1446
+
1259
1447
  // src/presence.ts
1260
1448
  import { HocuspocusProvider, HocuspocusProviderWebsocket } from "@hocuspocus/provider";
1261
1449
  import * as Y from "yjs";
1262
1450
  import WebSocket2 from "ws";
1263
- var COLLAB_URL = process.env.INPLAN_COLLAB_URL || "wss://inplan-collab.fly.dev";
1451
+ var COLLAB_URL = resolveHubUrl();
1264
1452
  function announcePresence(docId, token, model) {
1265
1453
  try {
1266
1454
  const ydoc = new Y.Doc();
@@ -1499,7 +1687,7 @@ function cachedElectronZip(version, platform, arch) {
1499
1687
  for (const sub of readdirSync2(root)) {
1500
1688
  const f = join9(root, sub, want);
1501
1689
  if (!existsSync9(f)) continue;
1502
- const mtime = statSync2(f).mtimeMs;
1690
+ const mtime = statSync3(f).mtimeMs;
1503
1691
  if (!best || mtime > best.mtime) best = { file: f, mtime };
1504
1692
  }
1505
1693
  return best?.file ?? null;
@@ -1686,12 +1874,12 @@ async function waitCycle(backend, explicitCursor, confirmed, model, gate = null)
1686
1874
  output({ status: "superseded" });
1687
1875
  return;
1688
1876
  }
1689
- await channel.setCursor(result.cursor);
1690
1877
  if (backend.onSaveLocally && result.entries.some((e) => e.type === LogEventType.SaveLocallyRequested)) {
1691
1878
  backend.logExit("save_locally");
1692
1879
  await backend.onSaveLocally();
1693
1880
  return;
1694
1881
  }
1882
+ await channel.setCursor(result.cursor);
1695
1883
  const navEntry = result.entries.find((e) => e.type === LogEventType.NavigatedTo);
1696
1884
  if (navEntry) {
1697
1885
  const path = navEntry.payload?.path;
@@ -1740,10 +1928,7 @@ async function doLogin(args) {
1740
1928
  return;
1741
1929
  }
1742
1930
  try {
1743
- const auth = await browserLogin({ onUrl: (u) => process.stderr.write(`Opening your browser to sign in:
1744
- ${u}
1745
- If it didn't open, paste that URL into your browser.
1746
- `) });
1931
+ const auth = await defaultBrowserLogin();
1747
1932
  saveAuth(auth);
1748
1933
  await persistCloudIdentity();
1749
1934
  output({ status: "logged_in", url: auth.url, ...auth.email ? { email: auth.email } : {} });
@@ -1761,7 +1946,36 @@ async function persistCloudIdentity() {
1761
1946
  } catch {
1762
1947
  }
1763
1948
  }
1949
+ function canInteractiveLogin(args) {
1950
+ if (hasFlag(args, "no-login")) return false;
1951
+ if (process.env.CI || process.env.INPLAN_NO_BROWSER) return false;
1952
+ return Boolean(process.stdin.isTTY && process.stdout.isTTY);
1953
+ }
1954
+ async function ensureLoggedIn(args, login = defaultBrowserLogin) {
1955
+ if (loadAuth()) return true;
1956
+ if (!canInteractiveLogin(args)) return false;
1957
+ try {
1958
+ process.stderr.write("inplan: not signed in \u2014 opening your browser to sign in\u2026\n");
1959
+ saveAuth(await login());
1960
+ await persistCloudIdentity();
1961
+ return true;
1962
+ } catch (e) {
1963
+ process.stderr.write(`inplan login: ${e instanceof Error ? e.message : String(e)}
1964
+ `);
1965
+ return false;
1966
+ }
1967
+ }
1968
+ function defaultBrowserLogin() {
1969
+ return browserLogin({ onUrl: (u) => process.stderr.write(`Opening your browser to sign in:
1970
+ ${u}
1971
+ If it didn't open, paste that URL into your browser.
1972
+ `) });
1973
+ }
1764
1974
  async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile, model) {
1975
+ if (!await ensureLoggedIn(rest)) {
1976
+ process.stderr.write("inplan: not logged in (or session expired) \u2014 run `inplan login`\n");
1977
+ process.exit(1);
1978
+ }
1765
1979
  const backend = await remoteBackend(docId, "cli-agent");
1766
1980
  if (!backend) {
1767
1981
  process.stderr.write("inplan: not logged in (or session expired) \u2014 run `inplan login`\n");
@@ -1793,8 +2007,9 @@ async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile,
1793
2007
  output({ status: "messaged" });
1794
2008
  return;
1795
2009
  }
2010
+ const live = liveRemoteBackend(docId, "cli-agent");
1796
2011
  const onSaveLocally = localFile ? async () => {
1797
- const body = await backend.store.loadDoc();
2012
+ const body = await live.store.loadDoc();
1798
2013
  writeFileSync8(localFile, body);
1799
2014
  writeStatus(docPaths(localFile).statusPath, { location: "local", originalPath: localFile, lastSyncedHash: hashBody(body) });
1800
2015
  const pid = spawnApp(localFile);
@@ -1802,11 +2017,102 @@ async function runRemote(cmd, docId, explicitCursor, confirmed, rest, localFile,
1802
2017
  } : void 0;
1803
2018
  const presence = announcePresence(docId, backend.token, model);
1804
2019
  try {
2020
+ const hubUrl = resolveHubUrl();
2021
+ const hubSession = JSON.stringify({ url: hubUrl, docName: docId, token: backend.token });
2022
+ const gate = await loadPluginGate(hubSession, { token: backend.token });
2023
+ if (gate) {
2024
+ const workFile = join9(sidecarRoot(), "remote", `${docId}.plan.md`);
2025
+ const pendingPath = `${workFile}.pending`;
2026
+ const hashPath = `${workFile}.synced`;
2027
+ mkdirSync8(dirname9(workFile), { recursive: true });
2028
+ const readIf = (p) => existsSync9(p) ? readFileSync9(p, "utf8") : null;
2029
+ const recordSynced = (content) => writeFileSync8(hashPath, hashBody(content));
2030
+ let onGate = true;
2031
+ let canonical = "";
2032
+ try {
2033
+ canonical = await gate.readCanonical();
2034
+ } catch (e) {
2035
+ process.stderr.write(`inplan: live-collab hub unreachable (${String(e)}); using turn-based sync
2036
+ `);
2037
+ onGate = false;
2038
+ }
2039
+ if (onGate) {
2040
+ const exists = existsSync9(workFile);
2041
+ if (shouldHydrateWorkFile({
2042
+ exists,
2043
+ pending: existsSync9(pendingPath),
2044
+ currentHash: exists ? hashBody(readFileSync9(workFile, "utf8")) : null,
2045
+ syncedHash: readIf(hashPath)
2046
+ })) {
2047
+ writeFileSync8(workFile, canonical);
2048
+ recordSynced(canonical);
2049
+ }
2050
+ const localStore = fsBackend(workFile).store;
2051
+ const gateStore = {
2052
+ loadDoc: () => localStore.loadDoc(),
2053
+ saveDoc: (c) => localStore.saveDoc(c),
2054
+ getCanonical: () => localStore.getCanonical(),
2055
+ setCanonical: (c) => localStore.setCanonical(c),
2056
+ backup: (c, m) => localStore.backup(c, m),
2057
+ getProposed: () => live.store.getProposed(),
2058
+ setProposed: (c) => live.store.setProposed(c),
2059
+ clearProposed: () => live.store.clearProposed()
2060
+ };
2061
+ const onSaveLocallyGate = localFile ? async () => {
2062
+ const body = await gate.readCanonical();
2063
+ writeFileSync8(localFile, body);
2064
+ writeStatus(docPaths(localFile).statusPath, { location: "local", originalPath: localFile, lastSyncedHash: hashBody(body) });
2065
+ const pid = spawnApp(localFile);
2066
+ output({ status: "moved_local", path: localFile, reopened: pid !== null });
2067
+ } : void 0;
2068
+ const tracked = trackGateDegradations(
2069
+ gate,
2070
+ localStore,
2071
+ (m) => process.stderr.write(`inplan: live-collab hub write failed (${m}); kept the edit locally to retry
2072
+ `)
2073
+ );
2074
+ process.stderr.write(`inplan: live-collab \u2014 plan at ${workFile}; read/edit it there, then re-run to sync
2075
+ `);
2076
+ await waitCycle(
2077
+ {
2078
+ channel: live.channel,
2079
+ // turns/comments still ride the cloud control log (self-refreshing)…
2080
+ store: gateStore,
2081
+ // …the agent reads/edits a local working copy; proposals go to the cloud…
2082
+ history: async () => (await live.channel.readSince(0)).entries,
2083
+ logExit: () => {
2084
+ },
2085
+ ...onSaveLocallyGate ? { onSaveLocally: onSaveLocallyGate } : {}
2086
+ },
2087
+ explicitCursor,
2088
+ confirmed,
2089
+ model,
2090
+ tracked.gate
2091
+ // …and accepted edits apply through the hub, not the store.
2092
+ );
2093
+ if (tracked.readFailed() || tracked.writeFailed()) {
2094
+ if (pendingRequiresReplay({ readFailed: tracked.readFailed(), writeFailed: tracked.writeFailed() })) {
2095
+ writeFileSync8(pendingPath, "1");
2096
+ }
2097
+ process.stderr.write("inplan: hub was unavailable this turn \u2014 keeping local edits (will sync next turn)\n");
2098
+ } else {
2099
+ if (existsSync9(pendingPath)) rmSync2(pendingPath);
2100
+ recordSynced(readFileSync9(workFile, "utf8"));
2101
+ try {
2102
+ const fresh = await gate.readCanonical();
2103
+ writeFileSync8(workFile, fresh);
2104
+ recordSynced(fresh);
2105
+ } catch {
2106
+ }
2107
+ }
2108
+ return;
2109
+ }
2110
+ }
1805
2111
  await waitCycle(
1806
2112
  {
1807
- channel: backend.channel,
1808
- store: backend.store,
1809
- history: async () => (await backend.channel.readSince(0)).entries,
2113
+ channel: live.channel,
2114
+ store: live.store,
2115
+ history: async () => (await live.channel.readSince(0)).entries,
1810
2116
  logExit: () => {
1811
2117
  },
1812
2118
  // no local sidecar for a cloud doc
@@ -1915,7 +2221,7 @@ function activeDocForCwd(cwd) {
1915
2221
  const rel = relative4(base2, real(orig));
1916
2222
  if (rel === "" || rel.startsWith("..") || isAbsolute2(rel)) continue;
1917
2223
  const logPath = join9(dir, "log.jsonl");
1918
- const mtime = existsSync9(logPath) ? statSync2(logPath).mtimeMs : 0;
2224
+ const mtime = existsSync9(logPath) ? statSync3(logPath).mtimeMs : 0;
1919
2225
  if (!best || mtime > best.mtime) best = { file: resolve3(orig), mtime };
1920
2226
  } catch {
1921
2227
  }
@@ -2058,7 +2364,8 @@ function skillTargets() {
2058
2364
  { name: "Codex", root: join9(home, ".codex"), target: join9(home, ".codex", "skills", "inplan", "SKILL.md") }
2059
2365
  ];
2060
2366
  }
2061
- var SKILL_ALLOW = ["Bash(inplan *)", "Edit(**/*.plan.md)", "Write(**/*.plan.md)", "Read(~/.inplan/**)", "Edit(~/.inplan/**)", "Write(~/.inplan/**)"];
2367
+ var SKILL_ALLOW = ["Bash(inplan *)", "Edit(**/*.plan.md)", "Read(~/.inplan/**)", "Edit(~/.inplan/**)"];
2368
+ var SKILL_ALLOW_OBSOLETE = ["Write(**/*.plan.md)", "Write(~/.inplan/**)"];
2062
2369
  var SKILL_DIRS = ["~/.inplan/"];
2063
2370
  function grantClaudePermissions(claudeRoot) {
2064
2371
  const settingsPath = join9(claudeRoot, "settings.json");
@@ -2074,9 +2381,12 @@ function grantClaudePermissions(claudeRoot) {
2074
2381
  }
2075
2382
  const rawPerms = settings.permissions;
2076
2383
  const perms = rawPerms && typeof rawPerms === "object" && !Array.isArray(rawPerms) ? rawPerms : {};
2077
- const allow = Array.isArray(perms.allow) ? perms.allow : [];
2384
+ let allow = Array.isArray(perms.allow) ? perms.allow : [];
2078
2385
  const dirs = Array.isArray(perms.additionalDirectories) ? perms.additionalDirectories : [];
2079
2386
  let changed = false;
2387
+ const beforePrune = allow.length;
2388
+ allow = allow.filter((r) => !SKILL_ALLOW_OBSOLETE.includes(r));
2389
+ if (allow.length !== beforePrune) changed = true;
2080
2390
  for (const r of SKILL_ALLOW) {
2081
2391
  if (!allow.includes(r)) {
2082
2392
  allow.push(r);
@@ -2096,7 +2406,7 @@ function grantClaudePermissions(claudeRoot) {
2096
2406
  try {
2097
2407
  const tmp = settingsPath + ".tmp";
2098
2408
  writeFileSync8(tmp, JSON.stringify(settings, null, 2) + "\n");
2099
- renameSync(tmp, settingsPath);
2409
+ renameSync2(tmp, settingsPath);
2100
2410
  } catch {
2101
2411
  return false;
2102
2412
  }
@@ -2154,7 +2464,7 @@ function writeJsonAtomic(path, value) {
2154
2464
  mkdirSync8(dirname9(path), { recursive: true });
2155
2465
  const tmp = path + ".tmp";
2156
2466
  writeFileSync8(tmp, JSON.stringify(value, null, 2) + "\n");
2157
- renameSync(tmp, path);
2467
+ renameSync2(tmp, path);
2158
2468
  return true;
2159
2469
  } catch {
2160
2470
  return false;
@@ -2227,7 +2537,7 @@ function installPiRelayExtension(piAgentRoot) {
2227
2537
  mkdirSync8(dirname9(path), { recursive: true });
2228
2538
  const tmp = path + ".tmp";
2229
2539
  writeFileSync8(tmp, PI_RELAY_EXTENSION);
2230
- renameSync(tmp, path);
2540
+ renameSync2(tmp, path);
2231
2541
  return true;
2232
2542
  } catch {
2233
2543
  return false;
@@ -2425,7 +2735,7 @@ async function main() {
2425
2735
  );
2426
2736
  if (!cmd || !["open", "wait", "signal", "message", "comment", "relay", "status", "promote", "demote", "upload"].includes(cmd)) {
2427
2737
  process.stderr.write(
2428
- 'usage: inplan <open|wait|signal> <file|--remote DOC_ID> [--model NAME] [--cursor N] [--confirmed-comment-deletion=a,b] [--done] [--reload]\n inplan message <file> "your message" (relay a note to the editor status bar)\n inplan comment <file> (--parent-id <id>|--doc|--span "text") --text "..." [--model NAME] [--may-resolve] [--question <json>]\n inplan relay [--hook <kind> | --text <s> [--activity]] (agent-hook \u2192 editor; resolves the active doc)\n inplan status <file>\n inplan upload <file> [--org <slug>] [--repo <name>] [--path <p>] [--evict-lru] (Collaborate on Cloud)\n inplan promote <file> --cloud-doc <docId> [--locator org/repo/path]\n inplan demote <file>\n inplan login (opens the browser to sign in; or --url <url> --anon <key> --refresh <token> for scripts)\n inplan whoami | logout\n'
2738
+ 'usage: inplan open <file> (create/open a local plan in the editor)\n inplan wait <file|--remote DOC_ID> [--model NAME] [--cursor N] [--confirmed-comment-deletion=a,b] [--done] [--reload]\n inplan signal <file|--remote DOC_ID> [--done] [--reload]\n inplan message <file> "your message" (relay a note to the editor status bar)\n inplan comment <file> (--parent-id <id>|--doc|--span "text") --text "..." [--model NAME] [--may-resolve] [--question <json>]\n inplan relay [--hook <kind> | --text <s> [--activity]] (agent-hook \u2192 editor; resolves the active doc)\n inplan status <file>\n inplan upload <file> [--org <slug>] [--repo <name>] [--path <p>] [--evict-lru] (Collaborate on Cloud)\n inplan promote <file> --cloud-doc <docId> [--locator org/repo/path]\n inplan demote <file>\n inplan login (opens the browser to sign in; or --url <url> --anon <key> --refresh <token> for scripts)\n inplan whoami | logout\n'
2429
2739
  );
2430
2740
  process.exit(64);
2431
2741
  }
@@ -2436,7 +2746,11 @@ async function main() {
2436
2746
  const remoteDocId = getFlag(args, "remote");
2437
2747
  if (remoteDocId) {
2438
2748
  rejectCommentOnCloud(cmd, false);
2439
- await runRemote(cmd, remoteDocId, explicitCursor, confirmed, args, void 0, model);
2749
+ const remoteCmd = cmd === "open" ? "wait" : cmd;
2750
+ if (cmd === "open") {
2751
+ process.stderr.write("inplan: `open --remote` is deprecated (a cloud doc has no local editor to launch) \u2014 use `wait --remote`. Attaching as `wait`.\n");
2752
+ }
2753
+ await runRemote(remoteCmd, remoteDocId, explicitCursor, confirmed, args, void 0, model);
2440
2754
  return;
2441
2755
  }
2442
2756
  const file = argv[1] ? resolve3(argv[1]) : argv[1];
@@ -2593,7 +2907,9 @@ if (isProgramEntry()) {
2593
2907
  }
2594
2908
  export {
2595
2909
  activeDocForCwd,
2910
+ canInteractiveLogin,
2596
2911
  doUpload,
2912
+ ensureLoggedIn,
2597
2913
  notesFromHook,
2598
2914
  transcriptTextBlocks
2599
2915
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inplan",
3
- "version": "0.1.24",
3
+ "version": "0.1.26",
4
4
  "description": "inplan — a Markdown editor for human ⇄ coding-agent planning. CLI + desktop editor.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {
package/skill/SKILL.md CHANGED
@@ -7,10 +7,8 @@ description: Use for ANY planning, design, PRD, or spec document — always plan
7
7
  allowed-tools:
8
8
  - Bash(inplan *)
9
9
  - Edit(**/*.plan.md)
10
- - Write(**/*.plan.md)
11
10
  - Read(~/.inplan/**)
12
11
  - Edit(~/.inplan/**)
13
- - Write(~/.inplan/**)
14
12
  ---
15
13
 
16
14
  # inplan