dsh-open-artifact 0.15.0 → 0.16.1

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/CHANGELOG.md CHANGED
@@ -1,11 +1,45 @@
1
1
  # Changelog
2
2
 
3
- Every release of Open Artifact: the `@open-artifact/*` libraries, `@open-artifact/cli`, `dsh-open-artifact` and the
4
- agent plugins. Since 0.9.0 they all share one version; before that `dsh-open-artifact` had its own (noted per release).
3
+ Every release of Open Artifact: the `@open-artifact/*` libraries, `@open-artifact/cli`, `dsh-open-artifact`,
4
+ `pi-open-artifact` and the agent plugins. Since 0.9.0 they all share one version; before that `dsh-open-artifact` had its own (noted per release).
5
5
 
6
6
  Each entry is written from the commits since the previous tag (`node scripts/changelog.mjs` lists them); see
7
7
  [Releasing](README.md#releasing).
8
8
 
9
+ ## [0.16.1] - 2026-11-25
10
+
11
+ Keep an agent that runs in a sandbox to its session's workspace, even though the daemon runs with your full rights.
12
+
13
+ ### Added
14
+
15
+ - A daemon started with `OPEN_ARTIFACT_WORKSPACE_FOLDERS_ONLY=1` works only inside the calling session's workspace: making, reading and listing artifacts, ArtifactData's `file_path` and `out_file`, file paths in type actions (an upload's `file`, docs import and export), and artifact pages and archives. Anything outside answers `not_granted`. A symbolic link out of the workspace, or a workspace folder replaced by another, is refused too. Without the variable nothing changes.
16
+ - A write refused because `if_match` no longer matches says `executionStatus: "not_executed"`, so an agent knows nothing was written.
17
+
18
+ ### Fixed
19
+
20
+ - On macOS, a workspace under `/var` or `/tmp` is recognised when its path is spelled through the system's link to `/private`.
21
+
22
+ ### Integrators
23
+
24
+ - `startDaemon({ workspaceFoldersOnly: true })` turns on the same confinement as the environment variable, for apps that run their agents in a sandbox. Each call is checked against the workspace the session gave (`caller.workspace`); a session without one cannot make or open artifacts there. A listing shows only artifacts inside that workspace, `scope: "all"` included. See "A sandboxed agent: workspace folders only" in the integrator guide's security page. Nothing in the Harness API messages, `harness-kit` or the Shell changed.
25
+
26
+ ## [0.16.0] - 2026-11-25
27
+
28
+ Make artifacts from Pi, and install an artifact as an app of its own from Open Artifact Desktop.
29
+
30
+ ### Added
31
+
32
+ - Pi support: `pi install npm:pi-open-artifact` gives Pi the Artifact, ArtifactData and ArtifactComments tools, the `open-artifact` skill and `/open-artifact <type> <what to make>`. Comments and requests from a page reach the Pi session that made the artifact: your own words as a message from you, a collaborator's comment or a background task's result as a separate note the model reads. Pages show whether Pi is working, and follow the files Pi's own write and edit tools change.
33
+ - Open Artifact Desktop can install an artifact as an app of its own, from a card, a sidebar row, a tab's menu or the File menu. The app opens that one artifact in its own window and hands everything else to the desktop app. Installed apps can be uninstalled, repaired, and are refreshed when the desktop app changes.
34
+
35
+ ### Fixed
36
+
37
+ - Desktop restarts a daemon running from an installed app before that app is moved or removed, and at start restarts only a daemon whose installed app is gone.
38
+
39
+ ### Integrators
40
+
41
+ - A shipped harness profile for Pi (`pi`, L3 over the Harness API, session variable `PI_SESSION_ID`, markers `PI_CODING_AGENT` and `PI_SESSION_ID`). `plugins/pi` is a second full adapter on `@open-artifact/harness-kit`, alongside DeepSeek Harness, and reports its profile in `hello` so a daemon without the shipped file knows it too. Nothing in the Harness API, the kit or the Shell changed.
42
+
9
43
  ## [0.15.0] - 2026-11-25
10
44
 
11
45
  Create free HTML pages and custom artifact types, publish them on sites, and work with artifacts in the new Open Artifact Desktop app.
@@ -625,6 +659,8 @@ One version for every package, with Docs and Sheets in every plugin.
625
659
  - Plugins for Claude Code, Codex, Cursor, Copilot, ChatGPT and DeepSeek Harness.
626
660
  - English and Chinese READMEs, under Apache-2.0.
627
661
 
662
+ [0.16.1]: https://github.com/JimLiu/open-artifact/compare/v0.16.0...v0.16.1
663
+ [0.16.0]: https://github.com/JimLiu/open-artifact/compare/v0.15.0...v0.16.0
628
664
  [0.15.0]: https://github.com/JimLiu/open-artifact/compare/v0.14.7...v0.15.0
629
665
  [0.14.7]: https://github.com/JimLiu/open-artifact/compare/v0.14.6...v0.14.7
630
666
  [0.14.6]: https://github.com/JimLiu/open-artifact/compare/v0.14.5...v0.14.6
package/lib/client.js CHANGED
@@ -1,4 +1,4 @@
1
- // dsh-open-artifact 0.15.0: the DSH plugin (browser half). Built by scripts/build.mjs; do not edit.
1
+ // dsh-open-artifact 0.16.1: the DSH plugin (browser half). Built by scripts/build.mjs; do not edit.
2
2
  window.__ModuleLoader__.load({
3
3
  id: "dsh-open-artifact",
4
4
  factory: (require) => {
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // dsh-open-artifact 0.15.0: the DSH plugin (server half). Built by scripts/build.mjs; do not edit.
1
+ // dsh-open-artifact 0.16.1: the DSH plugin (server half). Built by scripts/build.mjs; do not edit.
2
2
 
3
3
  // packages/harness-kit/src/daemon.ts
4
4
  import { spawn } from "node:child_process";
@@ -723,7 +723,10 @@ var LATER_ITEMS = [
723
723
  \`changed\`, \`read\` lists the files they touched in \`changed_files\`, and \`notes\` say so: read those files again
724
724
  before writing. When you write through the tools, pass the \`sha256\` you read as \`if_match\`
725
725
  (\`Artifact {action: "publish", url, files, if_match}\`; \`ArtifactData\` \`set\` and \`delete\` of an existing document
726
- need it). On a \`conflict\`, merge your change into \`current\` and write again.`,
726
+ need it). On a \`conflict\`, merge your change into \`current\` and write again; \`executionStatus: "not_executed"\` on
727
+ it means nothing was written.`,
728
+ `Some apps keep you to your workspace: there a folder or a file path outside it (an action's \`file\` or \`out\`,
729
+ ArtifactData's \`file_path\` or \`out_file\`) answers \`not_granted\`. Use a path inside the workspace instead.`,
727
730
  `To share it, \`Artifact {action: "open", url, panel: "share"}\` opens its Share panel for the person; to export
728
731
  (PDF, PPTX, PNG, …), \`panel: "export"\`. Only the person changes how an artifact is shared; never make share links
729
732
  yourself.`,
@@ -1663,7 +1666,7 @@ import { join as join3, resolve as resolve3 } from "node:path";
1663
1666
  // packages/harness-kit/package.json
1664
1667
  var package_default = {
1665
1668
  name: "@open-artifact/harness-kit",
1666
- version: "0.15.0",
1669
+ version: "0.16.1",
1667
1670
  private: true,
1668
1671
  type: "module",
1669
1672
  description: "The SDK an agent app uses to integrate Open Artifact: find or start the local daemon, hold a Harness API connection that reconnects, register the tools, take comment wakes and page opens, and follow the artifacts its sessions make.",
@@ -1673,7 +1676,7 @@ var package_default = {
1673
1676
  "./embed": "./src/embed/index.ts"
1674
1677
  },
1675
1678
  dependencies: {
1676
- "@open-artifact/protocol": "0.15.0"
1679
+ "@open-artifact/protocol": "0.16.1"
1677
1680
  },
1678
1681
  sideEffects: false,
1679
1682
  engines: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-open-artifact",
3
- "version": "0.15.0",
3
+ "version": "0.16.1",
4
4
  "description": "Open Artifact in DeepSeek Harness: the Artifact, ArtifactData and ArtifactComments tools, comments on artifact pages waking the session that owns them, the Open Artifact page in the sidebar listing the open-artifact library, artifacts the agent opens shown in the session's Browser, and /open-artifact <type> to make a new one.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -2,8 +2,8 @@
2
2
  name: open-artifact
3
3
  description: Make an Open Artifact (a slide deck, a design canvas, a whiteboard, a data dashboard, a doc, a short animated motion piece, …) as a folder of files that opens as a live local page where the person views, edits, comments and exports, with their comments coming back to you. Use when the person types `/open-artifact <type> <what to make>`, or asks for something they will look at closely, keep, change, comment on or present - a presentation, pitch or talk deck; app screens, a mockup, a landing page, a poster, flyer or graphic, or "a few options" to look at; a brainstorm or retro board, a flowchart or an architecture sketch; a dashboard, metrics page, KPI tracker or recurring report from their data; a document, report, proposal, plan, spec, memo, notes or other writing to keep, share or comment on; a short animated video, an explainer, a promo, motion graphics or a GIF; a widget or mini game - or asks to keep or share a diagram you drew. Not for answers read once, code, or a file in a format they named.
4
4
  argument-hint: <type> <what to make>
5
- generated-by: open-artifact 0.15.0
6
- etag: 30fac07afafeef8b
5
+ generated-by: open-artifact 0.16.1
6
+ etag: 4cfb8f99d733de16
7
7
  ---
8
8
 
9
9
  # Make an artifact: `/open-artifact <type> <what to make>`
@@ -162,7 +162,10 @@ beyond it (running commands, sending things, opening links).
162
162
  `changed`, `read` lists the files they touched in `changed_files`, and `notes` say so: read those files again
163
163
  before writing. When you write through the tools, pass the `sha256` you read as `if_match`
164
164
  (`Artifact {action: "publish", url, files, if_match}`; `ArtifactData` `set` and `delete` of an existing document
165
- need it). On a `conflict`, merge your change into `current` and write again.
165
+ need it). On a `conflict`, merge your change into `current` and write again; `executionStatus: "not_executed"` on
166
+ it means nothing was written.
167
+ - Some apps keep you to your workspace: there a folder or a file path outside it (an action's `file` or `out`,
168
+ ArtifactData's `file_path` or `out_file`) answers `not_granted`. Use a path inside the workspace instead.
166
169
  - To share it, `Artifact {action: "open", url, panel: "share"}` opens its Share panel for the person; to export
167
170
  (PDF, PPTX, PNG, …), `panel: "export"`. Only the person changes how an artifact is shared; never make share links
168
171
  yourself.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // packages/server-sdk/bin/frame-host.ts
4
- import { basename as basename4, resolve as resolve6 } from "node:path";
4
+ import { basename as basename5, resolve as resolve7 } from "node:path";
5
5
 
6
6
  // packages/server-sdk/src/frame/core.ts
7
7
  import { randomBytes as randomBytes4 } from "node:crypto";
@@ -842,12 +842,12 @@ var Parser = class {
842
842
  const value = this.value();
843
843
  if (key !== "__proto__") Object.defineProperty(out, key, { value, enumerable: true, configurable: true, writable: true });
844
844
  this.skip();
845
- const sep4 = s[this.i];
846
- if (sep4 === ",") {
845
+ const sep5 = s[this.i];
846
+ if (sep5 === ",") {
847
847
  this.i++;
848
848
  continue;
849
849
  }
850
- if (sep4 === "}") continue;
850
+ if (sep5 === "}") continue;
851
851
  this.fail(`\`,\` or \`}\` is expected, not ${this.describe()}`);
852
852
  }
853
853
  }
@@ -876,12 +876,12 @@ var Parser = class {
876
876
  if (c === "." && s.startsWith("...", this.i)) this.fail("A spread is not literal data");
877
877
  out.push(this.value());
878
878
  this.skip();
879
- const sep4 = s[this.i];
880
- if (sep4 === ",") {
879
+ const sep5 = s[this.i];
880
+ if (sep5 === ",") {
881
881
  this.i++;
882
882
  continue;
883
883
  }
884
- if (sep4 === "]") continue;
884
+ if (sep5 === "]") continue;
885
885
  this.fail(`\`,\` or \`]\` is expected, not ${this.describe()}`);
886
886
  }
887
887
  }
@@ -1081,8 +1081,8 @@ function cleanPath(p) {
1081
1081
  }
1082
1082
  function writeAtomic(file, data) {
1083
1083
  mkdirSync(dirname(file), { recursive: true });
1084
- const tmp = join(dirname(file), `.${basename(file)}.${randomBytes(4).toString("hex")}.tmp`);
1085
- writeFileSync(tmp, data);
1084
+ const tmp = join(dirname(file), `.${basename(file)}.${randomBytes(8).toString("hex")}.tmp`);
1085
+ writeFileSync(tmp, data, { flag: "wx" });
1086
1086
  renameSync(tmp, file);
1087
1087
  }
1088
1088
  var FileStore = class {
@@ -1348,6 +1348,11 @@ var CommentStore = class {
1348
1348
  this.guard = options.guard ?? LINK_GUARD;
1349
1349
  if (this.lock === "process") rmSync2(`${this.file}.lock`, { force: true });
1350
1350
  }
1351
+ /** The file's text as it is on disk (history compares it); throws when there is none or it leads out of the folder. */
1352
+ readText() {
1353
+ if (!this.guard.inside(this.root, this.file)) throw new FrameError("read_only_path", `${COMMENTS_FILE} leads out of the artifact folder (a link).`, 403);
1354
+ return readFileSync2(this.file, "utf8");
1355
+ }
1351
1356
  load() {
1352
1357
  try {
1353
1358
  if (!this.guard.inside(this.root, this.file)) return { version: 1, threads: [] };
@@ -1421,7 +1426,7 @@ var CommentStore = class {
1421
1426
  if (doc.threads.length || existsSync2(this.file)) {
1422
1427
  const tmp = join2(this.root, `.${COMMENTS_FILE}.${randomBytes2(4).toString("hex")}.tmp`);
1423
1428
  writeFileSync2(tmp, `${JSON.stringify({ version: 1, threads: doc.threads }, null, 2)}
1424
- `);
1429
+ `, { flag: "wx" });
1425
1430
  renameSync2(tmp, this.file);
1426
1431
  }
1427
1432
  return out;
@@ -1446,7 +1451,7 @@ var CommentStore = class {
1446
1451
  return thread;
1447
1452
  });
1448
1453
  }
1449
- addMessage(threadId2, author, text, { resolve: resolve7 = false, to } = {}) {
1454
+ addMessage(threadId2, author, text, { resolve: resolve8 = false, to } = {}) {
1450
1455
  const body = checkText(text);
1451
1456
  const recipients = checkTo(to);
1452
1457
  return this.mutate((doc) => {
@@ -1459,7 +1464,7 @@ var CommentStore = class {
1459
1464
  if (thread.agent?.unaskedAt) message.joined = true;
1460
1465
  const { unaskedAt: _answered, ...agent } = thread.agent ?? { status: "replied" };
1461
1466
  thread.agent = { ...agent, status: "replied", repliedAt: at };
1462
- if (resolve7) setStatus(thread, "resolved", at, author);
1467
+ if (resolve8) setStatus(thread, "resolved", at, author);
1463
1468
  } else if (thread.status === "resolved") {
1464
1469
  setStatus(thread, "open", at);
1465
1470
  }
@@ -1904,12 +1909,21 @@ var DbStore = class extends EventEmitter {
1904
1909
  dir;
1905
1910
  leases = /* @__PURE__ */ new Map();
1906
1911
  guard;
1907
- /** `guard`: how it keeps inside the artifact folder (default {@link LINK_GUARD}: links followed). */
1912
+ imports;
1913
+ /**
1914
+ * `guard`: how it keeps inside the artifact folder (default {@link LINK_GUARD}: links followed). `imports`: where a
1915
+ * write's `file_path` may be read from (it checks the path, or throws); none: anywhere.
1916
+ */
1908
1917
  constructor(root, options = {}) {
1909
1918
  super();
1910
1919
  this.root = root;
1911
1920
  this.dir = join3(root, DB_DIR);
1912
1921
  this.guard = options.guard ?? LINK_GUARD;
1922
+ this.imports = options.imports;
1923
+ }
1924
+ /** The bytes of a document's file as they are on disk (history and validation compare them); throws when it has none. */
1925
+ readDocumentFile(p) {
1926
+ return readFileSync3(this.fileOf(splitPath(p, "doc")), "utf8");
1913
1927
  }
1914
1928
  /** A document's file; refused when a link (db/ itself, or a folder in it) leads it out of the artifact folder. */
1915
1929
  fileOf(segs) {
@@ -2139,8 +2153,14 @@ var DbStore = class extends EventEmitter {
2139
2153
  let data = w.data;
2140
2154
  if (hasFile) {
2141
2155
  if (!isAbsolute(w.file_path)) throw dbError("invalid_argument", "file_path is an absolute path.");
2156
+ let file;
2142
2157
  try {
2143
- data = JSON.parse(readFileSync3(w.file_path, "utf8"));
2158
+ file = this.imports ? this.imports.resolve(w.file_path) : w.file_path;
2159
+ } catch {
2160
+ throw dbError("not_granted", `${w.file_path} is outside the artifact's workspace.`);
2161
+ }
2162
+ try {
2163
+ data = JSON.parse(readFileSync3(file, "utf8"));
2144
2164
  } catch (error) {
2145
2165
  throw dbError("invalid_argument", `${w.file_path}: ${error?.message ?? error}`);
2146
2166
  }
@@ -2311,7 +2331,7 @@ var FrameCore = class _FrameCore {
2311
2331
  );
2312
2332
  }
2313
2333
  const guard = { guard: env.guard };
2314
- this.db = new DbStore(root, guard);
2334
+ this.db = new DbStore(root, { ...guard, imports: env.imports });
2315
2335
  this.comments = new CommentStore(root, guard);
2316
2336
  this.files = new FileStore(root, { ownIndex: this.pageMode, ...guard });
2317
2337
  this.blobs = new BlobStore(root, guard);
@@ -3711,6 +3731,7 @@ function localFrameEnv(root, ctx, options, type = localTypeSource(options.typeDi
3711
3731
  allowedNetworkOrigins: options.allowedNetworkOrigins,
3712
3732
  page: page2,
3713
3733
  guard: LINK_GUARD,
3734
+ imports: ctx.workspace,
3714
3735
  debug: () => !!process.env.OPEN_ARTIFACT_FRAME_DEBUG,
3715
3736
  daemon: ctx.daemon,
3716
3737
  agentHook: ctx.agentHook,
@@ -4143,14 +4164,103 @@ var snapshotAction = {
4143
4164
  var localFrameActions = { ...frameActions, snapshot: snapshotAction };
4144
4165
 
4145
4166
  // packages/server-sdk/src/serve.ts
4146
- import { randomBytes as randomBytes6 } from "node:crypto";
4167
+ import { randomBytes as randomBytes7 } from "node:crypto";
4147
4168
  import { EventEmitter as EventEmitter2 } from "node:events";
4148
- import { appendFileSync, existsSync as existsSync6, readFileSync as readFileSync8, rmSync as rmSync6, writeFileSync as writeFileSync4 } from "node:fs";
4169
+ import { appendFileSync, existsSync as existsSync6, readFileSync as readFileSync9, rmSync as rmSync6, writeFileSync as writeFileSync5 } from "node:fs";
4149
4170
  import { createServer as createServer2 } from "node:http";
4150
4171
  import { hostname as hostname2 } from "node:os";
4151
- import { basename as basename3, isAbsolute as isAbsolute2, join as join10, resolve as resolve5 } from "node:path";
4172
+ import { basename as basename4, isAbsolute as isAbsolute3, join as join11, resolve as resolve6 } from "node:path";
4152
4173
  import { threadId } from "node:worker_threads";
4153
4174
 
4175
+ // packages/protocol/src/workspace-files.ts
4176
+ import { randomBytes as randomBytes6 } from "node:crypto";
4177
+ import { lstatSync as lstatSync2, readFileSync as readFileSync8, realpathSync as realpathSync2, renameSync as renameSync3, statSync as statSync6, unlinkSync, writeFileSync as writeFileSync4 } from "node:fs";
4178
+ import { basename as basename2, dirname as dirname3, isAbsolute as isAbsolute2, join as join9, relative, resolve as resolve4, sep as sep3 } from "node:path";
4179
+ function includesPath(root, target) {
4180
+ const path = relative(root, target);
4181
+ return path !== ".." && !path.startsWith(".." + sep3) && !isAbsolute2(path);
4182
+ }
4183
+ var forbidden = () => new OpenArtifactError("not_granted", "File is outside the authorized workspace.", { status: 403 });
4184
+ var WorkspaceDirectory = class {
4185
+ root;
4186
+ givenRoot;
4187
+ device;
4188
+ inode;
4189
+ constructor(root, identity) {
4190
+ this.givenRoot = resolve4(root);
4191
+ this.root = realpathSync2(this.givenRoot);
4192
+ const stat2 = statSync6(this.root, { bigint: true });
4193
+ if (!stat2.isDirectory()) throw forbidden();
4194
+ this.device = stat2.dev;
4195
+ this.inode = stat2.ino;
4196
+ if (identity && (identity.root !== this.root || identity.device !== this.device.toString() || identity.inode !== this.inode.toString())) throw forbidden();
4197
+ }
4198
+ get identity() {
4199
+ return { root: this.root, device: this.device.toString(), inode: this.inode.toString() };
4200
+ }
4201
+ /** Read optional metadata from a checked file. */
4202
+ readJson(input, fallback) {
4203
+ try {
4204
+ return JSON.parse(readFileSync8(this.resolve(input), "utf8"));
4205
+ } catch {
4206
+ return fallback;
4207
+ }
4208
+ }
4209
+ /** Atomically replace a metadata entry inside this directory. */
4210
+ writeJson(input, value, mode) {
4211
+ const file = this.resolve(input, false);
4212
+ const tmp = `${file}.${randomBytes6(8).toString("hex")}.tmp`;
4213
+ writeFileSync4(tmp, `${JSON.stringify(value, null, 2)}
4214
+ `, { flag: "wx", ...mode === void 0 ? {} : { mode } });
4215
+ try {
4216
+ renameSync3(tmp, file);
4217
+ } catch (error) {
4218
+ try {
4219
+ unlinkSync(tmp);
4220
+ } catch {
4221
+ }
4222
+ throw error;
4223
+ }
4224
+ }
4225
+ /**
4226
+ * Check both the directory identity and the path. New files inherit the nearest existing parent's boundary. A path
4227
+ * spelled through a link to the workspace (macOS's `/var` for `/private/var`) is judged by where it really leads.
4228
+ */
4229
+ resolve(input, followLeaf = true) {
4230
+ const directory = lstatSync2(this.root, { bigint: true });
4231
+ if (!directory.isDirectory() || directory.dev !== this.device || directory.ino !== this.inode) throw forbidden();
4232
+ const path = resolve4(this.givenRoot, input);
4233
+ const target = includesPath(this.givenRoot, path) ? resolve4(this.root, relative(this.givenRoot, path)) : path;
4234
+ const outside = !includesPath(this.root, target);
4235
+ const tail = [];
4236
+ let ancestor = target;
4237
+ if (!followLeaf && target !== this.root) {
4238
+ tail.push(basename2(target));
4239
+ ancestor = dirname3(target);
4240
+ }
4241
+ let real;
4242
+ try {
4243
+ for (; ; ) {
4244
+ try {
4245
+ lstatSync2(ancestor);
4246
+ break;
4247
+ } catch (error) {
4248
+ if (error.code !== "ENOENT" || ancestor === this.root || dirname3(ancestor) === ancestor) throw error;
4249
+ tail.unshift(basename2(ancestor));
4250
+ ancestor = dirname3(ancestor);
4251
+ }
4252
+ }
4253
+ real = realpathSync2(ancestor);
4254
+ } catch (error) {
4255
+ if (outside) throw forbidden();
4256
+ throw error;
4257
+ }
4258
+ const actual = join9(real, ...tail);
4259
+ if (!includesPath(this.root, actual)) throw forbidden();
4260
+ return actual;
4261
+ }
4262
+ };
4263
+
4154
4264
  // packages/server-sdk/src/daemon.ts
4155
4265
  var TypeApi = class {
4156
4266
  /** Base URL of the daemon without a trailing slash, or `null` when standalone. */
@@ -4309,11 +4419,11 @@ function lanAddresses(interfaces = networkInterfaces()) {
4309
4419
  }
4310
4420
  var NO_ANSWER = /* @__PURE__ */ new Set(["ECONNREFUSED", "EADDRNOTAVAIL", "EAFNOSUPPORT", "ENETUNREACH", "EHOSTUNREACH", "EACCES", "EPERM"]);
4311
4421
  function answers(host, port) {
4312
- return new Promise((resolve7) => {
4422
+ return new Promise((resolve8) => {
4313
4423
  const socket = connect({ host, port });
4314
4424
  const done = (taken) => {
4315
4425
  socket.destroy();
4316
- resolve7(taken);
4426
+ resolve8(taken);
4317
4427
  };
4318
4428
  socket.setTimeout(300, () => done(false));
4319
4429
  socket.once("connect", () => done(true));
@@ -4324,23 +4434,23 @@ async function answersAnyPort(address) {
4324
4434
  const server = createServer();
4325
4435
  let port = 0;
4326
4436
  try {
4327
- port = await new Promise((resolve7, reject) => {
4437
+ port = await new Promise((resolve8, reject) => {
4328
4438
  server.once("error", reject);
4329
- server.listen(0, address, () => resolve7(server.address()?.port ?? 0));
4439
+ server.listen(0, address, () => resolve8(server.address()?.port ?? 0));
4330
4440
  });
4331
4441
  } catch {
4332
4442
  return false;
4333
4443
  } finally {
4334
- await new Promise((resolve7) => server.close(() => resolve7()));
4444
+ await new Promise((resolve8) => server.close(() => resolve8()));
4335
4445
  }
4336
4446
  return port > 0 && answers(address, port);
4337
4447
  }
4338
4448
  function listen(server, port, host) {
4339
- return new Promise((resolve7, reject) => {
4449
+ return new Promise((resolve8, reject) => {
4340
4450
  server.once("error", reject);
4341
4451
  server.listen(port, host, () => {
4342
4452
  server.off("error", reject);
4343
- resolve7();
4453
+ resolve8();
4344
4454
  });
4345
4455
  });
4346
4456
  }
@@ -4581,7 +4691,7 @@ var WebSocketConnection = class {
4581
4691
  // packages/server-sdk/src/zip.ts
4582
4692
  import { constants } from "node:fs";
4583
4693
  import { lstat, mkdir, open, readdir, readFile, rename, rm, stat } from "node:fs/promises";
4584
- import { basename as basename2, dirname as dirname3, extname as extname2, join as join9, resolve as resolve4, sep as sep3 } from "node:path";
4694
+ import { basename as basename3, dirname as dirname4, extname as extname2, join as join10, resolve as resolve5, sep as sep4 } from "node:path";
4585
4695
  import { promisify } from "node:util";
4586
4696
  import { deflateRaw as deflateRawCallback, inflateRaw as inflateRawCallback, inflateRawSync } from "node:zlib";
4587
4697
  var inflateRaw = promisify(inflateRawCallback);
@@ -4601,9 +4711,9 @@ var ArchiveTooLarge = class extends Error {
4601
4711
  code = "TOO_LARGE";
4602
4712
  };
4603
4713
  async function archiveEntries(root, skip = []) {
4604
- const top = resolve4(root);
4605
- const folder = basename2(top) || "artifact";
4606
- const skipped = new Set(skip.map((file) => resolve4(file)));
4714
+ const top = resolve5(root);
4715
+ const folder = basename3(top) || "artifact";
4716
+ const skipped = new Set(skip.map((file) => resolve5(file)));
4607
4717
  const entries = [];
4608
4718
  const walk = async (dir2, rel) => {
4609
4719
  let names;
@@ -4617,7 +4727,7 @@ async function archiveEntries(root, skip = []) {
4617
4727
  const name = dirent.name;
4618
4728
  const inner = rel ? `${rel}/${name}` : name;
4619
4729
  if (!keepsStep(rel, name, inner)) continue;
4620
- const file = join9(dir2, name);
4730
+ const file = join10(dir2, name);
4621
4731
  if (skipped.has(file)) continue;
4622
4732
  if (dirent.isDirectory()) await walk(file, inner);
4623
4733
  else if (dirent.isFile()) {
@@ -4731,7 +4841,7 @@ async function writeZip(entries, write) {
4731
4841
  }
4732
4842
  function archiveFileName(root, now2 = /* @__PURE__ */ new Date()) {
4733
4843
  const day = `${now2.getFullYear()}-${String(now2.getMonth() + 1).padStart(2, "0")}-${String(now2.getDate()).padStart(2, "0")}`;
4734
- return `${basename2(resolve4(root)) || "artifact"}-${day}.zip`;
4844
+ return `${basename3(resolve5(root)) || "artifact"}-${day}.zip`;
4735
4845
  }
4736
4846
  function attachmentHeader(name) {
4737
4847
  const ascii = name.replace(/[^\x20-\x7e]|["\\]/g, "_");
@@ -4904,7 +5014,7 @@ var StreamResponse = class extends EventEmitter2 {
4904
5014
  function typeManifest(dir2 = process.env.OPEN_ARTIFACT_TYPE_DIR) {
4905
5015
  if (!dir2) return {};
4906
5016
  try {
4907
- const value = JSON.parse(readFileSync8(join10(dir2, "artifact-type.json"), "utf8"));
5017
+ const value = JSON.parse(readFileSync9(join11(dir2, "artifact-type.json"), "utf8"));
4908
5018
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
4909
5019
  } catch {
4910
5020
  return {};
@@ -5039,11 +5149,14 @@ var TypeServer = class {
5039
5149
  async open(request) {
5040
5150
  const { id, root, title } = request;
5041
5151
  if (typeof id !== "string" || !/^[A-Za-z0-9_-]{1,64}$/.test(id)) throw new OpenArtifactError("invalid_argument", "open needs an artifact id.", { status: 400 });
5042
- if (typeof root !== "string" || !isAbsolute2(root)) {
5152
+ if (typeof root !== "string" || !isAbsolute3(root)) {
5043
5153
  throw new OpenArtifactError("invalid_argument", "open needs the artifact root (an absolute path).", { status: 400 });
5044
5154
  }
5045
5155
  const have = this.byId.get(id);
5046
- if (have && have.root === resolve5(root)) {
5156
+ const identity = request.workspaceDirectory;
5157
+ const workspace = identity ? new WorkspaceDirectory(identity.root, identity) : have?.workspace;
5158
+ const target = workspace?.resolve(root) ?? resolve6(root);
5159
+ if (have && have.root === target && have.workspace?.root === workspace?.root) {
5047
5160
  have.lastUsed = Date.now();
5048
5161
  if (title) have.title = title;
5049
5162
  return have;
@@ -5051,16 +5164,16 @@ var TypeServer = class {
5051
5164
  if (have) this.unmount(id);
5052
5165
  const busy = this.mounting.get(id);
5053
5166
  if (busy) return busy;
5054
- const work = this.mount(id, resolve5(root), title).finally(() => this.mounting.delete(id));
5167
+ const work = this.mount(id, target, title, workspace).finally(() => this.mounting.delete(id));
5055
5168
  this.mounting.set(id, work);
5056
5169
  return work;
5057
5170
  }
5058
- async mount(id, root, title) {
5171
+ async mount(id, root, title, workspace) {
5059
5172
  if (!existsSync6(root)) throw new OpenArtifactError("not_found", `The folder ${root} is gone.`, { status: 404 });
5060
- const logFile = join10(root, LOG_FILE);
5173
+ const logPath = join11(root, LOG_FILE);
5061
5174
  const log = (line) => {
5062
5175
  try {
5063
- appendFileSync(logFile, `[${(/* @__PURE__ */ new Date()).toISOString()}] ${line}
5176
+ appendFileSync(workspace ? new WorkspaceDirectory(workspace.resolve(root)).resolve(logPath) : logPath, `[${(/* @__PURE__ */ new Date()).toISOString()}] ${line}
5064
5177
  `);
5065
5178
  } catch {
5066
5179
  }
@@ -5085,6 +5198,7 @@ var TypeServer = class {
5085
5198
  const site = await this.options.mountSite(root, {
5086
5199
  id,
5087
5200
  title: title ?? "",
5201
+ workspace,
5088
5202
  daemon: this.daemon,
5089
5203
  log,
5090
5204
  network: this.lan.network,
@@ -5102,7 +5216,7 @@ var TypeServer = class {
5102
5216
  site.close();
5103
5217
  throw new OpenArtifactError("conflict", `${other.root} is already open at ${site.page}.`, { status: 409 });
5104
5218
  }
5105
- const entry = { id, root, title: title ?? "", site, page: site.page, streams: 0, lastUsed: Date.now() };
5219
+ const entry = { id, root, title: title ?? "", site, page: site.page, workspace, streams: 0, lastUsed: Date.now() };
5106
5220
  this.byId.set(id, entry);
5107
5221
  this.byPage.set(site.page, entry);
5108
5222
  try {
@@ -5122,7 +5236,7 @@ var TypeServer = class {
5122
5236
  startedAt: (/* @__PURE__ */ new Date()).toISOString(),
5123
5237
  openArtifact: id
5124
5238
  };
5125
- writeFileSync4(join10(root, STATE_FILE), `${JSON.stringify(record, null, 2)}
5239
+ writeFileSync5(join11(root, STATE_FILE), `${JSON.stringify(record, null, 2)}
5126
5240
  `);
5127
5241
  } catch {
5128
5242
  }
@@ -5137,8 +5251,8 @@ var TypeServer = class {
5137
5251
  this.byId.delete(id);
5138
5252
  this.byPage.delete(entry.page);
5139
5253
  try {
5140
- const file = join10(entry.root, STATE_FILE);
5141
- const state = JSON.parse(readFileSync8(file, "utf8"));
5254
+ const file = join11(entry.root, STATE_FILE);
5255
+ const state = JSON.parse(readFileSync9(file, "utf8"));
5142
5256
  if (state.pid === process.pid && (state.thread ?? 0) === threadId) rmSync6(file, { force: true });
5143
5257
  } catch {
5144
5258
  }
@@ -5168,6 +5282,11 @@ var TypeServer = class {
5168
5282
  return null;
5169
5283
  }
5170
5284
  }
5285
+ requireAuthorized(entry) {
5286
+ if (entry.workspace && entry.workspace.resolve(entry.root) !== entry.root) {
5287
+ throw new OpenArtifactError("not_granted", "The authorized artifact directory changed.", { status: 403 });
5288
+ }
5289
+ }
5171
5290
  /** The site that answers a path outside every site's address: share links, uploads, common paths, the referrer. */
5172
5291
  async answering(req, pathname) {
5173
5292
  const link = /^\/s\/([A-Za-z0-9_-]{16,64})$/.exec(pathname);
@@ -5197,6 +5316,7 @@ var TypeServer = class {
5197
5316
  req.resume();
5198
5317
  return notFound(res);
5199
5318
  }
5319
+ this.requireAuthorized(content.entry);
5200
5320
  content.entry.lastUsed = Date.now();
5201
5321
  await site.content(req, res);
5202
5322
  return;
@@ -5208,6 +5328,7 @@ var TypeServer = class {
5208
5328
  async siteRequest(req, res, url) {
5209
5329
  const at = this.under(url.pathname);
5210
5330
  if (at) {
5331
+ this.requireAuthorized(at.entry);
5211
5332
  at.entry.lastUsed = Date.now();
5212
5333
  if (at.rest === "") {
5213
5334
  req.resume();
@@ -5220,6 +5341,7 @@ var TypeServer = class {
5220
5341
  }
5221
5342
  const entry = await this.answering(req, url.pathname);
5222
5343
  if (entry) {
5344
+ this.requireAuthorized(entry);
5223
5345
  entry.lastUsed = Date.now();
5224
5346
  await entry.site.handle(req, res);
5225
5347
  return;
@@ -5241,6 +5363,7 @@ var TypeServer = class {
5241
5363
  req.resume();
5242
5364
  return sendJson(res, 404, { code: "not_found", message: `${url.searchParams.get("id")} is not open here.`, fix: "Open it first (/__open-artifact/open)." });
5243
5365
  }
5366
+ this.requireAuthorized(entry);
5244
5367
  entry.lastUsed = Date.now();
5245
5368
  return sendArchive(req, res, entry.root);
5246
5369
  }
@@ -5249,6 +5372,7 @@ var TypeServer = class {
5249
5372
  const artifact = (id) => {
5250
5373
  const entry = this.byId.get(String(id ?? ""));
5251
5374
  if (!entry) throw new OpenArtifactError("not_found", `${String(id)} is not open here.`, { status: 404, fix: "Open it first (/__open-artifact/open)." });
5375
+ this.requireAuthorized(entry);
5252
5376
  entry.lastUsed = Date.now();
5253
5377
  return entry;
5254
5378
  };
@@ -5306,7 +5430,7 @@ var TypeServer = class {
5306
5430
  }
5307
5431
  /** Starts a long action and answers with its task; the end goes to the daemon (`open-artifact.type.task`). */
5308
5432
  runLong(name, action, ref, args) {
5309
- const task = `task_${randomBytes6(8).toString("hex")}`;
5433
+ const task = `task_${randomBytes7(8).toString("hex")}`;
5310
5434
  const report = (body) => this.daemon.task(task, body).then(
5311
5435
  () => void 0,
5312
5436
  (error) => this.log(`task ${task} (${name}): reporting failed: ${error instanceof Error ? error.message : String(error)}`)
@@ -5405,7 +5529,7 @@ async function serve(options) {
5405
5529
  }
5406
5530
 
5407
5531
  // packages/server-sdk/bin/frame-host.ts
5408
- var dir = resolve6(process.env.OPEN_ARTIFACT_TYPE_DIR ?? process.cwd());
5532
+ var dir = resolve7(process.env.OPEN_ARTIFACT_TYPE_DIR ?? process.cwd());
5409
5533
  var manifest = typeManifest(dir);
5410
5534
  var page = manifest.openArtifact?.style === "page";
5411
5535
  if (!page && !readDeclaration(dir)) {
@@ -5421,7 +5545,7 @@ await serve({
5421
5545
  // The core's actions and `snapshot` (this computer's headless Chrome): a hosted site serves `frameActions` alone.
5422
5546
  actions: localFrameActions,
5423
5547
  // The type id: the daemon passes it; by hand, the folder name (as the daemon would derive it).
5424
- type: process.env.OPEN_ARTIFACT_TYPE ?? basename4(dir),
5548
+ type: process.env.OPEN_ARTIFACT_TYPE ?? basename5(dir),
5425
5549
  version: manifest.version ?? "0",
5426
5550
  contentHosts: true,
5427
5551
  archive: true
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "pi",
3
+ "title": "Pi",
4
+ "agentName": "Pi",
5
+ "level": "L3",
6
+ "entry": "harness-api",
7
+ "plugin": "pi-open-artifact",
8
+ "sessionEnv": "PI_SESSION_ID",
9
+ "markers": [
10
+ "PI_CODING_AGENT",
11
+ "PI_SESSION_ID"
12
+ ],
13
+ "wake": [
14
+ "live",
15
+ "inbox"
16
+ ],
17
+ "open": "browser",
18
+ "caps": {
19
+ "tools": "native",
20
+ "commands": {
21
+ "names": [
22
+ "open-artifact"
23
+ ]
24
+ },
25
+ "wake": {
26
+ "resume": true
27
+ }
28
+ }
29
+ }