inplan 0.3.3 → 0.3.4

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.
@@ -81,6 +81,16 @@ var ParseError = class extends Error {
81
81
  this.name = "ParseError";
82
82
  }
83
83
  };
84
+ function decodeSegment(seg) {
85
+ try {
86
+ return decodeURIComponent(seg);
87
+ } catch {
88
+ return seg;
89
+ }
90
+ }
91
+ function decodeLinkPath(target) {
92
+ return target.split("/").map(decodeSegment).join("/");
93
+ }
84
94
  var CONTROL_LOG_VERSION = 1;
85
95
  var LogEventType = {
86
96
  EditorPid: "editor_pid",
@@ -566,6 +576,8 @@ function safeJoin(root, child) {
566
576
  return rel === "" || !rel.startsWith("..") && !path.isAbsolute(rel) ? full : null;
567
577
  }
568
578
  var base = (u) => u.endsWith("/") ? u : `${u}/`;
579
+ var PLUGIN_FETCH_TIMEOUT_MS = 8e3;
580
+ var bounded = () => ({ signal: AbortSignal.timeout(PLUGIN_FETCH_TIMEOUT_MS) });
569
581
  function loadCached(cacheDir2, version, publicKey, now) {
570
582
  try {
571
583
  const dir = safeJoin(cacheDir2, version);
@@ -588,7 +600,7 @@ function loadCached(cacheDir2, version, publicKey, now) {
588
600
  }
589
601
  async function fetchAndCache(bundleUrl, leaseToken, opts) {
590
602
  const root = base(bundleUrl);
591
- const mres = await opts.fetchImpl(`${root}manifest.json`);
603
+ const mres = await opts.fetchImpl(`${root}manifest.json`, bounded());
592
604
  if (!mres.ok) return null;
593
605
  const manifest = await mres.json();
594
606
  if (!manifest?.version || !Array.isArray(manifest.files)) return null;
@@ -599,7 +611,8 @@ async function fetchAndCache(bundleUrl, leaseToken, opts) {
599
611
  for (const entry of manifest.files) {
600
612
  const filePath = safeJoin(dir, entry.name);
601
613
  if (!filePath) return null;
602
- const r = await opts.fetchImpl(`${root}${entry.name}`);
614
+ if (fs.existsSync(filePath) && verifyBundleBytes(fs.readFileSync(filePath), entry, opts.publicKey)) continue;
615
+ const r = await opts.fetchImpl(`${root}${entry.name}`, bounded());
603
616
  if (!r.ok) return null;
604
617
  const bytes = Buffer.from(await r.arrayBuffer());
605
618
  if (!verifyBundleBytes(bytes, entry, opts.publicKey)) return null;
@@ -626,7 +639,7 @@ async function resolvePluginOutcome(options) {
626
639
  if (!publicKey) return { plugin: null, reason: "unavailable" };
627
640
  if (options.token) {
628
641
  try {
629
- const res = await fetchImpl(`${base(options.apiBase)}api/v1/desktop-plugin`, { headers: { authorization: `Bearer ${options.token}` } });
642
+ const res = await fetchImpl(`${base(options.apiBase)}api/v1/desktop-plugin`, { ...bounded(), headers: { authorization: `Bearer ${options.token}` } });
630
643
  if (res.ok) {
631
644
  const grant = await res.json();
632
645
  if (grant.entitled === false) return { plugin: null, reason: "unentitled" };
@@ -1633,7 +1646,8 @@ ${body.replace(/\s*$/, "")}
1633
1646
  return { relPath: toPosix(node_path.relative(docDir, abs)) };
1634
1647
  });
1635
1648
  electron.ipcMain.handle("doc:open", (_e, target) => {
1636
- const abs = node_path.resolve("/", target);
1649
+ const decoded = node_path.resolve("/", decodeLinkPath(target));
1650
+ const abs = node_fs.existsSync(decoded) ? decoded : node_path.resolve("/", target);
1637
1651
  if (!abs.endsWith(".md") || !node_fs.existsSync(abs)) {
1638
1652
  process.stderr.write(`[inplan] open-doc: no such .md file: ${abs}
1639
1653
  `);
@@ -7083,12 +7083,29 @@ function orderComments(comments) {
7083
7083
  for (const c of comments.slice().sort(cmp)) emit(c);
7084
7084
  return out;
7085
7085
  }
7086
+ var COMMENT_KEY_ORDER = ["id", "parentId", "anchor", "text", "author", "date", "resolved", "may_resolve", "question", "selected", "agent", "mentions"];
7087
+ function canonicalizeComment(c) {
7088
+ const out = {};
7089
+ const rec = c;
7090
+ for (const k2 of COMMENT_KEY_ORDER) if (rec[k2] !== void 0) out[k2] = rec[k2];
7091
+ for (const k2 of Object.keys(rec).sort()) if (!(k2 in out) && rec[k2] !== void 0) out[k2] = rec[k2];
7092
+ return out;
7093
+ }
7086
7094
  var ParseError = class extends Error {
7087
7095
  constructor(message) {
7088
7096
  super(message);
7089
7097
  this.name = "ParseError";
7090
7098
  }
7091
7099
  };
7100
+ function encodeSegment(seg) {
7101
+ return encodeURIComponent(seg).replace(/\(/g, "%28").replace(/\)/g, "%29");
7102
+ }
7103
+ function markdownLink(text2, path) {
7104
+ return `[${text2}](${path.split("/").map(encodeSegment).join("/")})`;
7105
+ }
7106
+ function escapeLinkText(text2) {
7107
+ return text2.replace(/[\\[\]]/g, (c) => `\\${c}`);
7108
+ }
7092
7109
  var LogEventType = {
7093
7110
  ModeChanged: "mode_changed",
7094
7111
  DocumentEdited: "document_edited",
@@ -43219,7 +43236,7 @@ function spanSource(body, selected, span) {
43219
43236
  function linkSelectionToDoc(body, selected, span, target) {
43220
43237
  const r2 = locateCleanSpan(body, selected, span);
43221
43238
  if (!r2) return null;
43222
- return body.slice(0, r2.start) + `[${body.slice(r2.start, r2.end)}](${target})` + body.slice(r2.end);
43239
+ return body.slice(0, r2.start) + markdownLink(body.slice(r2.start, r2.end), target) + body.slice(r2.end);
43223
43240
  }
43224
43241
  function spanLineRange(body, span) {
43225
43242
  if (!span || !Number.isInteger(span.startLine) || !Number.isInteger(span.endLine) || span.startLine < 0 || span.endLine < span.startLine) return null;
@@ -43257,7 +43274,7 @@ function moveSelectionToDoc(doc2, selected, span, title, target) {
43257
43274
  if (after === "") sep = sep ? "\n" : "";
43258
43275
  const remaining = {
43259
43276
  ...doc2,
43260
- body: before + prefix + `[${title}](${target})` + sep + after,
43277
+ body: before + prefix + markdownLink(escapeLinkText(title), target) + sep + after,
43261
43278
  comments: doc2.comments.filter((c) => !moved.has(c.id))
43262
43279
  };
43263
43280
  return { remaining, movedBody, movedComments: doc2.comments.filter((c) => moved.has(c.id)) };
@@ -46030,16 +46047,8 @@ function anchoredText(body, id2) {
46030
46047
  const m2 = new RegExp(`\\[([^\\]]*)\\]\\(#${id2}\\)`).exec(body);
46031
46048
  return m2 ? m2[1] : null;
46032
46049
  }
46033
- var COMMENT_KEY_ORDER = ["id", "parentId", "anchor", "text", "author", "date", "resolved", "may_resolve", "question", "selected", "agent", "mentions"];
46034
- function canonicalComment(c) {
46035
- const rec = c;
46036
- const out = {};
46037
- for (const k2 of COMMENT_KEY_ORDER) if (rec[k2] !== void 0) out[k2] = rec[k2];
46038
- for (const k2 of Object.keys(rec).sort()) if (!(k2 in out) && rec[k2] !== void 0) out[k2] = rec[k2];
46039
- return out;
46040
- }
46041
46050
  function sameComment(a, b) {
46042
- return JSON.stringify(canonicalComment(a)) === JSON.stringify(canonicalComment(b));
46051
+ return JSON.stringify(canonicalizeComment(a)) === JSON.stringify(canonicalizeComment(b));
46043
46052
  }
46044
46053
  function anchorLine(body, id2) {
46045
46054
  const idx = body.indexOf(`](#${id2})`);
@@ -46466,7 +46475,27 @@ function App(props = {}) {
46466
46475
  hostApi().cloudSignIn?.onClose(() => setSignInUrl(null)),
46467
46476
  // Comment store (plugin): adopt the external store's comments whenever it (or this editor)
46468
46477
  // changes them. Body stays driven by the editor/binding; only `comments` is synced.
46469
- commentStore?.observe(() => setDoc((d) => ({ ...d, comments: commentStore.list() })))
46478
+ commentStore?.observe(() => setDoc((d) => ({ ...d, comments: commentStore.list() }))),
46479
+ // The binding owns the body. Follow it whether or not a source pane is mounted to report it:
46480
+ // otherwise the editor's copy goes stale whenever the shared text changes from elsewhere, and
46481
+ // every programmatic edit built from that copy writes the change away. Body only, functional
46482
+ // and idempotent: this editor's own setText echoes back here, and must neither re-render nor
46483
+ // touch dirty tracking (a bound editor doesn't track it).
46484
+ hostApi().binding?.observe?.(() => {
46485
+ const binding = hostApi().binding;
46486
+ if (!binding) return;
46487
+ const text2 = binding.getText();
46488
+ let body;
46489
+ if (commentStore) body = text2;
46490
+ else {
46491
+ try {
46492
+ body = parse(text2).body;
46493
+ } catch {
46494
+ return;
46495
+ }
46496
+ }
46497
+ setDoc((d) => d.body === body ? d : { ...d, body });
46498
+ })
46470
46499
  ];
46471
46500
  const onSel = () => setSelectionText(window.getSelection()?.toString() ?? "");
46472
46501
  document.addEventListener("selectionchange", onSel);
@@ -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-CKlJ2VBc.js"></script>
24
+ <script type="module" crossorigin src="./assets/index-C1AH6VQU.js"></script>
25
25
  <link rel="stylesheet" crossorigin href="./assets/index-DziuyBKZ.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 dirname11, extname, 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-5WMTJCY6.js
12
+ // ../core/dist/chunk-56Z7HGQ3.js
13
13
  function isReply(c) {
14
14
  return c.parentId !== void 0;
15
15
  }
@@ -774,6 +774,8 @@ function safeJoin(root, child) {
774
774
  return rel === "" || !rel.startsWith("..") && !isAbsolute(rel) ? full : null;
775
775
  }
776
776
  var base = (u) => u.endsWith("/") ? u : `${u}/`;
777
+ var PLUGIN_FETCH_TIMEOUT_MS = 8e3;
778
+ var bounded = () => ({ signal: AbortSignal.timeout(PLUGIN_FETCH_TIMEOUT_MS) });
777
779
  function loadCached(cacheDir, version, publicKey, now) {
778
780
  try {
779
781
  const dir = safeJoin(cacheDir, version);
@@ -796,7 +798,7 @@ function loadCached(cacheDir, version, publicKey, now) {
796
798
  }
797
799
  async function fetchAndCache(bundleUrl, leaseToken, opts) {
798
800
  const root = base(bundleUrl);
799
- const mres = await opts.fetchImpl(`${root}manifest.json`);
801
+ const mres = await opts.fetchImpl(`${root}manifest.json`, bounded());
800
802
  if (!mres.ok) return null;
801
803
  const manifest = await mres.json();
802
804
  if (!manifest?.version || !Array.isArray(manifest.files)) return null;
@@ -807,7 +809,8 @@ async function fetchAndCache(bundleUrl, leaseToken, opts) {
807
809
  for (const entry of manifest.files) {
808
810
  const filePath = safeJoin(dir, entry.name);
809
811
  if (!filePath) return null;
810
- const r = await opts.fetchImpl(`${root}${entry.name}`);
812
+ if (existsSync7(filePath) && verifyBundleBytes(readFileSync6(filePath), entry, opts.publicKey)) continue;
813
+ const r = await opts.fetchImpl(`${root}${entry.name}`, bounded());
811
814
  if (!r.ok) return null;
812
815
  const bytes = Buffer.from(await r.arrayBuffer());
813
816
  if (!verifyBundleBytes(bytes, entry, opts.publicKey)) return null;
@@ -834,7 +837,7 @@ async function resolvePluginOutcome(options) {
834
837
  if (!publicKey) return { plugin: null, reason: "unavailable" };
835
838
  if (options.token) {
836
839
  try {
837
- const res = await fetchImpl(`${base(options.apiBase)}api/v1/desktop-plugin`, { headers: { authorization: `Bearer ${options.token}` } });
840
+ const res = await fetchImpl(`${base(options.apiBase)}api/v1/desktop-plugin`, { ...bounded(), headers: { authorization: `Bearer ${options.token}` } });
838
841
  if (res.ok) {
839
842
  const grant = await res.json();
840
843
  if (grant.entitled === false) return { plugin: null, reason: "unentitled" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inplan",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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": {