inplan 0.2.2 → 0.3.0

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 CHANGED
@@ -4101,15 +4101,10 @@ async function cleanupOrphanedUploads(db, paths) {
4101
4101
  } catch {
4102
4102
  }
4103
4103
  }
4104
- async function doAssetUpload(file, args) {
4105
- const status = readStatus(docPaths(file).statusPath);
4106
- if (status.location !== "cloud" || !status.cloudDocId) {
4107
- process.stderr.write("inplan asset-upload: document is not in the cloud\n");
4108
- process.exit(1);
4109
- }
4104
+ async function doAssetUploadForDoc(cloudDocId, args) {
4110
4105
  const bytesFile = getFlag(args, "bytes-file");
4111
4106
  if (!bytesFile) {
4112
- process.stderr.write("inplan asset-upload: usage: inplan asset-upload <file> --bytes-file <path> [--ext <ext>]\n");
4107
+ process.stderr.write("inplan asset-upload: usage: inplan asset-upload <file|--remote DOC_ID> --bytes-file <path> [--ext <ext>]\n");
4113
4108
  process.exit(64);
4114
4109
  }
4115
4110
  const s = await authedSession();
@@ -4117,7 +4112,7 @@ async function doAssetUpload(file, args) {
4117
4112
  process.stderr.write("inplan: not logged in (or session expired) \u2014 run `inplan login`\n");
4118
4113
  process.exit(1);
4119
4114
  }
4120
- const { data: doc, error: docErr } = await s.db.from("documents").select("org_id").eq("id", status.cloudDocId).maybeSingle();
4115
+ const { data: doc, error: docErr } = await s.db.from("documents").select("org_id").eq("id", cloudDocId).maybeSingle();
4121
4116
  const orgId = doc?.org_id;
4122
4117
  if (docErr || !orgId) {
4123
4118
  process.stderr.write(`inplan asset-upload: ${docErr?.message ?? "could not resolve the document's organization"}
@@ -4126,13 +4121,29 @@ async function doAssetUpload(file, args) {
4126
4121
  }
4127
4122
  const requestedExt = (getFlag(args, "ext") ?? "png").toLowerCase();
4128
4123
  const bytes = readFileSync11(bytesFile);
4129
- const uploaded = await uploadAssetBytes(s.db, orgId, status.cloudDocId, bytes, requestedExt);
4124
+ const storedExt = Object.prototype.hasOwnProperty.call(ASSET_MIME_BY_EXT, requestedExt) ? requestedExt : "png";
4125
+ const sha256 = createHash4("sha256").update(bytes).digest("hex");
4126
+ const known = await assetPathByContent(s.db, cloudDocId, sha256, storedExt);
4127
+ if (known) {
4128
+ output({ status: "uploaded", relPath: s.db.storage.from(ASSET_BUCKET).getPublicUrl(known).data.publicUrl, reused: true });
4129
+ return;
4130
+ }
4131
+ const uploaded = await uploadAssetBytes(s.db, orgId, cloudDocId, bytes, requestedExt);
4130
4132
  if (!uploaded) {
4131
4133
  process.stderr.write("inplan asset-upload: upload failed\n");
4132
4134
  process.exit(1);
4133
4135
  }
4136
+ await rememberAsset(s.db, cloudDocId, sha256, storedExt, uploaded.path);
4134
4137
  output({ status: "uploaded", relPath: uploaded.url });
4135
4138
  }
4139
+ async function doAssetUpload(file, args) {
4140
+ const status = readStatus(docPaths(file).statusPath);
4141
+ if (status.location !== "cloud" || !status.cloudDocId) {
4142
+ process.stderr.write("inplan asset-upload: document is not in the cloud \u2014 for a doc you attached by id, use `inplan asset-upload --remote <docId>`\n");
4143
+ process.exit(1);
4144
+ }
4145
+ await doAssetUploadForDoc(status.cloudDocId, args);
4146
+ }
4136
4147
  var IMAGE_REF_RE = /!\[([^\]]*)\]\(\s*(?:<([^>]+)>|([^()\s]+))\s*\)/g;
4137
4148
  function isLocalRelativePath(dest) {
4138
4149
  return !/^[a-z][a-z0-9+.-]*:/i.test(dest) && !dest.startsWith("//") && !dest.startsWith("/");
@@ -4165,10 +4176,27 @@ function codeRanges(body) {
4165
4176
  function inRange(ranges, index) {
4166
4177
  return ranges.some(([start, end]) => index >= start && index < end);
4167
4178
  }
4179
+ async function assetPathByContent(db, docId, sha256, ext) {
4180
+ try {
4181
+ const { data, error } = await db.from("doc_assets").select("object_path").eq("doc_id", docId).eq("sha256", sha256).eq("ext", ext).maybeSingle();
4182
+ if (error) return null;
4183
+ const path = data?.object_path;
4184
+ return typeof path === "string" && path.length > 0 ? path : null;
4185
+ } catch {
4186
+ return null;
4187
+ }
4188
+ }
4189
+ async function rememberAsset(db, docId, sha256, ext, objectPath) {
4190
+ try {
4191
+ await db.from("doc_assets").insert({ doc_id: docId, sha256, ext, object_path: objectPath });
4192
+ } catch {
4193
+ }
4194
+ }
4168
4195
  async function migrateLocalImages(body, docDir, db, orgId, docId) {
4169
4196
  const excluded = codeRanges(body);
4170
4197
  const migrations = /* @__PURE__ */ new Map();
4171
4198
  const uploadedByDest = /* @__PURE__ */ new Map();
4199
+ const uploadedByHash = /* @__PURE__ */ new Map();
4172
4200
  const uploadedPaths = [];
4173
4201
  let docDirReal;
4174
4202
  try {
@@ -4202,9 +4230,27 @@ async function migrateLocalImages(body, docDir, db, orgId, docId) {
4202
4230
  } catch {
4203
4231
  continue;
4204
4232
  }
4233
+ const sha256 = createHash4("sha256").update(bytes).digest("hex");
4234
+ const contentKey = `${ext}:${sha256}`;
4235
+ const byHash = uploadedByHash.get(contentKey);
4236
+ if (byHash) {
4237
+ uploadedByDest.set(dest, byHash);
4238
+ migrations.set(m.index, { dest, url: byHash.url });
4239
+ continue;
4240
+ }
4241
+ const known = await assetPathByContent(db, docId, sha256, ext);
4242
+ if (known) {
4243
+ const reused = { path: known, url: db.storage.from(ASSET_BUCKET).getPublicUrl(known).data.publicUrl };
4244
+ uploadedByDest.set(dest, reused);
4245
+ uploadedByHash.set(contentKey, reused);
4246
+ migrations.set(m.index, { dest, url: reused.url });
4247
+ continue;
4248
+ }
4205
4249
  const uploaded = await uploadAssetBytes(db, orgId, docId, bytes, ext);
4206
4250
  if (!uploaded) continue;
4251
+ await rememberAsset(db, docId, sha256, ext, uploaded.path);
4207
4252
  uploadedByDest.set(dest, uploaded);
4253
+ uploadedByHash.set(contentKey, uploaded);
4208
4254
  uploadedPaths.push(uploaded.path);
4209
4255
  migrations.set(m.index, { dest, url: uploaded.url });
4210
4256
  }
@@ -4294,7 +4340,7 @@ async function main() {
4294
4340
  );
4295
4341
  if (!cmd || !["open", "wait", "signal", "message", "comment", "relay", "status", "promote", "demote", "upload", "asset-upload"].includes(cmd)) {
4296
4342
  process.stderr.write(
4297
- '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> [--from-store] (bring a cloud doc back to disk; --from-store accepts the server copy when the hub is unreadable)\n inplan asset-upload <file> --bytes-file <path> [--ext <ext>] (cloud doc: paste/pick an image straight to storage)\n inplan login (opens the browser to sign in; or --url <url> --anon <key> --refresh <token> for scripts)\n inplan whoami | logout\n'
4343
+ '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> [--from-store] (bring a cloud doc back to disk; --from-store accepts the server copy when the hub is unreadable)\n inplan asset-upload <file|--remote DOC_ID> --bytes-file <path> [--ext <ext>] (cloud doc: paste/pick an image straight to storage)\n inplan login (opens the browser to sign in; or --url <url> --anon <key> --refresh <token> for scripts)\n inplan whoami | logout\n'
4298
4344
  );
4299
4345
  process.exit(64);
4300
4346
  }
@@ -4305,6 +4351,10 @@ async function main() {
4305
4351
  const remoteDocId = getFlag(args, "remote");
4306
4352
  if (remoteDocId) {
4307
4353
  rejectCommentOnCloud(cmd, false);
4354
+ if (cmd === "asset-upload") {
4355
+ await doAssetUploadForDoc(remoteDocId, args);
4356
+ return;
4357
+ }
4308
4358
  const remoteCmd = cmd === "open" ? "wait" : cmd;
4309
4359
  if (cmd === "open") {
4310
4360
  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");
@@ -4490,11 +4540,13 @@ export {
4490
4540
  activeDocForCwd,
4491
4541
  canInteractiveLogin,
4492
4542
  doAssetUpload,
4543
+ doAssetUploadForDoc,
4493
4544
  doUpload,
4494
4545
  ensureLoggedIn,
4495
4546
  exitAfterFlush,
4496
4547
  explainNoGate,
4497
4548
  isKnownAgentEnv,
4549
+ main,
4498
4550
  notesFromHook,
4499
4551
  primeSessionOrFail,
4500
4552
  resolveWaitStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inplan",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
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
@@ -196,6 +196,28 @@ anchored comment is an inline Markdown link whose href is the comment id:
196
196
  mechanism itself and is fine — this is about the surrounding prose.) The body should read as
197
197
  a complete document with every comment stripped out.
198
198
 
199
+ ### Images
200
+
201
+ A plan can carry images, but **the bytes have to reach the document's own storage first** —
202
+ a filename, a local path, or a `scratchpad/` reference renders as a broken image for the
203
+ human, who has no access to your filesystem. Upload, then reference what the upload prints:
204
+
205
+ $ inplan asset-upload --remote <docId> --bytes-file ./shot.png --ext png
206
+ {"status":"uploaded","relPath":"https://…/doc-images/<org>/<doc>/image-….png"}
207
+
208
+ then put that `relPath` in a normal Markdown image: `![what it shows](<relPath>)`. Use
209
+ `inplan asset-upload <file> …` for a local plan promoted to the cloud (its doc id comes from
210
+ the status sidecar), and the `--remote <docId>` form for a doc you attached to by id. Both
211
+ upload as **you** — the signed-in session is the authorization, so there is no key to find
212
+ and nothing to configure beyond `inplan login`.
213
+
214
+ For a purely local plan, images live next to the file in `<docname>.assets/` and a relative
215
+ link resolves; nothing needs uploading.
216
+
217
+ Write the image reference in the same edit that adds the surrounding prose. Do not leave a
218
+ placeholder for the human to fill in later — attaching images is not a human-only step, and a
219
+ body full of bare filenames is the failure this section exists to prevent.
220
+
199
221
  ## Turn-taking & control — read this first
200
222
 
201
223
  This is **turn-based**. The turn belongs to exactly one party at a time: