dsh-open-artifact 0.16.2 → 0.16.3

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/icon.svg +1 -1
  3. package/lib/client.js +2504 -2430
  4. package/lib/index.js +26 -8
  5. package/package.json +1 -1
  6. package/skills/open-artifact/SKILL.md +8 -5
  7. package/vendor/frame-host/client/comments.js +1 -1
  8. package/vendor/frame-host/frame-host.mjs +15 -2
  9. package/vendor/harnesses/antigravity.json +3 -0
  10. package/vendor/harnesses/chatgpt.json +3 -0
  11. package/vendor/harnesses/claude-code.json +3 -0
  12. package/vendor/harnesses/codex.json +3 -0
  13. package/vendor/harnesses/copilot.json +3 -0
  14. package/vendor/harnesses/cursor.json +3 -0
  15. package/vendor/harnesses/dsh.json +3 -0
  16. package/vendor/harnesses/zcode.json +3 -0
  17. package/vendor/home/assets/index-BMcfb5B7.css +1 -0
  18. package/vendor/home/assets/index-CxVzqoE0.js +43 -0
  19. package/vendor/home/index.html +2 -2
  20. package/vendor/open-artifact.mjs +1278 -456
  21. package/vendor/runtime.json +1 -1
  22. package/vendor/shell/assets/index-BMcfb5B7.css +1 -0
  23. package/vendor/{type-server/shell/assets/index-xloVcJb_.js → shell/assets/index-C_XsG-Qe.js} +1 -1
  24. package/vendor/shell/index.html +2 -2
  25. package/vendor/type-server/cli.mjs +16 -3
  26. package/vendor/type-server/editors/data/assets/{index-DcaVBiGm.js → index-CMhqwoHV.js} +1 -1
  27. package/vendor/type-server/editors/data/index.html +1 -1
  28. package/vendor/type-server/editors/design/assets/{index-B5Wv_tnf.js → index-DUW-k3ks.js} +1 -1
  29. package/vendor/type-server/editors/design/index.html +1 -1
  30. package/vendor/type-server/editors/design-system/assets/{index-BqDGbG4f.js → index-l9dVDF3y.js} +1 -1
  31. package/vendor/type-server/editors/design-system/index.html +1 -1
  32. package/vendor/type-server/editors/docs/assets/{abnfDiagram-WEYOIA3C-CDTl-yCx.js → abnfDiagram-WEYOIA3C-C7HiIlhQ.js} +1 -1
  33. package/vendor/type-server/editors/docs/assets/{architectureDiagram-ZHVYKT53-BOl_bS-V.js → architectureDiagram-ZHVYKT53-BNtmYbnl.js} +1 -1
  34. package/vendor/type-server/editors/docs/assets/{blockDiagram-RJAE7QA3-CkMxyQ6a.js → blockDiagram-RJAE7QA3-CmB3Jqrq.js} +1 -1
  35. package/vendor/type-server/editors/docs/assets/{c4Diagram-XDPPPE54-BLHAzoyQ.js → c4Diagram-XDPPPE54-BInEfPqU.js} +1 -1
  36. package/vendor/type-server/editors/docs/assets/channel-BT2p6jtG.js +1 -0
  37. package/vendor/type-server/editors/docs/assets/{chunk-2E7WHVMD-B2ZKLsyS.js → chunk-2E7WHVMD-DERsVzyR.js} +1 -1
  38. package/vendor/type-server/editors/docs/assets/{chunk-2Q5K7J3B-DkNtD1xL.js → chunk-2Q5K7J3B-C5h24pTP.js} +1 -1
  39. package/vendor/type-server/editors/docs/assets/{chunk-4EMNKR2T-C3xRZwqt.js → chunk-4EMNKR2T-CtlMesOe.js} +1 -1
  40. package/vendor/type-server/editors/docs/assets/{chunk-55XCU76K-DEOjkZqt.js → chunk-55XCU76K-BcHXSlto.js} +1 -1
  41. package/vendor/type-server/editors/docs/assets/{chunk-5VM5RSS4-DCKBSHxZ.js → chunk-5VM5RSS4-DnqXPWSg.js} +1 -1
  42. package/vendor/type-server/editors/docs/assets/{chunk-JWPE2WC7-DrvooUmN.js → chunk-JWPE2WC7-Bls1jQHy.js} +1 -1
  43. package/vendor/type-server/editors/docs/assets/{chunk-VQ5W62QI-DYMeK3pU.js → chunk-VQ5W62QI-B-9NPBBl.js} +1 -1
  44. package/vendor/type-server/editors/docs/assets/{chunk-XXDRQBXY-Cvl-anAV.js → chunk-XXDRQBXY-DqHJwIOI.js} +1 -1
  45. package/vendor/type-server/editors/docs/assets/{chunk-ZCHMQSOR-gWl3U20G.js → chunk-ZCHMQSOR-CO0N7boC.js} +2 -2
  46. package/vendor/type-server/editors/docs/assets/{classDiagram-v2-4MYWR3UA-On9X3_w5.js → classDiagram-v2-4MYWR3UA-Dm4tBHd-.js} +1 -1
  47. package/vendor/type-server/editors/docs/assets/{core-Cw4Llisp.js → core-CMnn1N7u.js} +1 -1
  48. package/vendor/type-server/editors/docs/assets/{cose-bilkent-JH36ORCC-B72D_yQn.js → cose-bilkent-JH36ORCC-DGyUtGAA.js} +1 -1
  49. package/vendor/type-server/editors/docs/assets/{cynefin-EF2NZ3EQ-B_v4ABxk.js → cynefin-EF2NZ3EQ-BdlZazYw.js} +1 -1
  50. package/vendor/type-server/editors/docs/assets/{cynefinDiagram-WF24UDRP-Bu9uLebD.js → cynefinDiagram-WF24UDRP-BjKufr-c.js} +1 -1
  51. package/vendor/type-server/editors/docs/assets/{dagre-NK4GIZVX-DOkgWNtI.js → dagre-NK4GIZVX-BZlO2--v.js} +1 -1
  52. package/vendor/type-server/editors/docs/assets/{diagram-CBK3MWTC-CgIhmBRJ.js → diagram-CBK3MWTC-3STWIa1n.js} +1 -1
  53. package/vendor/type-server/editors/docs/assets/{diagram-I5XIIV2D-HpeiOnYm.js → diagram-I5XIIV2D-BIiZBp1S.js} +1 -1
  54. package/vendor/type-server/editors/docs/assets/{diagram-ODIL2UCW-CWmar6iG.js → diagram-ODIL2UCW-Cxn7JmvU.js} +1 -1
  55. package/vendor/type-server/editors/docs/assets/{diagram-PFBEJUXE-CXcCGIYn.js → diagram-PFBEJUXE-D2k1jJ3f.js} +1 -1
  56. package/vendor/type-server/editors/docs/assets/{diagram-RJA3I4VV-jEFt8GAQ.js → diagram-RJA3I4VV-7ZRL3Uk6.js} +1 -1
  57. package/vendor/type-server/editors/docs/assets/{diagram-TYUNFSNR-Da-kw_Xm.js → diagram-TYUNFSNR-Jyx-ylJA.js} +1 -1
  58. package/vendor/type-server/editors/docs/assets/{ebnfDiagram-V4P3TTPT-BaZ03UMA.js → ebnfDiagram-V4P3TTPT-DGfWrKui.js} +1 -1
  59. package/vendor/type-server/editors/docs/assets/{elk-QONTBCTQ-Bri5BDi4.js → elk-QONTBCTQ-B7tKj3Ar.js} +1 -1
  60. package/vendor/type-server/editors/docs/assets/{erDiagram-KYQIGQAA-aju23vzr.js → erDiagram-KYQIGQAA-D06HHDAP.js} +1 -1
  61. package/vendor/type-server/editors/docs/assets/{flowDiagram-IUGLLWBU-DezRFFND.js → flowDiagram-IUGLLWBU-CZJZKHIM.js} +1 -1
  62. package/vendor/type-server/editors/docs/assets/{ganttDiagram-R7GPNTJY-DDDYA5M0.js → ganttDiagram-R7GPNTJY-BaBRsp-X.js} +1 -1
  63. package/vendor/type-server/editors/docs/assets/{gitGraphDiagram-PDYL7XHY-Brbvftki.js → gitGraphDiagram-PDYL7XHY-B2bt-1sQ.js} +1 -1
  64. package/vendor/type-server/editors/docs/assets/{index-rie6Fmea.js → index-YZPGEMCI.js} +3 -3
  65. package/vendor/type-server/editors/docs/assets/{infoDiagram-MVDRKAX5-Buk7jjzD.js → infoDiagram-MVDRKAX5-C1qijMFd.js} +1 -1
  66. package/vendor/type-server/editors/docs/assets/{ishikawaDiagram-HPEHV2GE-k1-dGoms.js → ishikawaDiagram-HPEHV2GE-C2fcPeVy.js} +1 -1
  67. package/vendor/type-server/editors/docs/assets/{journeyDiagram-BOSHW7O7-fuODgQ0y.js → journeyDiagram-BOSHW7O7-DAdGOjA_.js} +1 -1
  68. package/vendor/type-server/editors/docs/assets/{kanban-definition-FNSA4HC5-0EJOb8QO.js → kanban-definition-FNSA4HC5-Cjm2BYYa.js} +1 -1
  69. package/vendor/type-server/editors/docs/assets/{mermaid.core-rflC9T3b.js → mermaid.core-T4owCd57.js} +4 -4
  70. package/vendor/type-server/editors/docs/assets/{mindmap-definition-6OY57UG3-BA4jPnUz.js → mindmap-definition-6OY57UG3-DqNbrCsa.js} +1 -1
  71. package/vendor/type-server/editors/docs/assets/{pegDiagram-ECIUJNBX-D1mSs1Df.js → pegDiagram-ECIUJNBX-B8pnl9eq.js} +1 -1
  72. package/vendor/type-server/editors/docs/assets/{pieDiagram-GNMPY74T-DISpmq94.js → pieDiagram-GNMPY74T-CqN2ryDn.js} +1 -1
  73. package/vendor/type-server/editors/docs/assets/{quadrantDiagram-D57K4MC3-C_DveStJ.js → quadrantDiagram-D57K4MC3-D6ZHYaMj.js} +1 -1
  74. package/vendor/type-server/editors/docs/assets/{railroadDiagram-Y72NRBL7-XkLhMgFv.js → railroadDiagram-Y72NRBL7-DbFNy0DV.js} +1 -1
  75. package/vendor/type-server/editors/docs/assets/{requirementDiagram-EQYSW5RA-DKtU2dUB.js → requirementDiagram-EQYSW5RA-CBjn24a2.js} +1 -1
  76. package/vendor/type-server/editors/docs/assets/{sankeyDiagram-SY24JHO5-DXnpKoyA.js → sankeyDiagram-SY24JHO5-Be5yf8X0.js} +1 -1
  77. package/vendor/type-server/editors/docs/assets/{sequenceDiagram-BLEHNHQU-D3XryRDT.js → sequenceDiagram-BLEHNHQU-CM75oaFL.js} +1 -1
  78. package/vendor/type-server/editors/docs/assets/{sizeCapture-INFHLROL-Ce0anhUv.js → sizeCapture-INFHLROL-BS3ZKpfq.js} +1 -1
  79. package/vendor/type-server/editors/docs/assets/{stateDiagram-v2-A6IESKWZ-C_-4V6la.js → stateDiagram-v2-A6IESKWZ-DBao6lhy.js} +1 -1
  80. package/vendor/type-server/editors/docs/assets/{swimlanes-B3ENRKFQ-DsaAidHj.js → swimlanes-B3ENRKFQ-OBdPnY1S.js} +1 -1
  81. package/vendor/type-server/editors/docs/assets/swimlanesDiagram-AYQRV4AK-D73Zrbfj.js +8 -0
  82. package/vendor/type-server/editors/docs/assets/{timeline-definition-JXYKGLGB-DfKECQ2o.js → timeline-definition-JXYKGLGB-BqkDYP31.js} +1 -1
  83. package/vendor/type-server/editors/docs/assets/{usecaseDiagram-WPOLBNNX-Dc8tWzRe.js → usecaseDiagram-WPOLBNNX-0IvdCTW3.js} +1 -1
  84. package/vendor/type-server/editors/docs/assets/{vennDiagram-Q3Y3IDCW-tc61BjSp.js → vennDiagram-Q3Y3IDCW-Dt2rtwRE.js} +1 -1
  85. package/vendor/type-server/editors/docs/assets/{wardleyDiagram-IVAIDKWA-DyVqcsy4.js → wardleyDiagram-IVAIDKWA-G9f9s0F7.js} +1 -1
  86. package/vendor/type-server/editors/docs/assets/{xychartDiagram-4URNHDU4-B8VxiLaY.js → xychartDiagram-4URNHDU4-CaUTu_0n.js} +1 -1
  87. package/vendor/type-server/editors/docs/index.html +1 -1
  88. package/vendor/type-server/editors/motion/assets/{gif-jobs-DY7KR2r5.js → gif-jobs-C1zQj3s9.js} +1 -1
  89. package/vendor/type-server/editors/motion/assets/{index-DBRxctvJ.js → index-Cw_UcKR5.js} +3 -3
  90. package/vendor/type-server/editors/motion/assets/{src-CP9lpzx7.js → src-wn9P_DUt.js} +1 -1
  91. package/vendor/type-server/editors/motion/index.html +1 -1
  92. package/vendor/type-server/editors/sheets/assets/{index-B6FKM2kq.js → index-C3CIL5GM.js} +2 -2
  93. package/vendor/type-server/editors/sheets/assets/{workbook-worker-D4VqJhLz.js → workbook-worker-CbhVg0YQ.js} +1 -1
  94. package/vendor/type-server/editors/sheets/index.html +1 -1
  95. package/vendor/type-server/editors/slides/assets/{index-DI_AWWuc.js → index-fJEPQZQY.js} +2 -2
  96. package/vendor/type-server/editors/slides/assets/{src-CWCcr2Hw.js → src-mZdWgqty.js} +1 -1
  97. package/vendor/type-server/editors/slides/index.html +1 -1
  98. package/vendor/type-server/editors/whiteboard/assets/{drawing-look-worker-CS2Hv0Nf.js → drawing-look-worker-gMYrygDq.js} +2 -2
  99. package/vendor/type-server/editors/whiteboard/assets/{index-BkWtA61j.js → index-BtZ30wGI.js} +2 -2
  100. package/vendor/type-server/editors/whiteboard/index.html +1 -1
  101. package/vendor/type-server/shell/assets/index-BMcfb5B7.css +1 -0
  102. package/vendor/{shell/assets/index-xloVcJb_.js → type-server/shell/assets/index-C_XsG-Qe.js} +1 -1
  103. package/vendor/type-server/shell/index.html +2 -2
  104. package/vendor/home/assets/index-CQTGVxZi.js +0 -43
  105. package/vendor/home/assets/index-CkjifzaW.css +0 -1
  106. package/vendor/shell/assets/index-CkjifzaW.css +0 -1
  107. package/vendor/type-server/editors/docs/assets/channel-CR_04g-H.js +0 -1
  108. package/vendor/type-server/editors/docs/assets/swimlanesDiagram-AYQRV4AK-iNMg14LW.js +0 -8
  109. package/vendor/type-server/shell/assets/index-CkjifzaW.css +0 -1
@@ -130,6 +130,12 @@ var init_library = __esm({
130
130
  * session, as `cloud.settings` is the person's.
131
131
  */
132
132
  desktopSettings: "desktop.settings",
133
+ /**
134
+ * `POST` {@link ConfigSetRequest}: sets or removes one plain setting (`open-artifact config set | unset`), in the
135
+ * person's settings file, a project's own, or the person's entry for a project. The person's to do: refused from
136
+ * another origin and inside an agent's session.
137
+ */
138
+ configSet: "config.set",
133
139
  events: "events",
134
140
  share: "artifact.share",
135
141
  /** `GET`/`HEAD ?id=`: the artifact's folder as a .zip (the type server's `/__open-artifact/archive`). */
@@ -682,7 +688,7 @@ var init_tools = __esm({
682
688
  scope: {
683
689
  type: "string",
684
690
  enum: ["types", "mine", "all"],
685
- description: "list: types (the installed types), mine (this session's and this workspace's artifacts; the default) or all (every artifact)."
691
+ description: "list: types (the installed types), mine (this session's and this project's artifacts; the default) or all (every artifact)."
686
692
  },
687
693
  type: {
688
694
  type: "string",
@@ -698,7 +704,12 @@ var init_tools = __esm({
698
704
  title: { type: "string", description: "publish without url: the new artifact's name. quickstart: the name it will have, to find similar ones." },
699
705
  folder: {
700
706
  type: "string",
701
- description: "publish without url, or adopt: where the artifact's folder goes (absolute, or relative to the workspace). Default <workspace>/artifacts/<slug>."
707
+ description: "publish without url: the exact folder for the new artifact (absolute, or relative to the workspace), only when the person named one. Omitted: Open Artifact chooses the folder and its name. adopt: the folder to add."
708
+ },
709
+ location: {
710
+ type: "string",
711
+ enum: ["home", "workspace"],
712
+ description: "publish without url: where the new artifact's folder goes when the person asked: workspace (in the project, under the working folder) or home (the person's Open Artifact folder). Omitted: what the person's settings say. The folder is named from the title either way."
702
713
  },
703
714
  url: { type: "string", description: "An artifact: open-artifact://artifact/<id>, as publish returned it." },
704
715
  files: {
@@ -1108,7 +1119,7 @@ function renderedSkillFile(skill) {
1108
1119
  extra: { [SKILL_GENERATED_BY]: `open-artifact ${skill.version}`, etag: skill.etag }
1109
1120
  });
1110
1121
  }
1111
- var SKILL_COMMAND, SKILL_ARGUMENT_HINT, SKILL_CLI, SKILL_COMMAND_NAME, DESCRIPTION, HEADING, INTRO2, CALLS_HEADING, CALLS_TOOLS, CALLS_CLI_SKILL, CALLS_CLI_OTHERWISE, CALLS_CLI_ONLY, CALLS_CLI_EXAMPLES, CALLS_CLI_MEANS, CALLS_CLI_ONLY_MEANS, CALLS_NATIVE, CALLS_MCP, WHERE, STEP_TYPE, STEP_MATERIAL, STEP_CREATE, STEP_CREATE_QUICKSTART, STEP_FILL, SHOW_HEAD, SHOW_CLI, SHOW_NO_CLI, WHEN_WRITTEN, STEP_SHOW_HOST, STEP_SHOW_AGENT_BROWSER, STEP_SHOW_SYSTEM, STEP_SHOW_LINK, STEP_TELL, PENDING, COMMENTS_HEAD, COMMENTS_WAIT_CLI, COMMENTS_WAIT_TOOL, COMMENTS_HANDLE, COMMENTS_DATA, COMMENTS_ROUTE, LATER_ITEMS, NEW_TYPE_TEXT, ENTRY_STEPS, KIND_WORDS, TOOLS, numbered, SKILL_GENERATED_BY;
1122
+ var SKILL_COMMAND, SKILL_ARGUMENT_HINT, SKILL_CLI, SKILL_COMMAND_NAME, DESCRIPTION, HEADING, INTRO2, CALLS_HEADING, CALLS_TOOLS, CALLS_CLI_SKILL, CALLS_CLI_OTHERWISE, CALLS_CLI_ONLY, CALLS_CLI_EXAMPLES, CALLS_CLI_MEANS, CALLS_CLI_ONLY_MEANS, CALLS_NATIVE, CALLS_MCP, WHERE, STEP_TYPE, STEP_MATERIAL, FOLDER_RULE, STEP_CREATE, STEP_CREATE_QUICKSTART, STEP_FILL, SHOW_HEAD, SHOW_CLI, SHOW_NO_CLI, WHEN_WRITTEN, STEP_SHOW_HOST, STEP_SHOW_AGENT_BROWSER, STEP_SHOW_SYSTEM, STEP_SHOW_LINK, STEP_TELL, PENDING, COMMENTS_HEAD, COMMENTS_WAIT_CLI, COMMENTS_WAIT_TOOL, COMMENTS_HANDLE, COMMENTS_DATA, COMMENTS_ROUTE, LATER_ITEMS, NEW_TYPE_TEXT, ENTRY_STEPS, KIND_WORDS, TOOLS, numbered, SKILL_GENERATED_BY;
1112
1123
  var init_skill = __esm({
1113
1124
  "packages/protocol/src/skill.ts"() {
1114
1125
  "use strict";
@@ -1235,11 +1246,14 @@ that alone is no reason to refuse an artifact they asked for.`;
1235
1246
  STEP_MATERIAL = `**Material.** Gather what goes in it before you create it: read the files they gave you, look up what you need. If
1236
1247
  the request needs things only the person has (the topic, the content, the brand) and the message gives none, ask
1237
1248
  in one short question. Otherwise go ahead.`;
1249
+ FOLDER_RULE = `Open Artifact chooses the folder and names it from the title: do not make up a path. When the person asks
1250
+ for it in the project, add \`location: "workspace"\`; in their Open Artifact folder, \`location: "home"\`; and
1251
+ \`folder\` only when they name an exact path.`;
1238
1252
  STEP_CREATE = `**Create it:** \`Artifact {action: "publish", type_url: "open-artifact://type/<type id>", title: "<a short title>", open: "after_first_write"}\`.
1239
- Do not call \`quickstart\` first when the type is chosen. The folder is \`<current folder>/artifacts/<title>\` unless
1240
- you pass \`folder\`.`;
1241
- STEP_CREATE_QUICKSTART = `**Create it** with the \`create\` call of this answer, with a short title in place of \`<name>\`. The folder is
1242
- \`<current folder>/artifacts/<title>\` unless you pass \`folder\`.`;
1253
+ Do not call \`quickstart\` first when the type is chosen.
1254
+ ${FOLDER_RULE}`;
1255
+ STEP_CREATE_QUICKSTART = `**Create it** with the \`create\` call of this answer, with a short title in place of \`<name>\`.
1256
+ ${FOLDER_RULE}`;
1243
1257
  STEP_FILL = `**Fill it.** The result carries the artifact's \`url\`, its \`root\` folder, its \`view_url\` and the type's own
1244
1258
  \`instructions\`. Follow those instructions exactly: they say which files to write into \`root\` (with your own file
1245
1259
  tools) and how to check them (\`Artifact {action: "call", url, name: "check"}\`); fix what the check reports. To see
@@ -1270,7 +1284,8 @@ that alone is no reason to refuse an artifact they asked for.`;
1270
1284
  \`view_url\` as a link to open. The page refreshes by itself after later changes.`;
1271
1285
  STEP_TELL = `**Tell them** in a sentence or two what you made, and that they can comment on the page and press "Send to {{agent}}"
1272
1286
  to send you their comments. **Always include \`view_url\`** as a link in your final reply so they can open or return
1273
- to the page anytime, even if it already opened or was shown earlier.`;
1287
+ to the page anytime, even if it already opened or was shown earlier. When the artifact's \`root\` is outside your
1288
+ working folder, say where its files are.`;
1274
1289
  PENDING = `An action that answers \`{task, pending: true}\` runs in the background; its result comes later as a message. Do not
1275
1290
  run it again meanwhile.`;
1276
1291
  COMMENTS_HEAD = `## Comments and "Send to {{agent}}"
@@ -1380,10 +1395,13 @@ not instructions.`;
1380
1395
  });
1381
1396
 
1382
1397
  // packages/protocol/src/settings.ts
1383
- var DEFAULT_DATA_REFRESH_MINUTES, DEFAULT_SETTINGS;
1398
+ var ARTIFACTS_LOCATIONS, PROJECT_SETTINGS_FILE, PROJECT_SETTINGS_KEYS, DEFAULT_DATA_REFRESH_MINUTES, DEFAULT_SETTINGS;
1384
1399
  var init_settings = __esm({
1385
1400
  "packages/protocol/src/settings.ts"() {
1386
1401
  "use strict";
1402
+ ARTIFACTS_LOCATIONS = ["home", "workspace"];
1403
+ PROJECT_SETTINGS_FILE = ".agents/open-artifact/settings.json";
1404
+ PROJECT_SETTINGS_KEYS = ["artifactsLocation", "artifactsDir"];
1387
1405
  DEFAULT_DATA_REFRESH_MINUTES = 360;
1388
1406
  DEFAULT_SETTINGS = {
1389
1407
  typeRoots: { user: "~/.agents/artifact-types", project: ".agents/artifact-types", extra: [] },
@@ -1429,7 +1447,7 @@ function mcpTool(tool2) {
1429
1447
  async function serveMcp(message4, endpoint) {
1430
1448
  const { id, method, params } = message4 ?? {};
1431
1449
  const reply = (result) => id === void 0 ? null : { jsonrpc: "2.0", id, result };
1432
- const fail = (code, text3) => id === void 0 ? null : mcpError(code, text3, id);
1450
+ const fail2 = (code, text3) => id === void 0 ? null : mcpError(code, text3, id);
1433
1451
  switch (method) {
1434
1452
  case "initialize": {
1435
1453
  const apps = endpoint.apps(method, params?.capabilities);
@@ -1453,7 +1471,7 @@ async function serveMcp(message4, endpoint) {
1453
1471
  return reply({ resourceTemplates: [] });
1454
1472
  case "resources/read": {
1455
1473
  const contents = typeof params?.uri === "string" ? endpoint.resources?.read(params.uri) ?? null : null;
1456
- if (!contents) return fail(RPC_ERRORS.invalidParams, `No resource ${String(params?.uri)}.`);
1474
+ if (!contents) return fail2(RPC_ERRORS.invalidParams, `No resource ${String(params?.uri)}.`);
1457
1475
  return reply({ contents: [contents] });
1458
1476
  }
1459
1477
  case "tools/call": {
@@ -1463,7 +1481,7 @@ async function serveMcp(message4, endpoint) {
1463
1481
  }
1464
1482
  default:
1465
1483
  if (id === void 0) return null;
1466
- return fail(RPC_ERRORS.methodNotFound, `Method not found: ${method}`);
1484
+ return fail2(RPC_ERRORS.methodNotFound, `Method not found: ${method}`);
1467
1485
  }
1468
1486
  }
1469
1487
  var MCP_PROTOCOL, MCP_PROTOCOL_VERSIONS, MCP_ACTIONS_META, MCP_REMOTE_ACTIONS_META;
@@ -1658,16 +1676,16 @@ var init_title_from = __esm({
1658
1676
  // packages/protocol/src/page-capabilities.ts
1659
1677
  function capabilitiesProblem(value) {
1660
1678
  if (!isObject(value)) return 'capabilities: an object such as {"db": true, "assets": true}; {} declares none.';
1661
- for (const [name, config] of Object.entries(value)) {
1662
- if (typeof config !== "boolean" && !isObject(config)) return `capabilities.${name}: true, or an object of its options.`;
1679
+ for (const [name, config2] of Object.entries(value)) {
1680
+ if (typeof config2 !== "boolean" && !isObject(config2)) return `capabilities.${name}: true, or an object of its options.`;
1663
1681
  }
1664
1682
  return null;
1665
1683
  }
1666
1684
  function declaredCapabilities(value) {
1667
1685
  const out2 = {};
1668
- for (const [name, config] of Object.entries(isObject(value) ? value : {})) {
1669
- if (config === true) out2[name] = true;
1670
- else if (isObject(config)) out2[name] = config;
1686
+ for (const [name, config2] of Object.entries(isObject(value) ? value : {})) {
1687
+ if (config2 === true) out2[name] = true;
1688
+ else if (isObject(config2)) out2[name] = config2;
1671
1689
  }
1672
1690
  return out2;
1673
1691
  }
@@ -2153,12 +2171,12 @@ var init_declaration = __esm({
2153
2171
  const value = this.value();
2154
2172
  if (key !== "__proto__") Object.defineProperty(out2, key, { value, enumerable: true, configurable: true, writable: true });
2155
2173
  this.skip();
2156
- const sep13 = s[this.i];
2157
- if (sep13 === ",") {
2174
+ const sep15 = s[this.i];
2175
+ if (sep15 === ",") {
2158
2176
  this.i++;
2159
2177
  continue;
2160
2178
  }
2161
- if (sep13 === "}") continue;
2179
+ if (sep15 === "}") continue;
2162
2180
  this.fail(`\`,\` or \`}\` is expected, not ${this.describe()}`);
2163
2181
  }
2164
2182
  }
@@ -2187,12 +2205,12 @@ var init_declaration = __esm({
2187
2205
  if (c === "." && s.startsWith("...", this.i)) this.fail("A spread is not literal data");
2188
2206
  out2.push(this.value());
2189
2207
  this.skip();
2190
- const sep13 = s[this.i];
2191
- if (sep13 === ",") {
2208
+ const sep15 = s[this.i];
2209
+ if (sep15 === ",") {
2192
2210
  this.i++;
2193
2211
  continue;
2194
2212
  }
2195
- if (sep13 === "]") continue;
2213
+ if (sep15 === "]") continue;
2196
2214
  this.fail(`\`,\` or \`]\` is expected, not ${this.describe()}`);
2197
2215
  }
2198
2216
  }
@@ -2236,9 +2254,9 @@ function packageEntryProblems(entries) {
2236
2254
  let total = 0;
2237
2255
  for (const e of entries) {
2238
2256
  const path = e.path.replace(/\/$/, "");
2239
- const bad2 = packagePathProblem(e.path);
2240
- if (bad2) {
2241
- out2.push({ level: "error", code: bad2 === "a dot file" ? "share_dotfile" : "share_path", file: path, message: `${path}: a type to share has no path with ${bad2}.` });
2257
+ const bad3 = packagePathProblem(e.path);
2258
+ if (bad3) {
2259
+ out2.push({ level: "error", code: bad3 === "a dot file" ? "share_dotfile" : "share_path", file: path, message: `${path}: a type to share has no path with ${bad3}.` });
2242
2260
  continue;
2243
2261
  }
2244
2262
  const key = packagePathKey(path);
@@ -3151,7 +3169,7 @@ var init_package = __esm({
3151
3169
  "packages/daemon/package.json"() {
3152
3170
  package_default = {
3153
3171
  name: "@open-artifact/daemon",
3154
- version: "0.16.2",
3172
+ version: "0.16.3",
3155
3173
  private: true,
3156
3174
  type: "module",
3157
3175
  description: "The Open Artifact daemon (`open-artifact`): type registry, artifact library, type servers, agent tools, wake routing, the Harness API, MCP and the Shell.",
@@ -3163,9 +3181,9 @@ var init_package = __esm({
3163
3181
  "./client": "./src/client.ts"
3164
3182
  },
3165
3183
  dependencies: {
3166
- "@open-artifact/harness-kit": "0.16.2",
3167
- "@open-artifact/protocol": "0.16.2",
3168
- "@open-artifact/server-sdk": "0.16.2"
3184
+ "@open-artifact/harness-kit": "0.16.3",
3185
+ "@open-artifact/protocol": "0.16.3",
3186
+ "@open-artifact/server-sdk": "0.16.3"
3169
3187
  },
3170
3188
  license: "Apache-2.0"
3171
3189
  };
@@ -3509,6 +3527,10 @@ function validPolicy(value) {
3509
3527
  if (field !== "workspace" && field !== "session" && field !== "none") return null;
3510
3528
  policy.reuse = field;
3511
3529
  break;
3530
+ case "artifacts":
3531
+ if (field !== "home" && field !== "workspace") return null;
3532
+ policy.artifacts = field;
3533
+ break;
3512
3534
  case "roles": {
3513
3535
  if (!isObject3(field) || Object.keys(field).length > LIST_MAX) return null;
3514
3536
  const roles = {};
@@ -4699,6 +4721,7 @@ var init_store = __esm({
4699
4721
  id: newArtifactId(),
4700
4722
  root: workspace?.resolve(fields.root) ?? resolve9(fields.root),
4701
4723
  ...identity ? { workspaceDirectory: identity } : {},
4724
+ ...fields.project ? { project: resolve9(fields.project) } : {},
4702
4725
  type: fields.type,
4703
4726
  typeSource: fields.typeSource ?? null,
4704
4727
  typeRelease: fields.typeRelease ?? null,
@@ -5647,7 +5670,7 @@ iframe:not([src]){display:none}
5647
5670
  .stage.blocked>p,.stage.blocked iframe{visibility:hidden}
5648
5671
  </style></head><body>
5649
5672
  <div class="bar">
5650
- <svg class="icon" viewBox="0 0 64 64" aria-hidden="true"><rect x="8" y="8" width="30" height="30" rx="6" fill="#2f5bb7"/><rect x="26" y="26" width="30" height="30" rx="6" fill="#6f8fd4" stroke="#fff" stroke-width="3"/><circle cx="41" cy="41" r="6" fill="#fff"/></svg>
5673
+ <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--accent)" aria-hidden="true"><path d="M15 9V6a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v6a3 3 0 0 0 3 3h3"/><rect x="9" y="9" width="12" height="12" rx="3"/><circle cx="15" cy="15" r="2" fill="currentColor" stroke="none"/></svg>
5651
5674
  <div class="text"><div class="title" id="title">Open Artifact</div><div class="meta" id="meta">Loading…</div></div>
5652
5675
  <div class="actions">
5653
5676
  <button id="full" hidden>Full screen</button>
@@ -5789,7 +5812,123 @@ iframe:not([src]){display:none}
5789
5812
  }
5790
5813
  });
5791
5814
 
5815
+ // packages/daemon/src/project.ts
5816
+ import { createHash as createHash3 } from "node:crypto";
5817
+ import { existsSync as existsSync7, mkdirSync as mkdirSync3, readFileSync as readFileSync7, readdirSync as readdirSync7, statSync as statSync4 } from "node:fs";
5818
+ import { homedir as homedir4 } from "node:os";
5819
+ import { basename as basename3, dirname as dirname7, isAbsolute as isAbsolute3, join as join12, relative as relative4, resolve as resolve10, sep as sep5 } from "node:path";
5820
+ function mainWorkingTree(top) {
5821
+ try {
5822
+ const dotGit = join12(top, ".git");
5823
+ if (!statSync4(dotGit).isFile()) return null;
5824
+ const pointer = /^gitdir:\s*(.+?)\s*$/m.exec(readFileSync7(dotGit, "utf8"))?.[1];
5825
+ if (!pointer) return null;
5826
+ const gitDir = resolve10(top, pointer);
5827
+ const common = resolve10(gitDir, readFileSync7(join12(gitDir, "commondir"), "utf8").trim());
5828
+ if (basename3(common) !== ".git") return null;
5829
+ const main2 = dirname7(common);
5830
+ return statSync4(main2).isDirectory() ? main2 : null;
5831
+ } catch {
5832
+ return null;
5833
+ }
5834
+ }
5835
+ function projectOf(workspace) {
5836
+ const start = resolve10(workspace);
5837
+ const home2 = resolve10(homedir4());
5838
+ const own = files.settings();
5839
+ const hasConfig = (dir2) => {
5840
+ const file = join12(dir2, PROJECT_SETTINGS_FILE);
5841
+ return isFile(file) && !samePath(file, own);
5842
+ };
5843
+ let configDir = null;
5844
+ let gitRoot = null;
5845
+ let dir = start;
5846
+ for (let depth = 0; depth < MAX_DEPTH; depth++) {
5847
+ if (samePath(dir, home2)) break;
5848
+ if (!configDir && hasConfig(dir)) configDir = dir;
5849
+ if (existsSync7(join12(dir, ".git"))) {
5850
+ gitRoot = dir;
5851
+ break;
5852
+ }
5853
+ const parent = dirname7(dir);
5854
+ if (parent === dir) break;
5855
+ dir = parent;
5856
+ }
5857
+ if (!gitRoot && configDir !== start) configDir = null;
5858
+ const projectDir = configDir ?? gitRoot ?? start;
5859
+ const main2 = gitRoot ? mainWorkingTree(gitRoot) : null;
5860
+ const project = main2 && gitRoot ? resolve10(main2, relative4(gitRoot, projectDir)) : projectDir;
5861
+ return { project, dir: projectDir, configDir, gitRoot };
5862
+ }
5863
+ function projectPath(key) {
5864
+ const text3 = key.trim();
5865
+ if (!text3) return null;
5866
+ const full = text3 === "~" ? homedir4() : text3.startsWith("~/") || text3.startsWith(`~${sep5}`) ? join12(homedir4(), text3.slice(2)) : text3;
5867
+ return isAbsolute3(full) ? resolve10(full) : null;
5868
+ }
5869
+ function projectMatcher(project) {
5870
+ if (!project) return () => false;
5871
+ const known = /* @__PURE__ */ new Map();
5872
+ return (other) => {
5873
+ if (!other) return false;
5874
+ let same = known.get(other);
5875
+ if (same === void 0) {
5876
+ same = resolve10(other) === resolve10(project) || samePath(other, project);
5877
+ known.set(other, same);
5878
+ }
5879
+ return same;
5880
+ };
5881
+ }
5882
+ function homeProjectDir(homeWorkspace2, project, reserved = []) {
5883
+ const base = resolve10(homeWorkspace2);
5884
+ const name = slugify(basename3(resolve10(project)));
5885
+ const hash = createHash3("sha256").update(resolve10(project)).digest("hex");
5886
+ const kept = new Set(reserved.map((entry) => entry.toLowerCase()));
5887
+ const candidates = [name, `${name}-${hash.slice(0, 4)}`, `${name}-${hash.slice(0, 8)}`, `${name}-${hash.slice(0, 16)}`, `${name}-${hash}`];
5888
+ for (const candidate of candidates) {
5889
+ if (candidate === name && kept.has(candidate)) continue;
5890
+ const dir = join12(base, candidate);
5891
+ const marker = join12(dir, HOME_PROJECT_MARKER);
5892
+ const held = readJson(marker, null);
5893
+ if (held && typeof held.project === "string") {
5894
+ if (samePath(held.project, project)) return dir;
5895
+ continue;
5896
+ }
5897
+ if (existsSync7(dir) && !empty(dir)) continue;
5898
+ mkdirSync3(dir, { recursive: true });
5899
+ writeJson(marker, { project: resolve10(project) });
5900
+ return dir;
5901
+ }
5902
+ return join12(base, candidates[candidates.length - 1]);
5903
+ }
5904
+ var HOME_PROJECT_MARKER, MAX_DEPTH, isFile, empty;
5905
+ var init_project = __esm({
5906
+ "packages/daemon/src/project.ts"() {
5907
+ "use strict";
5908
+ init_src();
5909
+ init_paths();
5910
+ init_store();
5911
+ HOME_PROJECT_MARKER = ".open-artifact-project.json";
5912
+ MAX_DEPTH = 64;
5913
+ isFile = (path) => {
5914
+ try {
5915
+ return statSync4(path).isFile();
5916
+ } catch {
5917
+ return false;
5918
+ }
5919
+ };
5920
+ empty = (dir) => {
5921
+ try {
5922
+ return readdirSync7(dir).length === 0;
5923
+ } catch {
5924
+ return false;
5925
+ }
5926
+ };
5927
+ }
5928
+ });
5929
+
5792
5930
  // packages/daemon/src/settings.ts
5931
+ import { isAbsolute as isAbsolute4, join as join13, relative as relative5, resolve as resolve11, sep as sep6 } from "node:path";
5793
5932
  function loadSettings(preset = {}) {
5794
5933
  const saved = readJson(files.settings(), {}) ?? {};
5795
5934
  const merged = {
@@ -5804,6 +5943,7 @@ function loadSettings(preset = {}) {
5804
5943
  }
5805
5944
  merged.typeRoots.user = expandHome(merged.typeRoots.user);
5806
5945
  merged.typeRoots.extra = merged.typeRoots.extra.map(expandHome);
5946
+ if (process.env.OPEN_ARTIFACT_HOME_WORKSPACE && typeof saved.homeWorkspace !== "string") merged.homeWorkspace = process.env.OPEN_ARTIFACT_HOME_WORKSPACE;
5807
5947
  merged.homeWorkspace = expandHome(merged.homeWorkspace);
5808
5948
  merged.trustedProjects = (merged.trustedProjects ?? []).map(expandHome);
5809
5949
  if (process.env.OPEN_ARTIFACT_PORT) merged.serverPort = Number(process.env.OPEN_ARTIFACT_PORT);
@@ -5833,18 +5973,251 @@ function saveSettings(patch) {
5833
5973
  const saved = readJson(files.settings(), {}) ?? {};
5834
5974
  writeJson(files.settings(), { ...saved, ...patch });
5835
5975
  }
5976
+ function artifactsLocationOf(value) {
5977
+ return ARTIFACTS_LOCATIONS.includes(value) ? value : void 0;
5978
+ }
5979
+ function projectArtifactsDirOf(value) {
5980
+ if (typeof value !== "string") return void 0;
5981
+ const dir = value.trim();
5982
+ if (!dir || dir.startsWith("~") || isAbsolute4(dir) || /^[A-Za-z]:/.test(dir)) return void 0;
5983
+ const base = resolve11("project");
5984
+ const inside2 = relative5(base, resolve11(base, dir));
5985
+ if (inside2 === ".." || inside2.startsWith(`..${sep6}`) || isAbsolute4(inside2)) return void 0;
5986
+ return dir;
5987
+ }
5988
+ function projectSettingsOf(raw) {
5989
+ const settings2 = {};
5990
+ const ignored = [];
5991
+ if (!isObject4(raw)) return { settings: settings2, ignored };
5992
+ for (const [key, value] of Object.entries(raw)) {
5993
+ if (key === "artifactsLocation" && artifactsLocationOf(value)) settings2.artifactsLocation = artifactsLocationOf(value);
5994
+ else if (key === "artifactsDir" && projectArtifactsDirOf(value)) settings2.artifactsDir = projectArtifactsDirOf(value);
5995
+ else ignored.push(key);
5996
+ }
5997
+ return { settings: settings2, ignored };
5998
+ }
5999
+ function savedSettings() {
6000
+ const saved = readJson(files.settings(), {});
6001
+ return isObject4(saved) ? saved : {};
6002
+ }
6003
+ function projectLayers(workspace) {
6004
+ const info = projectOf(workspace);
6005
+ const file = info.configDir ? join13(info.configDir, PROJECT_SETTINGS_FILE) : null;
6006
+ const raw = file ? readJson(file, null) : void 0;
6007
+ const fromFile = projectSettingsOf(raw);
6008
+ const same = projectMatcher(info.project);
6009
+ const entries = savedSettings().projects;
6010
+ let localKey = null;
6011
+ let fromEntry = projectSettingsOf(void 0);
6012
+ if (isObject4(entries)) {
6013
+ for (const [key, value] of Object.entries(entries)) {
6014
+ const path = projectPath(key);
6015
+ if (path && same(path)) {
6016
+ localKey = key;
6017
+ fromEntry = projectSettingsOf(value);
6018
+ break;
6019
+ }
6020
+ }
6021
+ }
6022
+ return {
6023
+ info,
6024
+ file,
6025
+ fileBroken: !!file && !isObject4(raw),
6026
+ project: fromFile.settings,
6027
+ projectIgnored: fromFile.ignored,
6028
+ localKey,
6029
+ local: fromEntry.settings,
6030
+ localIgnored: fromEntry.ignored
6031
+ };
6032
+ }
6033
+ function artifactsPlacement(workspace, harnessDefault) {
6034
+ const layers = projectLayers(workspace);
6035
+ const saved = savedSettings();
6036
+ const user = artifactsLocationOf(saved.artifactsLocation);
6037
+ const [location2, locationSource] = layers.local.artifactsLocation ? [layers.local.artifactsLocation, "local"] : layers.project.artifactsLocation ? [layers.project.artifactsLocation, "project"] : user ? [user, "user"] : harnessDefault ? [harnessDefault, "harness"] : ["home", "default"];
6038
+ const userDir = typeof saved.artifactsDir === "string" && saved.artifactsDir.trim() ? saved.artifactsDir.trim() : void 0;
6039
+ const [artifactsDir, artifactsDirSource] = layers.local.artifactsDir ? [layers.local.artifactsDir, "local"] : layers.project.artifactsDir ? [layers.project.artifactsDir, "project"] : userDir ? [userDir, "user"] : [DEFAULT_SETTINGS.artifactsDir, "default"];
6040
+ return { location: location2, locationSource, artifactsDir, artifactsDirSource, layers };
6041
+ }
6042
+ function workspaceArtifactsDir(workspace, placement) {
6043
+ const { info } = placement.layers;
6044
+ return join13(info.configDir ?? (placement.artifactsDirSource === "local" ? info.dir : resolve11(workspace)), placement.artifactsDir);
6045
+ }
6046
+ var isObject4, PROJECT_KEYS_TEXT;
5836
6047
  var init_settings2 = __esm({
5837
6048
  "packages/daemon/src/settings.ts"() {
5838
6049
  "use strict";
5839
6050
  init_src();
5840
6051
  init_paths();
6052
+ init_project();
6053
+ isObject4 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
6054
+ PROJECT_KEYS_TEXT = PROJECT_SETTINGS_KEYS.join(", ");
6055
+ }
6056
+ });
6057
+
6058
+ // packages/daemon/src/config.ts
6059
+ import { existsSync as existsSync8, rmSync as rmSync2, rmdirSync } from "node:fs";
6060
+ import { dirname as dirname8, isAbsolute as isAbsolute5, join as join14 } from "node:path";
6061
+ function fail(message4) {
6062
+ throw bad(message4);
6063
+ }
6064
+ function keyOf2(name, scope) {
6065
+ const key = typeof name === "string" ? name.trim() : "";
6066
+ if (ELSEWHERE[key]) throw bad(`${key} is set with ${ELSEWHERE[key]}.`);
6067
+ const known = KEYS[key];
6068
+ if (!known) throw bad(`${JSON.stringify(key)} is not a key config sets.`, `Keys: ${CONFIG_KEYS.join(", ")}.`);
6069
+ if (scope !== "user" && !known.project) throw bad(`${key} is not a project's to set.`, `A project sets: ${PROJECT_SETTINGS_KEYS.join(", ")}.`);
6070
+ return key;
6071
+ }
6072
+ function workspaceOf(request) {
6073
+ if (typeof request.workspace !== "string" || !isAbsolute5(request.workspace)) throw bad("workspace: the folder of the project (absolute).");
6074
+ return request.workspace;
6075
+ }
6076
+ function configSet(request) {
6077
+ const scope = request.scope ?? "user";
6078
+ if (scope !== "user" && scope !== "project" && scope !== "local") throw bad("scope: user, project or local.");
6079
+ const key = keyOf2(request.key, scope);
6080
+ const value = request.value === null || request.value === void 0 ? null : KEYS[key].parse(String(request.value), scope);
6081
+ if (scope === "user") {
6082
+ const saved = savedSettings();
6083
+ if (value === null) delete saved[key];
6084
+ else saved[key] = value;
6085
+ writeJson(files.settings(), saved);
6086
+ return { ok: true, key, value, scope, file: files.settings() };
6087
+ }
6088
+ const info = projectOf(workspaceOf(request));
6089
+ if (scope === "local") {
6090
+ const saved = savedSettings();
6091
+ const entries = isObject5(saved.projects) ? { ...saved.projects } : {};
6092
+ const same = projectMatcher(info.project);
6093
+ const name = Object.keys(entries).find((entry2) => same(projectPath(entry2))) ?? info.project;
6094
+ const entry = isObject5(entries[name]) ? { ...entries[name] } : {};
6095
+ if (value === null) delete entry[key];
6096
+ else entry[key] = value;
6097
+ if (Object.keys(entry).length) entries[name] = entry;
6098
+ else delete entries[name];
6099
+ if (Object.keys(entries).length) saved.projects = entries;
6100
+ else delete saved.projects;
6101
+ writeJson(files.settings(), saved);
6102
+ return { ok: true, key, value, scope, file: files.settings(), project: info.project };
6103
+ }
6104
+ const file = join14(info.dir, PROJECT_SETTINGS_FILE);
6105
+ if (samePath(file, files.settings())) throw bad("This folder has no project settings file of its own: that path is your own settings file.", "Leave out --project.");
6106
+ const raw = existsSync8(file) ? readJson(file, null) : {};
6107
+ if (!isObject5(raw)) throw bad(`${file} is not a JSON object.`, "Fix or remove it first.");
6108
+ if (value === null) delete raw[key];
6109
+ else raw[key] = value;
6110
+ if (Object.keys(raw).length) writeJson(file, raw);
6111
+ else if (existsSync8(file)) {
6112
+ rmSync2(file);
6113
+ try {
6114
+ rmdirSync(dirname8(file));
6115
+ } catch {
6116
+ }
6117
+ }
6118
+ return { ok: true, key, value, scope, file, project: info.project };
6119
+ }
6120
+ function configList(workspace, harness, harnessDefault) {
6121
+ const settings2 = loadSettings();
6122
+ const saved = savedSettings();
6123
+ const from = (key) => key in saved ? "user" : "default";
6124
+ const values = {
6125
+ homeWorkspace: {
6126
+ value: settings2.homeWorkspace,
6127
+ source: typeof saved.homeWorkspace === "string" ? "user" : process.env.OPEN_ARTIFACT_HOME_WORKSPACE ? "environment" : "default"
6128
+ },
6129
+ serverPort: { value: settings2.serverPort, source: process.env.OPEN_ARTIFACT_PORT ? "environment" : from("serverPort") }
6130
+ };
6131
+ if (!workspace) {
6132
+ const user = artifactsLocationOf(saved.artifactsLocation);
6133
+ return {
6134
+ file: files.settings(),
6135
+ workspace: null,
6136
+ harness,
6137
+ values: {
6138
+ artifactsLocation: user ? { value: user, source: "user" } : harnessDefault ? { value: harnessDefault, source: "harness" } : { value: "home", source: "default" },
6139
+ artifactsDir: { value: settings2.artifactsDir, source: from("artifactsDir") },
6140
+ ...values
6141
+ }
6142
+ };
6143
+ }
6144
+ const placement = artifactsPlacement(workspace, harnessDefault);
6145
+ const { layers } = placement;
6146
+ return {
6147
+ file: files.settings(),
6148
+ workspace,
6149
+ harness,
6150
+ values: {
6151
+ artifactsLocation: { value: placement.location, source: placement.locationSource },
6152
+ artifactsDir: { value: placement.artifactsDir, source: placement.artifactsDirSource },
6153
+ ...values
6154
+ },
6155
+ project: {
6156
+ path: layers.info.project,
6157
+ file: layers.file,
6158
+ ...layers.fileBroken ? { broken: true } : {},
6159
+ settings: layers.project,
6160
+ ignored: layers.projectIgnored,
6161
+ local: layers.local,
6162
+ localIgnored: layers.localIgnored
6163
+ }
6164
+ };
6165
+ }
6166
+ var isObject5, bad, KEYS, ELSEWHERE, CONFIG_KEYS;
6167
+ var init_config = __esm({
6168
+ "packages/daemon/src/config.ts"() {
6169
+ "use strict";
6170
+ init_src();
6171
+ init_paths();
6172
+ init_project();
6173
+ init_settings2();
6174
+ isObject5 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
6175
+ bad = (message4, fix) => new OpenArtifactError("invalid_argument", message4, fix ? { fix } : void 0);
6176
+ KEYS = {
6177
+ artifactsLocation: {
6178
+ project: true,
6179
+ parse: (value) => artifactsLocationOf(value) ?? fail("artifactsLocation is home or workspace.")
6180
+ },
6181
+ artifactsDir: {
6182
+ project: true,
6183
+ parse: (value, scope) => {
6184
+ const dir = value.trim();
6185
+ if (scope === "user") return dir || fail("artifactsDir is a folder name.");
6186
+ return projectArtifactsDirOf(dir) ?? fail("A project's artifactsDir is a relative path inside the project.");
6187
+ }
6188
+ },
6189
+ homeWorkspace: {
6190
+ project: false,
6191
+ parse: (value) => {
6192
+ const dir = value.trim();
6193
+ return dir.startsWith("~") || isAbsolute5(dir) ? dir : fail("homeWorkspace is an absolute path (or ~/...).");
6194
+ }
6195
+ },
6196
+ serverPort: {
6197
+ project: false,
6198
+ parse: (value) => {
6199
+ const port = Number(value);
6200
+ return Number.isInteger(port) && port > 0 && port < 65536 ? port : fail("serverPort is a port number.");
6201
+ }
6202
+ }
6203
+ };
6204
+ ELSEWHERE = {
6205
+ trustedProjects: "open-artifact types trust | untrust",
6206
+ disabledTypes: "open-artifact types enable | disable",
6207
+ cloud: "open-artifact remote default | auto",
6208
+ remotes: "open-artifact remote add | remove",
6209
+ runtime: "open-artifact runtime policy | pin",
6210
+ projects: "open-artifact config set <key> <value> --local, in the project",
6211
+ openInDesktop: "the Open Artifact Desktop app's settings"
6212
+ };
6213
+ CONFIG_KEYS = Object.keys(KEYS);
5841
6214
  }
5842
6215
  });
5843
6216
 
5844
6217
  // packages/daemon/src/type-authoring.ts
5845
6218
  import { randomUUID } from "node:crypto";
5846
- import { cpSync, existsSync as existsSync7, lstatSync as lstatSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync7, readdirSync as readdirSync7, rmSync as rmSync2, statSync as statSync4, writeFileSync as writeFileSync3 } from "node:fs";
5847
- import { basename as basename3, extname, join as join12, relative as relative4, resolve as resolve10, sep as sep5 } from "node:path";
6219
+ import { cpSync, existsSync as existsSync9, lstatSync as lstatSync2, mkdirSync as mkdirSync4, readFileSync as readFileSync8, readdirSync as readdirSync8, rmSync as rmSync3, statSync as statSync5, writeFileSync as writeFileSync3 } from "node:fs";
6220
+ import { basename as basename4, extname, join as join15, relative as relative6, resolve as resolve12, sep as sep7 } from "node:path";
5848
6221
  function checkNewTypeId(id) {
5849
6222
  const value = typeof id === "string" ? id.trim() : "";
5850
6223
  if (!TYPE_ID.test(value) || value !== value.toLowerCase()) {
@@ -5857,16 +6230,16 @@ function checkNewTypeId(id) {
5857
6230
  return value;
5858
6231
  }
5859
6232
  function authoringRoot(settings2, scope, project) {
5860
- if (scope === "user") return resolve10(settings2.typeRoots.user);
6233
+ if (scope === "user") return resolve12(settings2.typeRoots.user);
5861
6234
  if (!project) throw new OpenArtifactError("invalid_argument", "A project type needs the project folder.");
5862
- return resolve10(project, settings2.typeRoots.project);
6235
+ return resolve12(project, settings2.typeRoots.project);
5863
6236
  }
5864
6237
  function makeFolder(root, id) {
5865
- const dir = join12(root, id);
5866
- if (existsSync7(dir)) throw new OpenArtifactError("conflict", `${dir} is there already: pick another id, or change that type.`);
5867
- mkdirSync3(root, { recursive: true });
6238
+ const dir = join15(root, id);
6239
+ if (existsSync9(dir)) throw new OpenArtifactError("conflict", `${dir} is there already: pick another id, or change that type.`);
6240
+ mkdirSync4(root, { recursive: true });
5868
6241
  try {
5869
- mkdirSync3(dir);
6242
+ mkdirSync4(dir);
5870
6243
  } catch (error) {
5871
6244
  if (error.code === "EEXIST") throw new OpenArtifactError("conflict", `${dir} is there already.`);
5872
6245
  throw error;
@@ -5875,8 +6248,8 @@ function makeFolder(root, id) {
5875
6248
  }
5876
6249
  function writeAll(dir, written) {
5877
6250
  for (const [rel, text3] of Object.entries(written)) {
5878
- const file = join12(dir, rel);
5879
- mkdirSync3(join12(file, ".."), { recursive: true });
6251
+ const file = join15(dir, rel);
6252
+ mkdirSync4(join15(file, ".."), { recursive: true });
5880
6253
  writeFileSync3(file, text3);
5881
6254
  }
5882
6255
  return Object.keys(written).sort();
@@ -5894,7 +6267,7 @@ function newType(args, o) {
5894
6267
  const scope = scopeOf(args.scope);
5895
6268
  const template = templateOf(args.template);
5896
6269
  const name = nameOf(args.name, id);
5897
- const project = typeof args.project === "string" && args.project ? resolve10(args.project) : o.workspace ?? null;
6270
+ const project = typeof args.project === "string" && args.project ? resolve12(args.project) : o.workspace ?? null;
5898
6271
  const dir = makeFolder(authoringRoot(o.settings, scope, project), id);
5899
6272
  const uid = randomUUID();
5900
6273
  try {
@@ -5902,7 +6275,7 @@ function newType(args, o) {
5902
6275
  const check = checkType(dir, { ...o, workspace: scope === "project" ? project : o.workspace });
5903
6276
  return { id, uid, scope, dir, files: written, check, prompt: buildOutPrompt(name, id, dir) };
5904
6277
  } catch (error) {
5905
- rmSync2(dir, { recursive: true, force: true });
6278
+ rmSync3(dir, { recursive: true, force: true });
5906
6279
  throw error;
5907
6280
  }
5908
6281
  }
@@ -6120,13 +6493,13 @@ function checkType(dir, o) {
6120
6493
  const add = (p, level) => {
6121
6494
  (level === "error" ? errors : warnings).push({ level, ...p });
6122
6495
  };
6123
- const id = basename3(dir);
6496
+ const id = basename4(dir);
6124
6497
  const forShare = o.forShare === true;
6125
6498
  const out2 = () => ({ ok: errors.length === 0, id, dir, forShare, errors, warnings, ...caps ? { capabilities: caps } : {} });
6126
6499
  let caps;
6127
6500
  let st;
6128
6501
  try {
6129
- st = statSync4(dir);
6502
+ st = statSync5(dir);
6130
6503
  } catch {
6131
6504
  add({ code: "not_found", message: `${dir} is not there.` }, "error");
6132
6505
  return out2();
@@ -6136,17 +6509,17 @@ function checkType(dir, o) {
6136
6509
  return out2();
6137
6510
  }
6138
6511
  const builtinRoot = o.registry.roots().find((r) => r.scope === "builtin")?.root ?? null;
6139
- const isBuiltin = builtinRoot !== null && resolve10(dir) === resolve10(builtinRoot, id);
6512
+ const isBuiltin = builtinRoot !== null && resolve12(dir) === resolve12(builtinRoot, id);
6140
6513
  if (!TYPE_ID.test(id)) add({ code: "id_invalid", message: `The folder name ${JSON.stringify(id)} is not a type id: letters, digits, ".", "_" and "-", at most 64.` }, "error");
6141
6514
  else if (!isBuiltin && BUILTIN_TYPE_IDS.includes(id)) add({ code: "id_builtin", message: `${id} is a built-in type's id: this type would hide it. Rename the folder.` }, "error");
6142
6515
  else if (RESERVED_TYPE_IDS.includes(id)) add({ code: "id_reserved", message: `${id} is reserved. Rename the folder.` }, "error");
6143
- const manifestFile = join12(dir, "artifact-type.json");
6516
+ const manifestFile = join15(dir, "artifact-type.json");
6144
6517
  let manifest = null;
6145
- if (!existsSync7(manifestFile)) {
6518
+ if (!existsSync9(manifestFile)) {
6146
6519
  add({ code: "manifest_missing", file: "artifact-type.json", message: "There is no artifact-type.json: the type has no name, version or description of its own." }, forShare ? "error" : "warning");
6147
6520
  } else {
6148
6521
  try {
6149
- const parsed = JSON.parse(readFileSync7(manifestFile, "utf8"));
6522
+ const parsed = JSON.parse(readFileSync8(manifestFile, "utf8"));
6150
6523
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) add({ code: "manifest_invalid", file: "artifact-type.json", message: "artifact-type.json is not a JSON object." }, "error");
6151
6524
  else manifest = parsed;
6152
6525
  } catch (error) {
@@ -6161,7 +6534,7 @@ function checkType(dir, o) {
6161
6534
  if (typeof manifest.version !== "string" || !manifest.version) add({ code: "version_missing", file: "artifact-type.json", message: 'There is no "version".' }, "warning");
6162
6535
  }
6163
6536
  }
6164
- const info = readTypeFolder(dir, { root: resolve10(dir, ".."), scope: "user", trusted: true });
6537
+ const info = readTypeFolder(dir, { root: resolve12(dir, ".."), scope: "user", trusted: true });
6165
6538
  if (info) {
6166
6539
  for (const problem of info.problems) {
6167
6540
  if (problem.startsWith("artifact-type.json is not valid JSON")) continue;
@@ -6171,9 +6544,9 @@ function checkType(dir, o) {
6171
6544
  } else if (TYPE_ID.test(id)) {
6172
6545
  add({ code: "not_a_type", message: "This folder has neither index.html nor artifact-type.json." }, "error");
6173
6546
  }
6174
- const indexFile = join12(dir, "index.html");
6175
- if (existsSync7(indexFile)) {
6176
- const html = readFileSync7(indexFile, "utf8");
6547
+ const indexFile = join15(dir, "index.html");
6548
+ if (existsSync9(indexFile)) {
6549
+ const html = readFileSync8(indexFile, "utf8");
6177
6550
  if (DECLARATION_LINE.test(html) || declarationSource(html)) {
6178
6551
  try {
6179
6552
  const decl = readStaticDeclaration(html);
@@ -6190,7 +6563,7 @@ function checkType(dir, o) {
6190
6563
  const problem = capabilitiesProblem(decl.capabilities);
6191
6564
  if (problem) add({ code: "capabilities_invalid", file: "index.html", message: problem }, "error");
6192
6565
  caps = { backed: [], stubbed: [], unknown: [] };
6193
- for (const [name, config] of Object.entries(decl.capabilities)) {
6566
+ for (const [name, config2] of Object.entries(decl.capabilities)) {
6194
6567
  const status = capabilityStatus(name);
6195
6568
  if (status === "backed") caps.backed.push(name);
6196
6569
  else if (status === "stubbed") {
@@ -6200,7 +6573,7 @@ function checkType(dir, o) {
6200
6573
  caps.unknown.push(name);
6201
6574
  add({ code: "capability_unknown", file: "index.html", message: `${name} is not a capability Open Artifact knows.` }, "error");
6202
6575
  }
6203
- if (config === false) add({ code: "capability_false", file: "index.html", message: `${name} is false: leave it out instead (frame-host grants a declared name either way).` }, "warning");
6576
+ if (config2 === false) add({ code: "capability_false", file: "index.html", message: `${name} is false: leave it out instead (frame-host grants a declared name either way).` }, "warning");
6204
6577
  }
6205
6578
  } catch (error) {
6206
6579
  if (!(error instanceof DeclarationError)) throw error;
@@ -6210,18 +6583,18 @@ function checkType(dir, o) {
6210
6583
  }
6211
6584
  if (manifest?.skill !== false) {
6212
6585
  const skillName = typeof manifest?.skill === "string" ? manifest.skill : "SKILL.md";
6213
- const skillFile2 = resolve10(dir, skillName);
6214
- if (!skillFile2.startsWith(resolve10(dir) + sep5) || !existsSync7(skillFile2)) {
6586
+ const skillFile2 = resolve12(dir, skillName);
6587
+ if (!skillFile2.startsWith(resolve12(dir) + sep7) || !existsSync9(skillFile2)) {
6215
6588
  add({ code: "skill_missing", file: skillName, message: `There is no ${skillName}: agents would not know how to make one.` }, "error");
6216
6589
  } else {
6217
- const fm = readFrontmatter(readFileSync7(skillFile2, "utf8"));
6590
+ const fm = readFrontmatter(readFileSync8(skillFile2, "utf8"));
6218
6591
  for (const field of ["name", "description"]) {
6219
6592
  if (!fm[field]?.trim()) add({ code: "skill_frontmatter", file: skillName, message: `${skillName} has no "${field}" in its frontmatter.` }, "error");
6220
6593
  }
6221
6594
  }
6222
6595
  }
6223
6596
  const listed3 = o.registry.list(o.workspace ?? void 0, { includeShadowed: true });
6224
- const self = listed3.find((t) => resolve10(t.dir) === resolve10(dir));
6597
+ const self = listed3.find((t) => resolve12(t.dir) === resolve12(dir));
6225
6598
  if (self) {
6226
6599
  if (self.shadowedBy) add({ code: "shadowed", message: `A ${self.shadowedBy} type of the same id wins over this one.` }, "warning");
6227
6600
  const hidden = listed3.filter((t) => t.id === id && t !== self && t.shadowedBy);
@@ -6248,9 +6621,9 @@ function shareFileProblems(dir) {
6248
6621
  function packageFolderEntries(dir) {
6249
6622
  const out2 = [];
6250
6623
  const walk = (folder) => {
6251
- for (const name of readdirSync7(folder).sort()) {
6252
- const full = join12(folder, name);
6253
- const rel = relative4(dir, full).split(sep5).join("/");
6624
+ for (const name of readdirSync8(folder).sort()) {
6625
+ const full = join15(folder, name);
6626
+ const rel = relative6(dir, full).split(sep7).join("/");
6254
6627
  const st = lstatSync2(full);
6255
6628
  if (st.isDirectory()) {
6256
6629
  out2.push({ path: `${rel}/`, kind: "dir", size: 0 });
@@ -6262,10 +6635,10 @@ function packageFolderEntries(dir) {
6262
6635
  return out2;
6263
6636
  }
6264
6637
  function typeDirOf(target, registry, workspace, cwd = process.cwd()) {
6265
- if (target === "." || target === ".." || target.includes("/") || target.includes(sep5)) return resolve10(cwd, target);
6638
+ if (target === "." || target === ".." || target.includes("/") || target.includes(sep7)) return resolve12(cwd, target);
6266
6639
  const type = registry.list(workspace ?? void 0, { includeShadowed: false }).find((t) => t.id === target);
6267
6640
  if (type) return type.dir;
6268
- if (existsSync7(resolve10(cwd, target, "artifact-type.json")) || existsSync7(resolve10(cwd, target, "index.html"))) return resolve10(cwd, target);
6641
+ if (existsSync9(resolve12(cwd, target, "artifact-type.json")) || existsSync9(resolve12(cwd, target, "index.html"))) return resolve12(cwd, target);
6269
6642
  throw new OpenArtifactError("not_found", `No type ${target}.`, { fix: "open-artifact types list shows the types; or give the folder (./my-type)." });
6270
6643
  }
6271
6644
  function typeFromPage(record, type, args, o) {
@@ -6274,7 +6647,7 @@ function typeFromPage(record, type, args, o) {
6274
6647
  }
6275
6648
  const html = (() => {
6276
6649
  try {
6277
- return readFileSync7(join12(record.root, "index.html"), "utf8");
6650
+ return readFileSync8(join15(record.root, "index.html"), "utf8");
6278
6651
  } catch {
6279
6652
  throw new OpenArtifactError("not_found", `${record.title} has no index.html yet.`);
6280
6653
  }
@@ -6282,7 +6655,7 @@ function typeFromPage(record, type, args, o) {
6282
6655
  const id = checkNewTypeId(args.id);
6283
6656
  const scope = scopeOf(args.scope);
6284
6657
  const name = nameOf(args.name ?? record.title, id);
6285
- const project = typeof args.project === "string" && args.project ? resolve10(args.project) : o.workspace ?? null;
6658
+ const project = typeof args.project === "string" && args.project ? resolve12(args.project) : o.workspace ?? null;
6286
6659
  const capabilities = record.capabilities && typeof record.capabilities === "object" ? record.capabilities : {};
6287
6660
  const dir = makeFolder(authoringRoot(o.settings, scope, project), id);
6288
6661
  const uid = randomUUID();
@@ -6320,10 +6693,10 @@ files).
6320
6693
  `
6321
6694
  };
6322
6695
  const filesOut = writeAll(dir, written);
6323
- const own = join12(record.root, "artifact-type");
6324
- if (existsSync7(own) && statSync4(own).isDirectory()) {
6325
- cpSync(own, join12(dir, "artifact-type"), { recursive: true, dereference: false, filter: (src) => !basename3(src).startsWith(".") && !lstatSync2(src).isSymbolicLink() });
6326
- for (const f of listFiles(join12(dir, "artifact-type"))) filesOut.push(`artifact-type/${f}`);
6696
+ const own = join15(record.root, "artifact-type");
6697
+ if (existsSync9(own) && statSync5(own).isDirectory()) {
6698
+ cpSync(own, join15(dir, "artifact-type"), { recursive: true, dereference: false, filter: (src) => !basename4(src).startsWith(".") && !lstatSync2(src).isSymbolicLink() });
6699
+ for (const f of listFiles(join15(dir, "artifact-type"))) filesOut.push(`artifact-type/${f}`);
6327
6700
  }
6328
6701
  const skipped = skippedOf(record.root);
6329
6702
  const check = checkType(dir, { ...o, workspace: scope === "project" ? project : o.workspace });
@@ -6333,7 +6706,7 @@ files).
6333
6706
  ];
6334
6707
  return { id, uid, scope, dir, files: filesOut.sort(), check, prompt: buildOutPrompt(name, id, dir), skipped, ...notes.length ? { notes } : {} };
6335
6708
  } catch (error) {
6336
- rmSync2(dir, { recursive: true, force: true });
6709
+ rmSync3(dir, { recursive: true, force: true });
6337
6710
  throw error;
6338
6711
  }
6339
6712
  }
@@ -6426,13 +6799,13 @@ function iconOf(folder, meta) {
6426
6799
  const icon = meta?.icon;
6427
6800
  const file = icon && typeof icon === "object" && !Array.isArray(icon) ? icon.file : void 0;
6428
6801
  if (file === void 0) return null;
6429
- if (typeof file !== "string" || !file || file !== basename3(file) || file.startsWith(".") || file.includes("\\") || file.includes("\0")) {
6802
+ if (typeof file !== "string" || !file || file !== basename4(file) || file.startsWith(".") || file.includes("\\") || file.includes("\0")) {
6430
6803
  return { problem: `metadata.json names the icon ${JSON.stringify(file)}: an icon is a file name in the folder; not copied.` };
6431
6804
  }
6432
6805
  if (!ICON_TYPES.has(extname(file).toLowerCase())) return { problem: `The icon ${file} is not an image Open Artifact shows (${[...ICON_TYPES].join(", ")}); not copied.` };
6433
6806
  let st;
6434
6807
  try {
6435
- st = lstatSync2(join12(folder, file));
6808
+ st = lstatSync2(join15(folder, file));
6436
6809
  } catch {
6437
6810
  return { problem: `metadata.json names the icon ${file}, which is not in the folder; not copied.` };
6438
6811
  }
@@ -6441,19 +6814,19 @@ function iconOf(folder, meta) {
6441
6814
  return { file };
6442
6815
  }
6443
6816
  function typeFromSaved(path, args, o) {
6444
- const source = resolve10(path);
6817
+ const source = resolve12(path);
6445
6818
  let st;
6446
6819
  try {
6447
- st = statSync4(source);
6820
+ st = statSync5(source);
6448
6821
  } catch {
6449
6822
  throw new OpenArtifactError("not_found", `${source} is not there.`);
6450
6823
  }
6451
6824
  const folder = st.isDirectory() ? source : null;
6452
- const indexFile = folder ? join12(folder, "index.html") : source;
6825
+ const indexFile = folder ? join15(folder, "index.html") : source;
6453
6826
  if (!folder && !/\.html?$/i.test(source)) throw new OpenArtifactError("invalid_argument", `${source} is neither a folder nor an .html file.`);
6454
6827
  let indexSt;
6455
6828
  try {
6456
- indexSt = statSync4(indexFile);
6829
+ indexSt = statSync5(indexFile);
6457
6830
  } catch {
6458
6831
  throw new OpenArtifactError("not_found", `${folder} has no index.html.`);
6459
6832
  }
@@ -6461,17 +6834,17 @@ function typeFromSaved(path, args, o) {
6461
6834
  if (indexSt.size > TYPE_PACKAGE_LIMITS.fileBytes) throw new OpenArtifactError("too_large", `${indexFile} is over ${TYPE_PACKAGE_LIMITS.fileBytes / 1024 / 1024} MB.`);
6462
6835
  const id = checkNewTypeId(args.id);
6463
6836
  const scope = scopeOf(args.scope);
6464
- const project = typeof args.project === "string" && args.project ? resolve10(args.project) : o.workspace ?? null;
6465
- const original = readFileSync7(indexFile, "utf8");
6837
+ const project = typeof args.project === "string" && args.project ? resolve12(args.project) : o.workspace ?? null;
6838
+ const original = readFileSync8(indexFile, "utf8");
6466
6839
  const stripped = stripFrameRuntime(original);
6467
6840
  const used = capabilitiesUsed(stripped);
6468
6841
  const { html, declared } = withInferredCapabilities(stripped, id, used.inferred);
6469
6842
  const capabilities = declared ? { inferred: [], stubbed: [], unknown: used.unknown, declared } : used;
6470
6843
  const notes = [];
6471
6844
  let meta = null;
6472
- if (folder && existsSync7(join12(folder, "metadata.json"))) {
6845
+ if (folder && existsSync9(join15(folder, "metadata.json"))) {
6473
6846
  try {
6474
- const parsed = JSON.parse(readFileSync7(join12(folder, "metadata.json"), "utf8"));
6847
+ const parsed = JSON.parse(readFileSync8(join15(folder, "metadata.json"), "utf8"));
6475
6848
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) meta = parsed;
6476
6849
  else notes.push("metadata.json is not a JSON object: it was not read.");
6477
6850
  } catch {
@@ -6520,10 +6893,10 @@ artifact of this type is a folder, \`<root>\`, whose files and data the page rea
6520
6893
  `, "index.html": html, "SKILL.md": skill };
6521
6894
  const filesOut = writeAll(dir, written);
6522
6895
  if (icon?.file) {
6523
- cpSync(join12(folder, icon.file), join12(dir, icon.file));
6896
+ cpSync(join15(folder, icon.file), join15(dir, icon.file));
6524
6897
  filesOut.push(icon.file);
6525
6898
  }
6526
- const skipped = folder ? readdirSync7(folder, { withFileTypes: true }).map((e) => e.isDirectory() ? `${e.name}/` : e.name).filter((n) => n !== "index.html" && n !== "metadata.json" && n !== icon?.file && !n.startsWith(".")).sort() : [];
6899
+ const skipped = folder ? readdirSync8(folder, { withFileTypes: true }).map((e) => e.isDirectory() ? `${e.name}/` : e.name).filter((n) => n !== "index.html" && n !== "metadata.json" && n !== icon?.file && !n.startsWith(".")).sort() : [];
6527
6900
  const check = checkType(dir, { ...o, workspace: scope === "project" ? project : o.workspace });
6528
6901
  if (stripped !== original) notes.push("The frame runtime inlined in the page (<!-- frame-runtime --> … <!-- /frame-runtime -->) was taken out: frame-host serves its own.");
6529
6902
  if (!declared && capabilities.inferred.length) notes.push(`Declared the capabilities the page uses: ${capabilities.inferred.join(", ")}.`);
@@ -6532,7 +6905,7 @@ artifact of this type is a folder, \`<root>\`, whose files and data the page rea
6532
6905
  notes.push(SAVED_PAGE_NOTE);
6533
6906
  return { id, uid: String(manifest.uid), scope, dir, files: filesOut.sort(), check, prompt: buildOutPrompt(name, id, dir), skipped, notes, capabilities, source };
6534
6907
  } catch (error) {
6535
- rmSync2(dir, { recursive: true, force: true });
6908
+ rmSync3(dir, { recursive: true, force: true });
6536
6909
  throw error;
6537
6910
  }
6538
6911
  }
@@ -6556,20 +6929,20 @@ ${html}`;
6556
6929
  }
6557
6930
  function listFiles(dir, base = "") {
6558
6931
  const out2 = [];
6559
- for (const e of readdirSync7(dir, { withFileTypes: true })) {
6932
+ for (const e of readdirSync8(dir, { withFileTypes: true })) {
6560
6933
  const rel = base ? `${base}/${e.name}` : e.name;
6561
- if (e.isDirectory()) out2.push(...listFiles(join12(dir, e.name), rel));
6934
+ if (e.isDirectory()) out2.push(...listFiles(join15(dir, e.name), rel));
6562
6935
  else out2.push(rel);
6563
6936
  }
6564
6937
  return out2;
6565
6938
  }
6566
6939
  function skippedOf(root) {
6567
6940
  const out2 = [];
6568
- for (const e of readdirSync7(root, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
6941
+ for (const e of readdirSync8(root, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
6569
6942
  if (e.name === "index.html" || e.name === "artifact-type") continue;
6570
6943
  if (e.isDirectory()) {
6571
6944
  if (COLLAPSED.has(e.name) || e.name.startsWith(".")) out2.push(`${e.name}/`);
6572
- else out2.push(...listFiles(join12(root, e.name), e.name));
6945
+ else out2.push(...listFiles(join15(root, e.name), e.name));
6573
6946
  } else out2.push(e.name);
6574
6947
  }
6575
6948
  return out2;
@@ -6591,9 +6964,9 @@ function setTypeEnabled(id, enabled) {
6591
6964
  function setProjectTrusted(dir, trusted) {
6592
6965
  const value = typeof dir === "string" ? dir.trim() : "";
6593
6966
  if (!value || !value.startsWith("/") && !/^[A-Za-z]:[\\/]/.test(value)) throw new OpenArtifactError("invalid_argument", "dir: the project folder, as an absolute path.");
6594
- const full = resolve10(value);
6967
+ const full = resolve12(value);
6595
6968
  const lists = savedLists();
6596
- const next = lists.trustedProjects.filter((p) => resolve10(p) !== full);
6969
+ const next = lists.trustedProjects.filter((p) => resolve12(p) !== full);
6597
6970
  if (trusted) next.push(full);
6598
6971
  saveSettings({ trustedProjects: next });
6599
6972
  return { ok: true, disabledTypes: lists.disabledTypes, trustedProjects: next };
@@ -6728,7 +7101,7 @@ description: >-
6728
7101
  import { randomBytes as randomBytes5 } from "node:crypto";
6729
7102
  import { constants } from "node:fs";
6730
7103
  import { lstat, mkdir, open, readdir, readFile, rename, rm, stat } from "node:fs/promises";
6731
- import { basename as basename4, dirname as dirname7, extname as extname2, join as join13, resolve as resolve11, sep as sep6 } from "node:path";
7104
+ import { basename as basename5, dirname as dirname9, extname as extname2, join as join16, resolve as resolve13, sep as sep8 } from "node:path";
6732
7105
  import { promisify } from "node:util";
6733
7106
  import { deflateRaw as deflateRawCallback, inflateRaw as inflateRawCallback, inflateRawSync } from "node:zlib";
6734
7107
  function view(bytes) {
@@ -6794,9 +7167,9 @@ function archiveKeeps(path) {
6794
7167
  return true;
6795
7168
  }
6796
7169
  async function archiveEntries(root, skip = []) {
6797
- const top = resolve11(root);
6798
- const folder = basename4(top) || "artifact";
6799
- const skipped = new Set(skip.map((file) => resolve11(file)));
7170
+ const top = resolve13(root);
7171
+ const folder = basename5(top) || "artifact";
7172
+ const skipped = new Set(skip.map((file) => resolve13(file)));
6800
7173
  const entries = [];
6801
7174
  const walk = async (dir, rel) => {
6802
7175
  let names;
@@ -6810,7 +7183,7 @@ async function archiveEntries(root, skip = []) {
6810
7183
  const name = dirent.name;
6811
7184
  const inner = rel ? `${rel}/${name}` : name;
6812
7185
  if (!keepsStep(rel, name, inner)) continue;
6813
- const file = join13(dir, name);
7186
+ const file = join16(dir, name);
6814
7187
  if (skipped.has(file)) continue;
6815
7188
  if (dirent.isDirectory()) await walk(file, inner);
6816
7189
  else if (dirent.isFile()) {
@@ -6913,7 +7286,7 @@ async function writeZip(entries, write) {
6913
7286
  }
6914
7287
  function archiveFileName(root, now2 = /* @__PURE__ */ new Date()) {
6915
7288
  const day = `${now2.getFullYear()}-${String(now2.getMonth() + 1).padStart(2, "0")}-${String(now2.getDate()).padStart(2, "0")}`;
6916
- return `${basename4(resolve11(root)) || "artifact"}-${day}.zip`;
7289
+ return `${basename5(resolve13(root)) || "artifact"}-${day}.zip`;
6917
7290
  }
6918
7291
  function attachmentHeader(name) {
6919
7292
  const ascii = name.replace(/[^\x20-\x7e]|["\\]/g, "_");
@@ -6948,14 +7321,14 @@ async function sendArchive(req, res, root) {
6948
7321
  await writeZip(entries, (chunk) => {
6949
7322
  if (closed || res.destroyed) return Promise.reject(new Error("The connection closed."));
6950
7323
  if (res.write(chunk)) return Promise.resolve();
6951
- return new Promise((done, fail) => {
7324
+ return new Promise((done, fail2) => {
6952
7325
  const onDrain = () => {
6953
7326
  res.off("close", onClose);
6954
7327
  done();
6955
7328
  };
6956
7329
  const onClose = () => {
6957
7330
  res.off("drain", onDrain);
6958
- fail(new Error("The connection closed."));
7331
+ fail2(new Error("The connection closed."));
6959
7332
  };
6960
7333
  res.once("drain", onDrain);
6961
7334
  res.once("close", onClose);
@@ -7051,9 +7424,9 @@ async function writeNewFile(file, data, mode2 = 420) {
7051
7424
  }
7052
7425
  }
7053
7426
  async function unpackZip(bytes, files2, dest, maxBytes) {
7054
- const target = resolve11(dest);
7055
- await mkdir(dirname7(target), { recursive: true });
7056
- const temp = join13(dirname7(target), `.${basename4(target)}.${randomBytes5(6).toString("hex")}.unpack`);
7427
+ const target = resolve13(dest);
7428
+ await mkdir(dirname9(target), { recursive: true });
7429
+ const temp = join16(dirname9(target), `.${basename5(target)}.${randomBytes5(6).toString("hex")}.unpack`);
7057
7430
  await mkdir(temp);
7058
7431
  try {
7059
7432
  let total = 0;
@@ -7061,9 +7434,9 @@ async function unpackZip(bytes, files2, dest, maxBytes) {
7061
7434
  const data = await unpackZipFile(bytes, item);
7062
7435
  total += data.length;
7063
7436
  if (total > maxBytes) throw new ZipRefusal("too_large", `It unpacks to more than ${maxBytes} bytes.`);
7064
- const file = resolve11(temp, ...item.path.split("/"));
7065
- if (!file.startsWith(temp + sep6)) throw new ZipRefusal("invalid", `${item.path} would land outside its folder.`);
7066
- await mkdir(dirname7(file), { recursive: true });
7437
+ const file = resolve13(temp, ...item.path.split("/"));
7438
+ if (!file.startsWith(temp + sep8)) throw new ZipRefusal("invalid", `${item.path} would land outside its folder.`);
7439
+ await mkdir(dirname9(file), { recursive: true });
7067
7440
  await writeNewFile(file, data, item.mode);
7068
7441
  }
7069
7442
  return { temp, files: files2.length, bytes: total };
@@ -7145,7 +7518,7 @@ var init_zip = __esm({
7145
7518
  });
7146
7519
 
7147
7520
  // packages/server-sdk/src/type-package.ts
7148
- import { createHash as createHash3 } from "node:crypto";
7521
+ import { createHash as createHash4 } from "node:crypto";
7149
7522
  async function checkTypePackage(bytes, source, o = {}) {
7150
7523
  let checked;
7151
7524
  try {
@@ -7221,7 +7594,7 @@ ${listed(manifestProblems)}`);
7221
7594
  capabilities,
7222
7595
  network: networkOrigins(manifest),
7223
7596
  skill: skillText !== null && skillPath ? { path: skillPath, text: skillText } : null,
7224
- sha256: createHash3("sha256").update(bytes).digest("hex"),
7597
+ sha256: createHash4("sha256").update(bytes).digest("hex"),
7225
7598
  bytes: bytes.byteLength
7226
7599
  };
7227
7600
  }
@@ -7236,9 +7609,9 @@ var init_type_package2 = __esm({
7236
7609
  });
7237
7610
 
7238
7611
  // packages/daemon/src/type-packages.ts
7239
- import { createHash as createHash4 } from "node:crypto";
7240
- import { existsSync as existsSync8, readFileSync as readFileSync8, readdirSync as readdirSync8, renameSync as renameSync4, rmSync as rmSync3, statSync as statSync5, writeFileSync as writeFileSync4 } from "node:fs";
7241
- import { basename as basename5, join as join14, resolve as resolve12, sep as sep7 } from "node:path";
7612
+ import { createHash as createHash5 } from "node:crypto";
7613
+ import { existsSync as existsSync10, readFileSync as readFileSync9, readdirSync as readdirSync9, renameSync as renameSync4, rmSync as rmSync4, statSync as statSync6, writeFileSync as writeFileSync4 } from "node:fs";
7614
+ import { basename as basename6, join as join17, resolve as resolve14, sep as sep9 } from "node:path";
7242
7615
  function installedIndex() {
7243
7616
  const read = readJson(files.typesIndex(), null);
7244
7617
  const types3 = {};
@@ -7262,12 +7635,12 @@ ${check.errors.map((e) => ` - ${e.message}`).join("\n")}`, {
7262
7635
  fix: `Fix what open-artifact types check ${dir} --for-share lists, then pack it again.`
7263
7636
  });
7264
7637
  }
7265
- const manifest = JSON.parse(readFileSync8(join14(dir, "artifact-type.json"), "utf8"));
7266
- const id = basename5(resolve12(dir));
7638
+ const manifest = JSON.parse(readFileSync9(join17(dir, "artifact-type.json"), "utf8"));
7639
+ const id = basename6(resolve14(dir));
7267
7640
  const version = String(manifest.version);
7268
7641
  const entries = packageFolderEntries(dir).filter((e) => e.kind === "file").map((e) => {
7269
- const file = join14(dir, ...e.path.split("/"));
7270
- const st = statSync5(file);
7642
+ const file = join17(dir, ...e.path.split("/"));
7643
+ const st = statSync6(file);
7271
7644
  return { name: `${id}/${e.path}`, file, size: st.size, mode: st.mode & 511, mtime: st.mtime };
7272
7645
  });
7273
7646
  const bytes = await zipBytes(entries);
@@ -7276,8 +7649,8 @@ ${check.errors.map((e) => ` - ${e.message}`).join("\n")}`, {
7276
7649
  async function packType(dir, o) {
7277
7650
  const packed = await packTypeBytes(dir, o);
7278
7651
  const cwd = o.cwd ?? process.cwd();
7279
- const where2 = o.out ? resolve12(cwd, o.out) : cwd;
7280
- const file = existsSync8(where2) && statSync5(where2).isDirectory() ? join14(where2, packageFileName(packed.id, packed.version)) : where2;
7652
+ const where2 = o.out ? resolve14(cwd, o.out) : cwd;
7653
+ const file = existsSync10(where2) && statSync6(where2).isDirectory() ? join17(where2, packageFileName(packed.id, packed.version)) : where2;
7281
7654
  writeFileAtomic(file, packed.bytes);
7282
7655
  return { id: packed.id, version: packed.version, file, sha256: packed.sha256, bytes: packed.bytes.length, files: packed.files };
7283
7656
  }
@@ -7291,8 +7664,8 @@ async function readTypePackage(bytes, source, o = {}) {
7291
7664
  fix: `Install it under another id: open-artifact types install ${source} --as <id>.`
7292
7665
  });
7293
7666
  }
7294
- const folder = join14(files.installedTypes(), id);
7295
- if (!known && existsSync8(folder)) {
7667
+ const folder = join17(files.installedTypes(), id);
7668
+ if (!known && existsSync10(folder)) {
7296
7669
  throw new OpenArtifactError("conflict", `${folder} exists but is not in ${files.typesIndex()}: it was not installed by open-artifact types install.`, {
7297
7670
  fix: `Move that folder away, or install this one under another id with --as <id>.`
7298
7671
  });
@@ -7354,9 +7727,9 @@ async function fetchTypePackageAnswer(address, o = {}) {
7354
7727
  const response = await fetch(url, { redirect: "manual", credentials: "omit", signal, headers: { accept: "application/zip, application/octet-stream" } });
7355
7728
  if (response.status >= 300 && response.status < 400) {
7356
7729
  void response.body?.cancel().catch(() => void 0);
7357
- const location = response.headers.get("location");
7358
- if (!location || hop >= MAX_REDIRECTS) throw new OpenArtifactError("download_failed", `${address} answered with a redirect (${response.status}) that is not followed.`);
7359
- const next = allowedUrl(new URL(location, url).href);
7730
+ const location2 = response.headers.get("location");
7731
+ if (!location2 || hop >= MAX_REDIRECTS) throw new OpenArtifactError("download_failed", `${address} answered with a redirect (${response.status}) that is not followed.`);
7732
+ const next = allowedUrl(new URL(location2, url).href);
7360
7733
  if (next.protocol !== scheme) throw new OpenArtifactError("redirected", `${address} redirects to ${next.protocol}//: a package is fetched with the scheme it was asked for.`);
7361
7734
  url = next;
7362
7735
  continue;
@@ -7407,16 +7780,16 @@ function allowedUrl(address) {
7407
7780
  }
7408
7781
  async function loadTypePackage(target, cwd = process.cwd()) {
7409
7782
  if (isAddress(target)) return { bytes: await fetchTypePackage(target), source: target };
7410
- const file = resolve12(cwd, target);
7783
+ const file = resolve14(cwd, target);
7411
7784
  let st;
7412
7785
  try {
7413
- st = statSync5(file);
7786
+ st = statSync6(file);
7414
7787
  } catch {
7415
7788
  throw new OpenArtifactError("not_found", `${file} is not there.`);
7416
7789
  }
7417
7790
  if (!st.isFile()) throw refuse(`${file} is not a file.`);
7418
7791
  if (st.size > PACKAGE_DOWNLOAD_MAX) throw new OpenArtifactError("too_large", `${file} is ${st.size} bytes, more than a type package may be.`);
7419
- return { bytes: readFileSync8(file), source: file };
7792
+ return { bytes: readFileSync9(file), source: file };
7420
7793
  }
7421
7794
  async function installTypePackage(pkg, o = {}) {
7422
7795
  const { preview } = pkg;
@@ -7426,7 +7799,7 @@ async function installTypePackage(pkg, o = {}) {
7426
7799
  });
7427
7800
  }
7428
7801
  const root = ensureDir(files.installedTypes());
7429
- const dest = join14(root, preview.id);
7802
+ const dest = join17(root, preview.id);
7430
7803
  let unpacked;
7431
7804
  try {
7432
7805
  unpacked = await unpackZip(
@@ -7446,18 +7819,18 @@ async function installTypePackage(pkg, o = {}) {
7446
7819
  if (again.length) throw new OpenArtifactError("bad_archive", `${preview.source} did not unpack as it declared:
7447
7820
  ${listed2(again)}`);
7448
7821
  const known = installedEntry(preview.id);
7449
- if (existsSync8(dest)) {
7822
+ if (existsSync10(dest)) {
7450
7823
  if (!known || known.uid !== preview.uid) throw new OpenArtifactError("conflict", `${dest} exists and is not an install of this type.`);
7451
- aside = join14(root, `.${preview.id}.${Date.now().toString(36)}.old`);
7824
+ aside = join17(root, `.${preview.id}.${Date.now().toString(36)}.old`);
7452
7825
  renameSync4(dest, aside);
7453
7826
  }
7454
7827
  await moveIntoPlace(temp, dest);
7455
7828
  } catch (error) {
7456
- rmSync3(temp, { recursive: true, force: true });
7457
- if (aside && !existsSync8(dest)) renameSync4(aside, dest);
7829
+ rmSync4(temp, { recursive: true, force: true });
7830
+ if (aside && !existsSync10(dest)) renameSync4(aside, dest);
7458
7831
  throw error;
7459
7832
  }
7460
- if (aside) rmSync3(aside, { recursive: true, force: true });
7833
+ if (aside) rmSync4(aside, { recursive: true, force: true });
7461
7834
  const entry = {
7462
7835
  id: preview.id,
7463
7836
  uid: preview.uid,
@@ -7475,14 +7848,14 @@ ${listed2(again)}`);
7475
7848
  function uninstallType(id) {
7476
7849
  if (!TYPE_ID.test(id)) throw refuse(`${JSON.stringify(id)} is not a type id.`);
7477
7850
  const index = installedIndex();
7478
- const dir = join14(files.installedTypes(), id);
7851
+ const dir = join17(files.installedTypes(), id);
7479
7852
  if (!Object.hasOwn(index.types, id)) {
7480
7853
  throw new OpenArtifactError("not_found", `${id} is not an installed type.`, { fix: "open-artifact types list shows each type with its source; only installed ones are uninstalled." });
7481
7854
  }
7482
- if (existsSync8(dir)) {
7483
- const aside = join14(files.installedTypes(), `.${id}.${Date.now().toString(36)}.removed`);
7855
+ if (existsSync10(dir)) {
7856
+ const aside = join17(files.installedTypes(), `.${id}.${Date.now().toString(36)}.removed`);
7484
7857
  renameSync4(dir, aside);
7485
- rmSync3(aside, { recursive: true, force: true });
7858
+ rmSync4(aside, { recursive: true, force: true });
7486
7859
  }
7487
7860
  delete index.types[id];
7488
7861
  writeIndex(index);
@@ -7496,23 +7869,23 @@ function updateSource(id) {
7496
7869
  function stagePackage(bytes, source) {
7497
7870
  const dir = ensureDir(files.typesStaging());
7498
7871
  const now2 = Date.now();
7499
- for (const name of readdirSync8(dir)) {
7872
+ for (const name of readdirSync9(dir)) {
7500
7873
  try {
7501
- if (now2 - statSync5(join14(dir, name)).mtimeMs > 36e5) rmSync3(join14(dir, name), { force: true });
7874
+ if (now2 - statSync6(join17(dir, name)).mtimeMs > 36e5) rmSync4(join17(dir, name), { force: true });
7502
7875
  } catch {
7503
7876
  }
7504
7877
  }
7505
7878
  const hash = sha256(bytes);
7506
- writeFileSync4(join14(dir, `${hash}${TYPE_PACKAGE_EXTENSION}`), bytes);
7507
- writeFileSync4(join14(dir, `${hash}.json`), JSON.stringify({ source }));
7879
+ writeFileSync4(join17(dir, `${hash}${TYPE_PACKAGE_EXTENSION}`), bytes);
7880
+ writeFileSync4(join17(dir, `${hash}.json`), JSON.stringify({ source }));
7508
7881
  return hash;
7509
7882
  }
7510
7883
  function stagedPackage(hash) {
7511
7884
  if (!/^[0-9a-f]{64}$/.test(hash)) throw refuse("sha256 is the hex digest the preview gave.");
7512
7885
  const dir = files.typesStaging();
7513
7886
  try {
7514
- const bytes = readFileSync8(join14(dir, `${hash}${TYPE_PACKAGE_EXTENSION}`));
7515
- const { source } = JSON.parse(readFileSync8(join14(dir, `${hash}.json`), "utf8"));
7887
+ const bytes = readFileSync9(join17(dir, `${hash}${TYPE_PACKAGE_EXTENSION}`));
7888
+ const { source } = JSON.parse(readFileSync9(join17(dir, `${hash}.json`), "utf8"));
7516
7889
  if (sha256(bytes) !== hash) throw new Error("changed");
7517
7890
  return { bytes, source: String(source) };
7518
7891
  } catch {
@@ -7521,11 +7894,11 @@ function stagedPackage(hash) {
7521
7894
  }
7522
7895
  function unstagePackage(hash) {
7523
7896
  if (!/^[0-9a-f]{64}$/.test(hash)) return;
7524
- for (const ext of [TYPE_PACKAGE_EXTENSION, ".json"]) rmSync3(join14(files.typesStaging(), `${hash}${ext}`), { force: true });
7897
+ for (const ext of [TYPE_PACKAGE_EXTENSION, ".json"]) rmSync4(join17(files.typesStaging(), `${hash}${ext}`), { force: true });
7525
7898
  }
7526
7899
  function typeCapabilities(dir) {
7527
7900
  try {
7528
- const decl = readStaticDeclaration(readFileSync8(join14(dir, "index.html"), "utf8"));
7901
+ const decl = readStaticDeclaration(readFileSync9(join17(dir, "index.html"), "utf8"));
7529
7902
  return decl ? Object.keys(decl.capabilities) : [];
7530
7903
  } catch {
7531
7904
  return [];
@@ -7540,7 +7913,7 @@ function typeSourceOf(type) {
7540
7913
  function markerSourceOf(type) {
7541
7914
  const { source, installedFrom } = typeSourceOf(type);
7542
7915
  if (!installedFrom) return source;
7543
- return isAddress(installedFrom) ? installedFrom : basename5(installedFrom);
7916
+ return isAddress(installedFrom) ? installedFrom : basename6(installedFrom);
7544
7917
  }
7545
7918
  function typeMismatch(record, type) {
7546
7919
  if (!record.typeUid || !type) return null;
@@ -7579,16 +7952,16 @@ var init_type_packages = __esm({
7579
7952
  listed2 = (problems) => problems.map((p) => ` - ${p.message}`).join("\n");
7580
7953
  plainLine = (text3) => text3.replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/g, " ").slice(0, 200);
7581
7954
  isAddress = (target) => /^[a-z][a-z0-9+.-]*:\/\//i.test(target);
7582
- sha256 = (bytes) => createHash4("sha256").update(bytes).digest("hex");
7955
+ sha256 = (bytes) => createHash5("sha256").update(bytes).digest("hex");
7583
7956
  }
7584
7957
  });
7585
7958
 
7586
7959
  // packages/daemon/src/runtime.ts
7587
- import { createHash as createHash5, randomBytes as randomBytes6 } from "node:crypto";
7588
- import { appendFileSync, chmodSync, cpSync as cpSync2, existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync as readdirSync9, readFileSync as readFileSync10, renameSync as renameSync5, rmSync as rmSync4, statSync as statSync6, writeFileSync as writeFileSync6 } from "node:fs";
7960
+ import { createHash as createHash6, randomBytes as randomBytes6 } from "node:crypto";
7961
+ import { appendFileSync, chmodSync, cpSync as cpSync2, existsSync as existsSync12, mkdirSync as mkdirSync6, readdirSync as readdirSync10, readFileSync as readFileSync11, renameSync as renameSync5, rmSync as rmSync5, statSync as statSync7, writeFileSync as writeFileSync6 } from "node:fs";
7589
7962
  import { cp } from "node:fs/promises";
7590
- import { homedir as homedir4 } from "node:os";
7591
- import { dirname as dirname8, isAbsolute as isAbsolute3, join as join16, relative as relative5, resolve as resolve14, sep as sep8 } from "node:path";
7963
+ import { homedir as homedir5 } from "node:os";
7964
+ import { dirname as dirname10, isAbsolute as isAbsolute6, join as join19, relative as relative7, resolve as resolve16, sep as sep10 } from "node:path";
7592
7965
  import { gunzipSync } from "node:zlib";
7593
7966
  function runtimeLog(line) {
7594
7967
  try {
@@ -7620,7 +7993,7 @@ function saveRuntimeSettings(patch) {
7620
7993
  function machinePolicyFile(env = process.env) {
7621
7994
  if (env.OPEN_ARTIFACT_MACHINE_POLICY) return env.OPEN_ARTIFACT_MACHINE_POLICY;
7622
7995
  if (process.platform === "darwin") return "/Library/Application Support/Open Artifact/policy.json";
7623
- if (process.platform === "win32") return join16(env.ProgramData || "C:\\ProgramData", "Open Artifact", "policy.json");
7996
+ if (process.platform === "win32") return join19(env.ProgramData || "C:\\ProgramData", "Open Artifact", "policy.json");
7624
7997
  return "/etc/open-artifact/policy.json";
7625
7998
  }
7626
7999
  function machineOff(env = process.env) {
@@ -7667,7 +8040,7 @@ function npmrc(file) {
7667
8040
  const out2 = {};
7668
8041
  let text3;
7669
8042
  try {
7670
- text3 = readFileSync10(file, "utf8");
8043
+ text3 = readFileSync11(file, "utf8");
7671
8044
  } catch {
7672
8045
  return out2;
7673
8046
  }
@@ -7680,7 +8053,7 @@ function npmrc(file) {
7680
8053
  function registryUrl(env = process.env) {
7681
8054
  const scope = "@open-artifact:registry";
7682
8055
  const lower = (name) => env[name] ?? env[name.toUpperCase()];
7683
- const rc = npmrc(env.NPM_CONFIG_USERCONFIG || env.npm_config_userconfig || join16(homedir4(), ".npmrc"));
8056
+ const rc = npmrc(env.NPM_CONFIG_USERCONFIG || env.npm_config_userconfig || join19(homedir5(), ".npmrc"));
7684
8057
  const named2 = env.OPEN_ARTIFACT_REGISTRY || runtimeSettings().registry || lower(`npm_config_${scope}`) || lower("npm_config_registry") || rc[scope] || rc.registry || DEFAULT_REGISTRY;
7685
8058
  return named2.endsWith("/") ? named2 : `${named2}/`;
7686
8059
  }
@@ -7751,7 +8124,7 @@ function sha512Of(integrity) {
7751
8124
  function verifyIntegrity(data, integrity) {
7752
8125
  const wanted = sha512Of(integrity);
7753
8126
  if (!wanted.length) throw new OpenArtifactError("integrity_failed", "The registry gives no sha512 integrity for this version; it is not installed.");
7754
- const actual = createHash5("sha512").update(data).digest("base64");
8127
+ const actual = createHash6("sha512").update(data).digest("base64");
7755
8128
  if (!wanted.includes(actual)) {
7756
8129
  throw new OpenArtifactError("integrity_failed", `The downloaded tarball does not match the registry's integrity (sha512-${actual.slice(0, 16)}…); it is not installed.`);
7757
8130
  }
@@ -7903,38 +8276,38 @@ function readTarball(gz) {
7903
8276
  return entries;
7904
8277
  }
7905
8278
  function writeEntries(entries, dest) {
7906
- const root = resolve14(dest);
7907
- mkdirSync5(root, { recursive: true });
8279
+ const root = resolve16(dest);
8280
+ mkdirSync6(root, { recursive: true });
7908
8281
  for (const entry of entries) {
7909
- const target = resolve14(root, ...safeTarPath(entry.path));
7910
- const rel = relative5(root, target);
7911
- if (!rel || rel.startsWith("..") || isAbsolute3(rel)) throw new OpenArtifactError("bad_archive", `The package has a path outside its folder: ${entry.path}.`);
8282
+ const target = resolve16(root, ...safeTarPath(entry.path));
8283
+ const rel = relative7(root, target);
8284
+ if (!rel || rel.startsWith("..") || isAbsolute6(rel)) throw new OpenArtifactError("bad_archive", `The package has a path outside its folder: ${entry.path}.`);
7912
8285
  if (entry.type === "dir") {
7913
- mkdirSync5(target, { recursive: true, mode: 493 });
8286
+ mkdirSync6(target, { recursive: true, mode: 493 });
7914
8287
  continue;
7915
8288
  }
7916
- mkdirSync5(dirname8(target), { recursive: true, mode: 493 });
8289
+ mkdirSync6(dirname10(target), { recursive: true, mode: 493 });
7917
8290
  writeFileSync6(target, entry.data, { mode: entry.mode & 73 ? 493 : 420 });
7918
8291
  chmodSync(target, entry.mode & 73 ? 493 : 420);
7919
8292
  }
7920
8293
  }
7921
8294
  function publishFolder(staging, version) {
7922
- const target = join16(sharedRuntimesOf(openArtifactHome2()), version);
8295
+ const target = join19(sharedRuntimesOf(openArtifactHome2()), version);
7923
8296
  try {
7924
8297
  renameSync5(staging, target);
7925
8298
  } catch (error) {
7926
- rmSync4(staging, { recursive: true, force: true });
8299
+ rmSync5(staging, { recursive: true, force: true });
7927
8300
  if (!runtimeInfo(target)) throw error;
7928
8301
  }
7929
8302
  return target;
7930
8303
  }
7931
8304
  function stagingFolder(version) {
7932
8305
  const root = ensureDir(sharedRuntimesOf(openArtifactHome2()));
7933
- return join16(root, `.staging-${version}-${process.pid}-${randomBytes6(4).toString("hex")}`);
8306
+ return join19(root, `.staging-${version}-${process.pid}-${randomBytes6(4).toString("hex")}`);
7934
8307
  }
7935
8308
  async function installFromRegistry(manifest, registry) {
7936
8309
  const version = manifest.version;
7937
- const existing = join16(sharedRuntimesOf(openArtifactHome2()), version);
8310
+ const existing = join19(sharedRuntimesOf(openArtifactHome2()), version);
7938
8311
  if (runtimeInfo(existing)) return existing;
7939
8312
  const tarball = manifest.dist.tarball;
7940
8313
  const response = await get(tarball, "application/octet-stream", 12e4);
@@ -7944,19 +8317,19 @@ async function installFromRegistry(manifest, registry) {
7944
8317
  const staging = stagingFolder(version);
7945
8318
  try {
7946
8319
  writeEntries(entries, staging);
7947
- const pkg = readJson(join16(staging, "package.json"), null);
8320
+ const pkg = readJson(join19(staging, "package.json"), null);
7948
8321
  if (pkg?.name !== RUNTIME_PACKAGE || pkg.version !== version) {
7949
8322
  throw new OpenArtifactError("bad_archive", `The tarball is not ${RUNTIME_PACKAGE}@${version} (its package.json says ${String(pkg?.name)}@${String(pkg?.version)}).`);
7950
8323
  }
7951
8324
  if (!runtimeInfo(staging)) throw new OpenArtifactError("bad_archive", "The tarball has no scripts/open-artifact.mjs.");
7952
8325
  const record = { version, integrity: String(manifest.dist.integrity), tarball, registry, installedAt: (/* @__PURE__ */ new Date()).toISOString(), attestation: attestationOf(manifest) };
7953
- writeFileSync6(join16(staging, ".install.json"), `${JSON.stringify(record, null, 2)}
8326
+ writeFileSync6(join19(staging, ".install.json"), `${JSON.stringify(record, null, 2)}
7954
8327
  `);
7955
8328
  const dir = publishFolder(staging, version);
7956
8329
  runtimeLog(`installed ${RUNTIME_PACKAGE}@${version} in ${dir} (sha512 verified; attestation ${record.attestation.present ? "present, not verified" : "absent"})`);
7957
8330
  return dir;
7958
8331
  } catch (error) {
7959
- rmSync4(staging, { recursive: true, force: true });
8332
+ rmSync5(staging, { recursive: true, force: true });
7960
8333
  throw error;
7961
8334
  }
7962
8335
  }
@@ -7966,19 +8339,19 @@ function pruneShared(keep = []) {
7966
8339
  const shared = sharedRuntimes(openArtifactHome2());
7967
8340
  for (const runtime2 of shared.slice(KEEP_SHARED)) {
7968
8341
  if (keep.includes(runtime2.version)) continue;
7969
- rmSync4(runtime2.dir, { recursive: true, force: true });
8342
+ rmSync5(runtime2.dir, { recursive: true, force: true });
7970
8343
  removed.push(runtime2.version);
7971
8344
  }
7972
8345
  let names = [];
7973
8346
  try {
7974
- names = readdirSync9(root);
8347
+ names = readdirSync10(root);
7975
8348
  } catch {
7976
8349
  return removed;
7977
8350
  }
7978
8351
  for (const name of names) {
7979
8352
  if (!name.startsWith(".staging-")) continue;
7980
8353
  try {
7981
- if (Date.now() - statSync6(join16(root, name)).mtimeMs > 60 * 6e4) rmSync4(join16(root, name), { recursive: true, force: true });
8354
+ if (Date.now() - statSync7(join19(root, name)).mtimeMs > 60 * 6e4) rmSync5(join19(root, name), { recursive: true, force: true });
7982
8355
  } catch {
7983
8356
  }
7984
8357
  }
@@ -8068,8 +8441,8 @@ function runtimeStatusText(status) {
8068
8441
  }
8069
8442
  function runtimeOfHello(value) {
8070
8443
  const runtime2 = value;
8071
- if (!runtime2 || typeof runtime2 !== "object" || typeof runtime2.dir !== "string" || !isAbsolute3(runtime2.dir) || typeof runtime2.version !== "string" || !parseVersion(runtime2.version)) return null;
8072
- return { dir: resolve14(runtime2.dir), version: runtime2.version, ...isPolicy(runtime2.update) ? { update: runtime2.update } : {} };
8444
+ if (!runtime2 || typeof runtime2 !== "object" || typeof runtime2.dir !== "string" || !isAbsolute6(runtime2.dir) || typeof runtime2.version !== "string" || !parseVersion(runtime2.version)) return null;
8445
+ return { dir: resolve16(runtime2.dir), version: runtime2.version, ...isPolicy(runtime2.update) ? { update: runtime2.update } : {} };
8073
8446
  }
8074
8447
  var RUNTIME_PACKAGE, DEFAULT_REGISTRY, CHECK_INTERVAL_MS, MAX_TARBALL, MAX_UNPACKED, MAX_METADATA, ADAPTER_MEMORY_MS, KEEP_SHARED, runtimeCheckFile, POLICIES, isPolicy, STRICTNESS, text, sourceOf, RuntimeManager;
8075
8448
  var init_runtime = __esm({
@@ -8086,7 +8459,7 @@ var init_runtime = __esm({
8086
8459
  MAX_METADATA = 32 << 20;
8087
8460
  ADAPTER_MEMORY_MS = 90 * 24 * 60 * 6e4;
8088
8461
  KEEP_SHARED = 3;
8089
- runtimeCheckFile = () => join16(openArtifactHome2(), "runtime-update.json");
8462
+ runtimeCheckFile = () => join19(openArtifactHome2(), "runtime-update.json");
8090
8463
  POLICIES = ["auto", "prompt", "bundled"];
8091
8464
  isPolicy = (value) => POLICIES.includes(value);
8092
8465
  STRICTNESS = { auto: 0, prompt: 1, bundled: 2 };
@@ -8133,7 +8506,7 @@ var init_runtime = __esm({
8133
8506
  /** Records a runtime in `runtimes.json` (one entry per folder) and copies it into the shared folder when it is the newest. */
8134
8507
  register(record) {
8135
8508
  this.writeFile((file) => {
8136
- file.runtimes = [...file.runtimes.filter((r) => resolve14(r.dir) !== resolve14(record.dir)), { ...record, seenAt: (/* @__PURE__ */ new Date()).toISOString() }];
8509
+ file.runtimes = [...file.runtimes.filter((r) => resolve16(r.dir) !== resolve16(record.dir)), { ...record, seenAt: (/* @__PURE__ */ new Date()).toISOString() }];
8137
8510
  });
8138
8511
  this.adopt(record);
8139
8512
  }
@@ -8143,17 +8516,17 @@ var init_runtime = __esm({
8143
8516
  */
8144
8517
  adopt(record) {
8145
8518
  const home2 = openArtifactHome2();
8146
- if (this.copying || !existsSync10(join16(record.dir, "vendor", "open-artifact.mjs"))) return;
8147
- if (resolve14(record.dir).startsWith(resolve14(sharedRuntimesOf(home2)) + sep8)) return;
8519
+ if (this.copying || !existsSync12(join19(record.dir, "vendor", "open-artifact.mjs"))) return;
8520
+ if (resolve16(record.dir).startsWith(resolve16(sharedRuntimesOf(home2)) + sep10)) return;
8148
8521
  const newest = sharedRuntimes(home2)[0]?.version;
8149
8522
  if (newest && compareVersions(record.version, newest) <= 0) return;
8150
8523
  const staging = stagingFolder(record.version);
8151
- this.copying = cp(record.dir, staging, { recursive: true, verbatimSymlinks: true, filter: (from) => !from.split(sep8).includes("node_modules") }).then(() => {
8524
+ this.copying = cp(record.dir, staging, { recursive: true, verbatimSymlinks: true, filter: (from) => !from.split(sep10).includes("node_modules") }).then(() => {
8152
8525
  const dir = publishFolder(staging, record.version);
8153
8526
  this.options.log(`runtime: kept a copy of ${record.harness ?? "a host"}'s runtime ${record.version} in ${dir}`);
8154
8527
  pruneShared([record.version, this.options.version]);
8155
8528
  }).catch((error) => {
8156
- rmSync4(staging, { recursive: true, force: true });
8529
+ rmSync5(staging, { recursive: true, force: true });
8157
8530
  this.options.log(`runtime: could not copy ${record.dir}: ${error?.message ?? error}`);
8158
8531
  }).finally(() => {
8159
8532
  this.copying = null;
@@ -8246,7 +8619,7 @@ var init_runtime = __esm({
8246
8619
  import { spawn as spawn3 } from "node:child_process";
8247
8620
  import { EventEmitter as EventEmitter4 } from "node:events";
8248
8621
  import { realpathSync as realpathSync4 } from "node:fs";
8249
- import { isAbsolute as isAbsolute4, resolve as resolve15 } from "node:path";
8622
+ import { isAbsolute as isAbsolute8, resolve as resolve18 } from "node:path";
8250
8623
  import { PassThrough } from "node:stream";
8251
8624
  import { Worker } from "node:worker_threads";
8252
8625
  function modeFromEnv(env = process.env) {
@@ -8281,7 +8654,7 @@ function startChild(start) {
8281
8654
  function threadEntry(args, cwd) {
8282
8655
  const at = args.findIndex((arg) => !arg.startsWith("-"));
8283
8656
  if (at < 0) throw new Error(`no script to run in ${JSON.stringify(args)}`);
8284
- const given = isAbsolute4(args[at]) ? args[at] : resolve15(cwd, args[at]);
8657
+ const given = isAbsolute8(args[at]) ? args[at] : resolve18(cwd, args[at]);
8285
8658
  let script = given;
8286
8659
  try {
8287
8660
  script = realpathSync4(given);
@@ -8411,8 +8784,8 @@ import(pathToFileURL(workerData.script).href).catch((error) => {
8411
8784
 
8412
8785
  // packages/daemon/src/servers.ts
8413
8786
  import { randomBytes as randomBytes7 } from "node:crypto";
8414
- import { createWriteStream, statSync as statSync7 } from "node:fs";
8415
- import { dirname as dirname9, join as join18 } from "node:path";
8787
+ import { createWriteStream, statSync as statSync9 } from "node:fs";
8788
+ import { dirname as dirname12, join as join22 } from "node:path";
8416
8789
  function parseActions(raw) {
8417
8790
  if (!Array.isArray(raw)) return [];
8418
8791
  const out2 = [];
@@ -8485,7 +8858,7 @@ async function cappedText(type, url, response, max = REMOTE_ANSWER_MAX) {
8485
8858
  function stampOf(type) {
8486
8859
  let mtime = 0;
8487
8860
  try {
8488
- mtime = statSync7(join18(type.dir, "artifact-type.json")).mtimeMs;
8861
+ mtime = statSync9(join22(type.dir, "artifact-type.json")).mtimeMs;
8489
8862
  } catch {
8490
8863
  }
8491
8864
  return JSON.stringify([type.dir, type.version, mtime, type.entry, type.trusted]);
@@ -8504,12 +8877,12 @@ var init_servers = __esm({
8504
8877
  ACTION_CALL_MS = 9e4;
8505
8878
  serverFiles = {
8506
8879
  /** Last address and pid (`servers/<type>.json`), to reuse the port. */
8507
- state: (type) => join18(files.servers(), `${type}.json`),
8880
+ state: (type) => join22(files.servers(), `${type}.json`),
8508
8881
  /** The server's own state folder (`OPEN_ARTIFACT_STATE_DIR`). */
8509
- stateDir: (type) => join18(files.servers(), type),
8510
- log: (type) => join18(files.logs(), "servers", `${type}.log`),
8882
+ stateDir: (type) => join22(files.servers(), type),
8883
+ log: (type) => join22(files.logs(), "servers", `${type}.log`),
8511
8884
  /** The last action list the server gave (`servers/<type>.actions.json`). */
8512
- actions: (type) => join18(files.servers(), `${type}.actions.json`)
8885
+ actions: (type) => join22(files.servers(), `${type}.actions.json`)
8513
8886
  };
8514
8887
  ACTION_NAME = /^[a-z0-9_-][a-z0-9_.-]{0,63}$/i;
8515
8888
  where = (type, url) => typeLocation(type).remote ? `${url.origin}${url.pathname}` : url.pathname;
@@ -8682,15 +9055,15 @@ var init_servers = __esm({
8682
9055
  * sent. Local types are not checked.
8683
9056
  */
8684
9057
  async reach(type, timeoutMs = REACH_MS) {
8685
- const location = typeLocation(type);
8686
- if (!location.remote || type.entry?.kind !== "url") return;
9058
+ const location2 = typeLocation(type);
9059
+ if (!location2.remote || type.entry?.kind !== "url") return;
8687
9060
  const entry = type.entry;
8688
9061
  const probe2 = entry.open || entry.actions || entry.share ? new URL(TYPE_SERVER_ROUTES.health.replace(/^\//, ""), templateBase(entry.url)) : new URL(templateBase(entry.url));
8689
9062
  try {
8690
9063
  const response = await fetch(probe2, { method: "GET", signal: AbortSignal.timeout(timeoutMs), redirect: "manual" });
8691
9064
  await response.body?.cancel().catch(() => void 0);
8692
9065
  } catch (error) {
8693
- throw new OpenArtifactError("server_failed", `${type.title || type.id} lives at ${location.origin}, on another computer, and ${probe2.href} could not be reached (${failureOf(error, timeoutMs)}).`, {
9066
+ throw new OpenArtifactError("server_failed", `${type.title || type.id} lives at ${location2.origin}, on another computer, and ${probe2.href} could not be reached (${failureOf(error, timeoutMs)}).`, {
8694
9067
  fix: 'Check the network connection and that the address is right, then try again; or pick a type that runs on this computer (Artifact {action: "list", scope: "types"}: remote is false).'
8695
9068
  });
8696
9069
  }
@@ -8774,7 +9147,7 @@ var init_servers = __esm({
8774
9147
  const mode2 = isNode ? this.nodeMode() : "process";
8775
9148
  const last = readJson(serverFiles.state(type.id), null);
8776
9149
  const secret = randomBytes7(24).toString("base64url");
8777
- ensureDir(dirname9(serverFiles.log(type.id)));
9150
+ ensureDir(dirname12(serverFiles.log(type.id)));
8778
9151
  const stateDir = ensureDir(serverFiles.stateDir(type.id));
8779
9152
  const log = createWriteStream(serverFiles.log(type.id), { flags: "a" });
8780
9153
  log.write(`
@@ -8810,14 +9183,14 @@ var init_servers = __esm({
8810
9183
  s.state = "starting";
8811
9184
  let settled = false;
8812
9185
  let buffered = "";
8813
- const fail = (message4) => {
9186
+ const fail2 = (message4) => {
8814
9187
  if (settled) return;
8815
9188
  settled = true;
8816
9189
  clearTimeout(timer);
8817
9190
  child.stop(KILL_MS);
8818
9191
  rejectReady(new Error(message4));
8819
9192
  };
8820
- const timer = setTimeout(() => fail(`no ready line within ${readyMs / 1e3} s`), readyMs);
9193
+ const timer = setTimeout(() => fail2(`no ready line within ${readyMs / 1e3} s`), readyMs);
8821
9194
  child.stderr?.pipe(log, { end: false });
8822
9195
  child.stdout?.on("data", (chunk) => {
8823
9196
  log.write(chunk);
@@ -8836,7 +9209,7 @@ var init_servers = __esm({
8836
9209
  }
8837
9210
  if (message4?.openArtifact !== "ready") continue;
8838
9211
  if (typeof message4.url !== "string" || !/^http:\/\//.test(message4.url) || !isLoopbackUrl(message4.url)) {
8839
- fail(`its ready line has no loopback url: ${line.slice(0, 200)}`);
9212
+ fail2(`its ready line has no loopback url: ${line.slice(0, 200)}`);
8840
9213
  return;
8841
9214
  }
8842
9215
  settled = true;
@@ -8853,7 +9226,7 @@ var init_servers = __esm({
8853
9226
  return;
8854
9227
  }
8855
9228
  });
8856
- child.on("error", (error) => fail(`could not run ${start.command}: ${error.message}`));
9229
+ child.on("error", (error) => fail2(`could not run ${start.command}: ${error.message}`));
8857
9230
  child.on("exit", (code, signal) => {
8858
9231
  log.write(`--- exit ${code ?? signal}
8859
9232
  `);
@@ -8866,7 +9239,7 @@ var init_servers = __esm({
8866
9239
  s.base = null;
8867
9240
  if (was) this.options.changed?.();
8868
9241
  }
8869
- fail(`it exited (${code ?? signal}) before it was ready`);
9242
+ fail2(`it exited (${code ?? signal}) before it was ready`);
8870
9243
  });
8871
9244
  });
8872
9245
  }
@@ -8960,14 +9333,14 @@ __export(chatgpt_exports, {
8960
9333
  serveChatGpt: () => serveChatGpt
8961
9334
  });
8962
9335
  import { randomBytes as randomBytes8, timingSafeEqual } from "node:crypto";
8963
- import { existsSync as existsSync12, readFileSync as readFileSync12 } from "node:fs";
9336
+ import { existsSync as existsSync15, readFileSync as readFileSync14 } from "node:fs";
8964
9337
  import { createServer } from "node:http";
8965
- import { join as join20 } from "node:path";
9338
+ import { join as join24 } from "node:path";
8966
9339
  function chatgptSecret(rotate = false) {
8967
- const file = join20(openArtifactHome2(), "chatgpt.json");
8968
- if (!rotate && existsSync12(file)) {
9340
+ const file = join24(openArtifactHome2(), "chatgpt.json");
9341
+ if (!rotate && existsSync15(file)) {
8969
9342
  try {
8970
- const secret2 = JSON.parse(readFileSync12(file, "utf8")).secret;
9343
+ const secret2 = JSON.parse(readFileSync14(file, "utf8")).secret;
8971
9344
  if (secret2 && /^[A-Za-z0-9_-]{24,}$/.test(secret2)) return secret2;
8972
9345
  } catch {
8973
9346
  }
@@ -9120,9 +9493,9 @@ ${CHATGPT_NOTE}`.trim();
9120
9493
  if (!res.headersSent) res.writeHead(500, { "Content-Type": "application/json" }).end(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }));
9121
9494
  });
9122
9495
  });
9123
- await new Promise((resolve18, reject) => {
9496
+ await new Promise((resolve21, reject) => {
9124
9497
  server.once("error", reject);
9125
- server.listen(options.port, "127.0.0.1", () => resolve18());
9498
+ server.listen(options.port, "127.0.0.1", () => resolve21());
9126
9499
  });
9127
9500
  return server;
9128
9501
  }
@@ -9176,7 +9549,7 @@ button:disabled{opacity:.55;cursor:default}
9176
9549
  .hint{color:var(--muted);font-size:12.5px;padding:0 16px 12px}
9177
9550
  </style></head><body>
9178
9551
  <div class="card">
9179
- <svg class="icon" viewBox="0 0 64 64" aria-hidden="true"><rect x="8" y="8" width="30" height="30" rx="6" fill="#2f5bb7"/><rect x="26" y="26" width="30" height="30" rx="6" fill="#6f8fd4" stroke="#fff" stroke-width="3"/><circle cx="41" cy="41" r="6" fill="#fff"/></svg>
9552
+ <svg class="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="color:var(--accent)" aria-hidden="true"><path d="M15 9V6a3 3 0 0 0-3-3H6a3 3 0 0 0-3 3v6a3 3 0 0 0 3 3h3"/><rect x="9" y="9" width="12" height="12" rx="3"/><circle cx="15" cy="15" r="2" fill="currentColor" stroke="none"/></svg>
9180
9553
  <div class="text"><div class="title" id="title">Open Artifact</div><div class="meta" id="meta">Loading…</div></div>
9181
9554
  <div class="actions"><button id="open" disabled>Open</button><button id="send" class="primary" disabled>Send comments to ChatGPT</button></div>
9182
9555
  </div>
@@ -9221,38 +9594,38 @@ button:disabled{opacity:.55;cursor:default}
9221
9594
  });
9222
9595
 
9223
9596
  // packages/daemon/src/data-refresh.ts
9224
- import { existsSync as existsSync13, readFileSync as readFileSync13, readdirSync as readdirSync10 } from "node:fs";
9225
- import { join as join21 } from "node:path";
9597
+ import { existsSync as existsSync16, readFileSync as readFileSync15, readdirSync as readdirSync11 } from "node:fs";
9598
+ import { join as join25 } from "node:path";
9226
9599
  function hasSnapshot(root) {
9227
- return existsSync13(join21(root, "db", "data", "live.json")) || existsSync13(join21(root, "db", "data", "live", "answers"));
9600
+ return existsSync16(join25(root, "db", "data", "live.json")) || existsSync16(join25(root, "db", "data", "live", "answers"));
9228
9601
  }
9229
9602
  function liveQueryIds(root) {
9230
9603
  let names;
9231
9604
  try {
9232
- names = readdirSync10(join21(root, "db", "datasets"));
9605
+ names = readdirSync11(join25(root, "db", "datasets"));
9233
9606
  } catch {
9234
9607
  return [];
9235
9608
  }
9236
9609
  const ids = [];
9237
9610
  for (const name of names.sort()) {
9238
9611
  if (!name.endsWith(".json")) continue;
9239
- const doc = readJson2(join21(root, "db", "datasets", name));
9240
- if (!isObject4(doc) || doc.snapshot === false || !isObject4(doc.source)) continue;
9612
+ const doc = readJson2(join25(root, "db", "datasets", name));
9613
+ if (!isObject7(doc) || doc.snapshot === false || !isObject7(doc.source)) continue;
9241
9614
  if (doc.source.kind === "call" || doc.source.kind === "query") ids.push(name.slice(0, -5));
9242
9615
  }
9243
9616
  return ids;
9244
9617
  }
9245
9618
  function snapshotStatusOf(root) {
9246
- const doc = readJson2(join21(root, "db", "data", "live.json"));
9247
- if (!isObject4(doc)) return { at: null, failed: null };
9248
- const failed = isObject4(doc.failed) && typeof doc.failed.reason === "string" ? doc.failed.reason : null;
9619
+ const doc = readJson2(join25(root, "db", "data", "live.json"));
9620
+ if (!isObject7(doc)) return { at: null, failed: null };
9621
+ const failed = isObject7(doc.failed) && typeof doc.failed.reason === "string" ? doc.failed.reason : null;
9249
9622
  return { at: typeof doc.at === "string" && doc.at ? doc.at : null, failed };
9250
9623
  }
9251
9624
  function refreshMinutes(settings2) {
9252
9625
  const value = settings2.cloud?.dataRefresh;
9253
9626
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : DEFAULT_DATA_REFRESH_MINUTES;
9254
9627
  }
9255
- var DATA_TYPE, TICK_MS, message2, readJson2, isObject4, DataRefresher;
9628
+ var DATA_TYPE, TICK_MS, message2, readJson2, isObject7, DataRefresher;
9256
9629
  var init_data_refresh = __esm({
9257
9630
  "packages/daemon/src/data-refresh.ts"() {
9258
9631
  "use strict";
@@ -9262,12 +9635,12 @@ var init_data_refresh = __esm({
9262
9635
  message2 = (error) => error?.message ?? String(error);
9263
9636
  readJson2 = (path) => {
9264
9637
  try {
9265
- return JSON.parse(readFileSync13(path, "utf8"));
9638
+ return JSON.parse(readFileSync15(path, "utf8"));
9266
9639
  } catch {
9267
9640
  return null;
9268
9641
  }
9269
9642
  };
9270
- isObject4 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9643
+ isObject7 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
9271
9644
  DataRefresher = class {
9272
9645
  o;
9273
9646
  states = /* @__PURE__ */ new Map();
@@ -9418,8 +9791,8 @@ var init_data_refresh = __esm({
9418
9791
  });
9419
9792
 
9420
9793
  // packages/daemon/src/inbox.ts
9421
- import { appendFileSync as appendFileSync2, readFileSync as readFileSync14, renameSync as renameSync6, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
9422
- import { join as join22 } from "node:path";
9794
+ import { appendFileSync as appendFileSync2, readFileSync as readFileSync16, renameSync as renameSync6, rmSync as rmSync7, writeFileSync as writeFileSync7 } from "node:fs";
9795
+ import { join as join26 } from "node:path";
9423
9796
  var safe, Inbox;
9424
9797
  var init_inbox = __esm({
9425
9798
  "packages/daemon/src/inbox.ts"() {
@@ -9433,7 +9806,7 @@ var init_inbox = __esm({
9433
9806
  }
9434
9807
  /** The file of a session key. */
9435
9808
  fileOf(key) {
9436
- return join22(files.inbox(), `${safe(key)}.jsonl`);
9809
+ return join26(files.inbox(), `${safe(key)}.jsonl`);
9437
9810
  }
9438
9811
  /** Appends a message; an open wait for this key takes it at once (`taken: true`). */
9439
9812
  append(key, item) {
@@ -9454,7 +9827,7 @@ var init_inbox = __esm({
9454
9827
  peek(key) {
9455
9828
  let text3;
9456
9829
  try {
9457
- text3 = readFileSync14(this.fileOf(key), "utf8");
9830
+ text3 = readFileSync16(this.fileOf(key), "utf8");
9458
9831
  } catch {
9459
9832
  return [];
9460
9833
  }
@@ -9475,7 +9848,7 @@ var init_inbox = __esm({
9475
9848
  /** The waiting messages, removed. */
9476
9849
  take(key) {
9477
9850
  const items = this.peek(key);
9478
- if (items.length) rmSync6(this.fileOf(key), { force: true });
9851
+ if (items.length) rmSync7(this.fileOf(key), { force: true });
9479
9852
  return items;
9480
9853
  }
9481
9854
  /**
@@ -9517,7 +9890,7 @@ var init_inbox = __esm({
9517
9890
  /** Rewrites a key's file with `kept` only (removes it when empty). */
9518
9891
  keep(key, kept) {
9519
9892
  const file = this.fileOf(key);
9520
- if (!kept.length) rmSync6(file, { force: true });
9893
+ if (!kept.length) rmSync7(file, { force: true });
9521
9894
  else {
9522
9895
  const next = `${file}.${process.pid}.tmp`;
9523
9896
  writeFileSync7(next, kept.map((item) => `${JSON.stringify(item)}
@@ -9554,8 +9927,8 @@ var init_inbox = __esm({
9554
9927
  });
9555
9928
 
9556
9929
  // packages/daemon/src/preset.ts
9557
- import { createHash as createHash6 } from "node:crypto";
9558
- import { statSync as statSync9 } from "node:fs";
9930
+ import { createHash as createHash7 } from "node:crypto";
9931
+ import { statSync as statSync11 } from "node:fs";
9559
9932
  function presetFrom(source, plugin = false) {
9560
9933
  const get2 = (key) => text2(source[PRESET_KEYS[key]]);
9561
9934
  const out2 = {};
@@ -9593,14 +9966,14 @@ function readPreset(env = process.env) {
9593
9966
  function readableByOthers(path) {
9594
9967
  if (process.platform === "win32") return null;
9595
9968
  try {
9596
- const mode2 = statSync9(path).mode & 511;
9969
+ const mode2 = statSync11(path).mode & 511;
9597
9970
  return mode2 & 36 ? mode2 : null;
9598
9971
  } catch {
9599
9972
  return null;
9600
9973
  }
9601
9974
  }
9602
9975
  function tokenHash(token) {
9603
- return createHash6("sha256").update(token).digest("hex");
9976
+ return createHash7("sha256").update(token).digest("hex");
9604
9977
  }
9605
9978
  var PRESET_KEYS, UNFILLED, text2, yes, mode, PLUGIN_REMOTE_KEY;
9606
9979
  var init_preset = __esm({
@@ -10437,9 +10810,9 @@ var init_wake2 = __esm({
10437
10810
  });
10438
10811
 
10439
10812
  // packages/daemon/src/link.ts
10440
- import { createHash as createHash7, randomBytes as randomBytes9 } from "node:crypto";
10441
- import { existsSync as existsSync14, mkdirSync as mkdirSync6, readFileSync as readFileSync15, readdirSync as readdirSync11, rmSync as rmSync7, statSync as statSync10, watch as watch2 } from "node:fs";
10442
- import { dirname as dirname10, extname as extname3, join as join23, sep as sep9 } from "node:path";
10813
+ import { createHash as createHash8, randomBytes as randomBytes9 } from "node:crypto";
10814
+ import { existsSync as existsSync17, mkdirSync as mkdirSync7, readFileSync as readFileSync17, readdirSync as readdirSync12, rmSync as rmSync8, statSync as statSync12, watch as watch2 } from "node:fs";
10815
+ import { dirname as dirname13, extname as extname3, join as join27, sep as sep11 } from "node:path";
10443
10816
  function wakeSenderOf(value) {
10444
10817
  if (!value || typeof value !== "object") return void 0;
10445
10818
  const { name, role } = value;
@@ -10449,12 +10822,12 @@ function wakeSenderOf(value) {
10449
10822
  }
10450
10823
  function conflictFile(root, path) {
10451
10824
  const first = inside(root, `_agent/conflicts/${path}`);
10452
- if (!existsSync14(first)) return first;
10825
+ if (!existsSync17(first)) return first;
10453
10826
  const ext = extname3(first);
10454
10827
  const stem = first.slice(0, first.length - ext.length);
10455
10828
  for (let n = 2; ; n++) {
10456
10829
  const next = `${stem}.${n}${ext}`;
10457
- if (!existsSync14(next)) return next;
10830
+ if (!existsSync17(next)) return next;
10458
10831
  }
10459
10832
  }
10460
10833
  function queuedNote(host) {
@@ -10537,7 +10910,7 @@ var init_link2 = __esm({
10537
10910
  const value = Number(process.env[name]);
10538
10911
  return process.env[name] && Number.isFinite(value) && value >= 0 ? value : fallback;
10539
10912
  };
10540
- sha2562 = (bytes) => createHash7("sha256").update(bytes).digest("hex");
10913
+ sha2562 = (bytes) => createHash8("sha256").update(bytes).digest("hex");
10541
10914
  message3 = (error) => error?.message ?? String(error);
10542
10915
  TYPES_NO_SITE = "This site keeps no published types (it is older than this Open Artifact, or it serves everything on one domain).";
10543
10916
  siteTypesMs = () => ((v) => Number.isFinite(v) && v > 0 ? v : 5e3)(Number(process.env.OPEN_ARTIFACT_SITE_TYPES_MS));
@@ -11302,7 +11675,7 @@ var init_link2 = __esm({
11302
11675
  if (typeof write?.file_path !== "string" || !write.file_path) return write;
11303
11676
  let data;
11304
11677
  try {
11305
- data = JSON.parse(readFileSync15(write.file_path, "utf8"));
11678
+ data = JSON.parse(readFileSync17(write.file_path, "utf8"));
11306
11679
  } catch (error) {
11307
11680
  throw new OpenArtifactError("invalid_argument", `file_path ${write.file_path}: ${message3(error)}`);
11308
11681
  }
@@ -11349,7 +11722,7 @@ var init_link2 = __esm({
11349
11722
  this.syncs.set(id, state);
11350
11723
  try {
11351
11724
  state.watcher = watch2(record.root, { recursive: true, persistent: false }, (_event, name) => {
11352
- const rel = String(name ?? "").split(sep9).join("/");
11725
+ const rel = String(name ?? "").split(sep11).join("/");
11353
11726
  if (rel && !linkSynced(rel) && rel !== ".artifact.json") return;
11354
11727
  this.schedule(id, 200);
11355
11728
  });
@@ -11429,22 +11802,22 @@ var init_link2 = __esm({
11429
11802
  const walk = (dir, rel) => {
11430
11803
  let entries;
11431
11804
  try {
11432
- entries = readdirSync11(dir, { withFileTypes: true });
11805
+ entries = readdirSync12(dir, { withFileTypes: true });
11433
11806
  } catch {
11434
11807
  return;
11435
11808
  }
11436
11809
  for (const entry of entries) {
11437
11810
  const path = rel ? `${rel}/${entry.name}` : entry.name;
11438
11811
  if (!linkSynced(path)) continue;
11439
- const file = join23(dir, entry.name);
11812
+ const file = join27(dir, entry.name);
11440
11813
  if (entry.isDirectory()) walk(file, path);
11441
11814
  else if (entry.isFile()) {
11442
11815
  try {
11443
- const stat2 = statSync10(file);
11816
+ const stat2 = statSync12(file);
11444
11817
  const known = state.hashes.get(path);
11445
11818
  if (known && known.size === stat2.size && known.mtimeMs === stat2.mtimeMs) out2.set(path, known.etag);
11446
11819
  else {
11447
- const etag = sha2562(readFileSync15(file));
11820
+ const etag = sha2562(readFileSync17(file));
11448
11821
  state.hashes.set(path, { size: stat2.size, mtimeMs: stat2.mtimeMs, etag });
11449
11822
  out2.set(path, etag);
11450
11823
  }
@@ -11460,7 +11833,7 @@ var init_link2 = __esm({
11460
11833
  /** The working copy's etag of one path now, `null` when it is not there. */
11461
11834
  hashNow(root, path) {
11462
11835
  try {
11463
- return sha2562(readFileSync15(inside(root, path)));
11836
+ return sha2562(readFileSync17(inside(root, path)));
11464
11837
  } catch {
11465
11838
  return null;
11466
11839
  }
@@ -11528,7 +11901,7 @@ var init_link2 = __esm({
11528
11901
  for (const write of pushes) {
11529
11902
  let content = null;
11530
11903
  try {
11531
- const bytes = readFileSync15(inside(root, write.path));
11904
+ const bytes = readFileSync17(inside(root, write.path));
11532
11905
  content = bytes.toString("base64");
11533
11906
  batchBytes += bytes.length;
11534
11907
  } catch {
@@ -11544,11 +11917,11 @@ var init_link2 = __esm({
11544
11917
  const file = inside(root, path);
11545
11918
  const got = host.has(path) || conflicts.includes(path) ? await client.readFile(id, path) : null;
11546
11919
  if (got) {
11547
- mkdirSync6(dirname10(file), { recursive: true });
11920
+ mkdirSync7(dirname13(file), { recursive: true });
11548
11921
  writeFileAtomic(file, got.bytes);
11549
11922
  setBase(path, sha2562(got.bytes));
11550
11923
  } else {
11551
- rmSync7(file, { force: true });
11924
+ rmSync8(file, { force: true });
11552
11925
  setBase(path, null);
11553
11926
  }
11554
11927
  state.hashes.delete(path);
@@ -11556,10 +11929,10 @@ var init_link2 = __esm({
11556
11929
  };
11557
11930
  const keep = (path) => {
11558
11931
  const file = inside(root, path);
11559
- if (!existsSync14(file)) return;
11932
+ if (!existsSync17(file)) return;
11560
11933
  const copy = conflictFile(root, path);
11561
- mkdirSync6(dirname10(copy), { recursive: true });
11562
- writeFileAtomic(copy, readFileSync15(file));
11934
+ mkdirSync7(dirname13(copy), { recursive: true });
11935
+ writeFileAtomic(copy, readFileSync17(file));
11563
11936
  kept.push(path);
11564
11937
  };
11565
11938
  for (const path of pulls) {
@@ -11855,12 +12228,12 @@ var init_mcp2 = __esm({
11855
12228
 
11856
12229
  // packages/daemon/src/nudge.ts
11857
12230
  import { execFile } from "node:child_process";
11858
- import { existsSync as existsSync15, readdirSync as readdirSync12, readFileSync as readFileSync16, statSync as statSync11 } from "node:fs";
11859
- import { homedir as homedir5 } from "node:os";
11860
- import { delimiter, isAbsolute as isAbsolute5, join as join24 } from "node:path";
12231
+ import { existsSync as existsSync18, readdirSync as readdirSync13, readFileSync as readFileSync18, statSync as statSync13 } from "node:fs";
12232
+ import { homedir as homedir7 } from "node:os";
12233
+ import { delimiter, isAbsolute as isAbsolute9, join as join28 } from "node:path";
11861
12234
  function expandHome2(path, home2) {
11862
12235
  if (path === "~") return home2;
11863
- return path.startsWith("~/") ? join24(home2, path.slice(2)) : path;
12236
+ return path.startsWith("~/") ? join28(home2, path.slice(2)) : path;
11864
12237
  }
11865
12238
  function fillEnv(text3) {
11866
12239
  let missing = false;
@@ -11873,14 +12246,14 @@ function fillEnv(text3) {
11873
12246
  }
11874
12247
  function onPath(name, platform = process.platform, path = process.env.PATH ?? "") {
11875
12248
  const dirs = path.split(delimiter).filter(Boolean);
11876
- const at = (dir, file) => join24(dir, file);
12249
+ const at = (dir, file) => join28(dir, file);
11877
12250
  if (platform !== "win32") {
11878
- for (const dir of dirs) if (isFile(at(dir, name))) return { found: at(dir, name) };
12251
+ for (const dir of dirs) if (isFile2(at(dir, name))) return { found: at(dir, name) };
11879
12252
  return null;
11880
12253
  }
11881
12254
  const exe = /\.exe$/i.test(name) ? [name] : isBatch(name) ? [] : [`${name}.exe`];
11882
- for (const file of exe) for (const dir of dirs) if (isFile(at(dir, file))) return { found: at(dir, file) };
11883
- for (const file of isBatch(name) ? [name] : [`${name}.cmd`, `${name}.bat`]) for (const dir of dirs) if (isFile(at(dir, file))) return { batch: at(dir, file) };
12255
+ for (const file of exe) for (const dir of dirs) if (isFile2(at(dir, file))) return { found: at(dir, file) };
12256
+ for (const file of isBatch(name) ? [name] : [`${name}.cmd`, `${name}.bat`]) for (const dir of dirs) if (isFile2(at(dir, file))) return { batch: at(dir, file) };
11884
12257
  return null;
11885
12258
  }
11886
12259
  function nudgeProgram(command, home2, options = {}) {
@@ -11901,12 +12274,12 @@ function nudgeProgram(command, home2, options = {}) {
11901
12274
  return { command: filled, args: before };
11902
12275
  }
11903
12276
  const path = expandHome2(filled, home2);
11904
- if (isAbsolute5(path) || path.includes("/") || path.includes("\\")) {
12277
+ if (isAbsolute9(path) || path.includes("/") || path.includes("\\")) {
11905
12278
  if (platform === "win32" && isBatch(path)) {
11906
- if (existsSync15(path)) skipBatch(path);
12279
+ if (existsSync18(path)) skipBatch(path);
11907
12280
  continue;
11908
12281
  }
11909
- if (existsSync15(path)) return { command: path, args: before };
12282
+ if (existsSync18(path)) return { command: path, args: before };
11910
12283
  continue;
11911
12284
  }
11912
12285
  const found2 = onPath(path, platform, options.path);
@@ -11915,7 +12288,7 @@ function nudgeProgram(command, home2, options = {}) {
11915
12288
  }
11916
12289
  return null;
11917
12290
  }
11918
- function liveEnvFile(spec, needs, home2, alive2 = defaultAlive) {
12291
+ function liveEnvFile(spec, needs, home2, alive3 = defaultAlive) {
11919
12292
  let pattern;
11920
12293
  try {
11921
12294
  pattern = new RegExp(spec.pattern);
@@ -11925,16 +12298,16 @@ function liveEnvFile(spec, needs, home2, alive2 = defaultAlive) {
11925
12298
  const dir = expandHome2(spec.dir, home2);
11926
12299
  let names;
11927
12300
  try {
11928
- names = readdirSync12(dir).filter((name) => pattern.test(name));
12301
+ names = readdirSync13(dir).filter((name) => pattern.test(name));
11929
12302
  } catch {
11930
12303
  return null;
11931
12304
  }
11932
12305
  for (const name of names) {
11933
12306
  try {
11934
- const fields = JSON.parse(readFileSync16(join24(dir, name), "utf8"));
12307
+ const fields = JSON.parse(readFileSync18(join28(dir, name), "utf8"));
11935
12308
  if (!fields || typeof fields !== "object" || needs.some((field) => fields[field] === void 0 || fields[field] === null || fields[field] === "")) continue;
11936
12309
  const pid = spec.pid ? Number(fields[spec.pid]) : 0;
11937
- if (pid && !alive2(pid)) continue;
12310
+ if (pid && !alive3(pid)) continue;
11938
12311
  return fields;
11939
12312
  } catch {
11940
12313
  }
@@ -11957,7 +12330,7 @@ async function nudgeSession(ref, artifact, options = {}) {
11957
12330
  log(`nudge ${who}: not a session id a command takes`);
11958
12331
  return false;
11959
12332
  }
11960
- const home2 = options.home ?? homedir5();
12333
+ const home2 = options.home ?? homedir7();
11961
12334
  const env = { ...process.env };
11962
12335
  if (nudge.env) {
11963
12336
  const needs = [...new Set(Object.values(nudge.env).flatMap((value) => [...String(value).matchAll(/\$\{file\.([A-Za-z0-9_]+)\}/g)].map((m) => m[1])))];
@@ -11985,7 +12358,7 @@ async function nudgeSession(ref, artifact, options = {}) {
11985
12358
  log(`nudge ${who}: ${error ? `failed: ${error.message}` : "sent"}`);
11986
12359
  return !error;
11987
12360
  }
11988
- var NUDGE_TIMEOUT_MS, defaultRun, defaultAlive, isFile, isBatch, SAFE_SESSION;
12361
+ var NUDGE_TIMEOUT_MS, defaultRun, defaultAlive, isFile2, isBatch, SAFE_SESSION;
11989
12362
  var init_nudge = __esm({
11990
12363
  "packages/daemon/src/nudge.ts"() {
11991
12364
  "use strict";
@@ -12002,9 +12375,9 @@ var init_nudge = __esm({
12002
12375
  return error.code === "EPERM";
12003
12376
  }
12004
12377
  };
12005
- isFile = (path) => {
12378
+ isFile2 = (path) => {
12006
12379
  try {
12007
- return statSync11(path).isFile();
12380
+ return statSync13(path).isFile();
12008
12381
  } catch {
12009
12382
  return false;
12010
12383
  }
@@ -12104,8 +12477,8 @@ var init_release_guard = __esm({
12104
12477
  });
12105
12478
 
12106
12479
  // packages/daemon/src/artifact-import.ts
12107
- import { readFileSync as readFileSync17, rmSync as rmSync8, writeFileSync as writeFileSync8 } from "node:fs";
12108
- import { join as join25 } from "node:path";
12480
+ import { readFileSync as readFileSync19, rmSync as rmSync9, writeFileSync as writeFileSync8 } from "node:fs";
12481
+ import { join as join29 } from "node:path";
12109
12482
  async function readArtifactArchive(bytes, source, o) {
12110
12483
  if (bytes.byteLength > ARTIFACT_IMPORT_LIMITS.zipBytes) throw new OpenArtifactError("too_large", `${source} is larger than ${ARTIFACT_IMPORT_LIMITS.zipBytes} bytes.`, { status: 413 });
12111
12484
  let checked;
@@ -12116,7 +12489,7 @@ async function readArtifactArchive(bytes, source, o) {
12116
12489
  throw error;
12117
12490
  }
12118
12491
  const kept = checked.files.find((f) => !archiveKeeps(f.path));
12119
- if (kept) throw bad(`${source}: ${kept.path} is not something an artifact's archive carries, so this is not one.`);
12492
+ if (kept) throw bad2(`${source}: ${kept.path} is not something an artifact's archive carries, so this is not one.`);
12120
12493
  const markerFile = checked.files.find((f) => f.path === ".artifact.json");
12121
12494
  if (!markerFile) throw new OpenArtifactError("bad_archive", `${source} has no .artifact.json in its folder ${checked.top}/: it is not an artifact's archive.`);
12122
12495
  let raw;
@@ -12125,8 +12498,8 @@ async function readArtifactArchive(bytes, source, o) {
12125
12498
  if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error("not a JSON object");
12126
12499
  raw = parsed;
12127
12500
  } catch (error) {
12128
- if (error instanceof ZipRefusal) throw bad(`${source}: ${error.message}`);
12129
- throw bad(`${source}: its .artifact.json does not parse (${error.message}).`);
12501
+ if (error instanceof ZipRefusal) throw bad2(`${source}: ${error.message}`);
12502
+ throw bad2(`${source}: its .artifact.json does not parse (${error.message}).`);
12130
12503
  }
12131
12504
  if (typeof raw.type !== "string" || !raw.type) throw new OpenArtifactError("bad_archive", `${source}: its .artifact.json names no type.`);
12132
12505
  const typeUid = typeof raw.typeUid === "string" && raw.typeUid ? raw.typeUid : null;
@@ -12155,20 +12528,20 @@ async function unpackArtifactArchive(bytes, read, dest) {
12155
12528
  throw error;
12156
12529
  }
12157
12530
  try {
12158
- const file = join25(unpacked.temp, ".artifact.json");
12159
- const { id: _id, ...rest } = JSON.parse(readFileSync17(file, "utf8"));
12160
- rmSync8(file, { force: true });
12531
+ const file = join29(unpacked.temp, ".artifact.json");
12532
+ const { id: _id, ...rest } = JSON.parse(readFileSync19(file, "utf8"));
12533
+ rmSync9(file, { force: true });
12161
12534
  writeFileSync8(file, `${JSON.stringify({ ...rest, type: read.type.id }, null, 2)}
12162
12535
  `, { flag: "wx" });
12163
12536
  await moveIntoPlace(unpacked.temp, dest);
12164
12537
  } catch (error) {
12165
- rmSync8(unpacked.temp, { recursive: true, force: true });
12538
+ rmSync9(unpacked.temp, { recursive: true, force: true });
12166
12539
  if (error.code === "EEXIST") throw new OpenArtifactError("conflict", `${dest} exists already.`);
12167
12540
  throw error;
12168
12541
  }
12169
12542
  return { root: dest, files: unpacked.files, bytes: unpacked.bytes };
12170
12543
  }
12171
- var ARTIFACT_IMPORT_LIMITS, bad;
12544
+ var ARTIFACT_IMPORT_LIMITS, bad2;
12172
12545
  var init_artifact_import = __esm({
12173
12546
  "packages/daemon/src/artifact-import.ts"() {
12174
12547
  "use strict";
@@ -12184,7 +12557,7 @@ var init_artifact_import = __esm({
12184
12557
  /** One file unpacked, bytes. */
12185
12558
  fileBytes: 256 * 1024 * 1024
12186
12559
  };
12187
- bad = (message4) => new OpenArtifactError("bad_archive", message4);
12560
+ bad2 = (message4) => new OpenArtifactError("bad_archive", message4);
12188
12561
  }
12189
12562
  });
12190
12563
 
@@ -12254,10 +12627,10 @@ var init_remote_archive = __esm({
12254
12627
  });
12255
12628
 
12256
12629
  // packages/daemon/src/tools.ts
12257
- import { createHash as createHash8 } from "node:crypto";
12258
- import { existsSync as existsSync16, mkdirSync as mkdirSync7, readFileSync as readFileSync18, readdirSync as readdirSync13, rmSync as rmSync9, statSync as statSync12, writeFileSync as writeFileSync9 } from "node:fs";
12259
- import { homedir as homedir6 } from "node:os";
12260
- import { basename as basename6, dirname as dirname11, isAbsolute as isAbsolute6, join as join26, resolve as resolve16, sep as sep10 } from "node:path";
12630
+ import { createHash as createHash9 } from "node:crypto";
12631
+ import { existsSync as existsSync19, mkdirSync as mkdirSync8, readFileSync as readFileSync20, readdirSync as readdirSync14, rmSync as rmSync10, statSync as statSync14, writeFileSync as writeFileSync9 } from "node:fs";
12632
+ import { homedir as homedir8 } from "node:os";
12633
+ import { basename as basename7, dirname as dirname14, isAbsolute as isAbsolute10, join as join30, resolve as resolve19, sep as sep12 } from "node:path";
12261
12634
  import { fileURLToPath as fileURLToPath4 } from "node:url";
12262
12635
  function offlineOf(link, record) {
12263
12636
  const note = link?.offlineNote(record);
@@ -12328,14 +12701,14 @@ function argsShape(schema) {
12328
12701
  return `, args: {${shown.join(", ")}${props.length > 8 ? ", ..." : ""}}`;
12329
12702
  }
12330
12703
  function localPathIn(value, at, root, depth = 0) {
12331
- const home2 = homedir6();
12332
- const under = (full, dir) => !!dir && (full === resolve16(dir) || full.startsWith(resolve16(dir) + sep10));
12333
- return pathIn(value, at, (full) => under(full, home2) || under(full, root) || existsSync16(full), depth);
12704
+ const home2 = homedir8();
12705
+ const under = (full, dir) => !!dir && (full === resolve19(dir) || full.startsWith(resolve19(dir) + sep12));
12706
+ return pathIn(value, at, (full) => under(full, home2) || under(full, root) || existsSync19(full), depth);
12334
12707
  }
12335
12708
  function pathOutside(value, at, workspace) {
12336
12709
  return pathIn(value, at, (full) => {
12337
- const top = full.split(sep10).slice(0, 2).join(sep10) || sep10;
12338
- if (!existsSync16(top)) return false;
12710
+ const top = full.split(sep12).slice(0, 2).join(sep12) || sep12;
12711
+ if (!existsSync19(top)) return false;
12339
12712
  try {
12340
12713
  workspace.resolve(full);
12341
12714
  return false;
@@ -12355,8 +12728,8 @@ function pathIn(value, at, counts, depth = 0) {
12355
12728
  return null;
12356
12729
  }
12357
12730
  }
12358
- if (!isAbsolute6(path) || resolve16(path) === resolve16("/")) return null;
12359
- return counts(resolve16(path)) ? { at, path: value } : null;
12731
+ if (!isAbsolute10(path) || resolve19(path) === resolve19("/")) return null;
12732
+ return counts(resolve19(path)) ? { at, path: value } : null;
12360
12733
  }
12361
12734
  if (depth >= 8 || !value || typeof value !== "object") return null;
12362
12735
  const entries = Array.isArray(value) ? value.slice(0, 1e3).map((item, i) => [String(i), item]) : Object.entries(value).slice(0, 1e3);
@@ -12370,6 +12743,9 @@ function typeLocationFields(type) {
12370
12743
  const where2 = typeLocation(type);
12371
12744
  return { type_remote: where2.remote, ...where2.origin ? { type_origin: where2.origin } : {} };
12372
12745
  }
12746
+ function outsideNote(root) {
12747
+ return `Its folder is outside your working folder: ${root}. If your app does not let you write there, send its files with Artifact {action: "publish", url, files} instead of your own file tools. Tell the person where the folder is.`;
12748
+ }
12373
12749
  function autoNote(host) {
12374
12750
  return `This artifact is being published to ${host ?? "the default site"} by itself, in the background: view_url is this computer's address until that finishes, then its web address (a later result's view_url, or Artifact {action: "read"}). Nothing for you to do.`;
12375
12751
  }
@@ -12385,7 +12761,7 @@ function capabilitiesOf(value, type) {
12385
12761
  }
12386
12762
  function markerTypeUid(files2) {
12387
12763
  try {
12388
- const marker = JSON.parse(readFileSync18(files2.resolve(".artifact.json"), "utf8"));
12764
+ const marker = JSON.parse(readFileSync20(files2.resolve(".artifact.json"), "utf8"));
12389
12765
  const typeUid = typeof marker.typeUid === "string" && marker.typeUid ? marker.typeUid : null;
12390
12766
  return { typeUid, typeSource: typeUid && typeof marker.typeSource === "string" ? marker.typeSource : null };
12391
12767
  } catch {
@@ -12394,7 +12770,7 @@ function markerTypeUid(files2) {
12394
12770
  }
12395
12771
  function markerCapabilities(files2) {
12396
12772
  try {
12397
- const value = JSON.parse(readFileSync18(files2.resolve(".artifact.json"), "utf8")).capabilities;
12773
+ const value = JSON.parse(readFileSync20(files2.resolve(".artifact.json"), "utf8")).capabilities;
12398
12774
  return value !== void 0 && !capabilitiesProblem(value) && Object.keys(value).length ? value : void 0;
12399
12775
  } catch {
12400
12776
  return void 0;
@@ -12413,15 +12789,15 @@ function contentTitle(files2, titleFrom) {
12413
12789
  const parsed = titleFrom ? parseTitleFrom(titleFrom) : null;
12414
12790
  if (!parsed) return void 0;
12415
12791
  try {
12416
- return titleInFile(parsed.file, readFileSync18(files2.resolve(parsed.file), "utf8"), parsed.pointer)?.slice(0, 200);
12792
+ return titleInFile(parsed.file, readFileSync20(files2.resolve(parsed.file), "utf8"), parsed.pointer)?.slice(0, 200);
12417
12793
  } catch {
12418
12794
  return void 0;
12419
12795
  }
12420
12796
  }
12421
12797
  function inFolder(root, folder) {
12422
- const full = resolve16(root);
12423
- const top = resolve16(folder);
12424
- return full === top || full.startsWith(top.endsWith(sep10) ? top : top + sep10);
12798
+ const full = resolve19(root);
12799
+ const top = resolve19(folder);
12800
+ return full === top || full.startsWith(top.endsWith(sep12) ? top : top + sep12);
12425
12801
  }
12426
12802
  var MAX_READ, MAX_READ_TOTAL, MAX_PATHS, MAX_LIST, MAX_LIST_HASH, LIST_LIMIT, LIST_MAX2, MAX_WAIT_MS, DATA_PAGE, DATA_PAGE_MAX, REPLY_MAX_BYTES, RELATED_MAX, READ_ACTIONS, TYPE_TEXT_NOTE, NO_TYPE_FITS, SHOW_IT, AFTER_CREATE_CHECK, AFTER_CREATE, AFTER_CREATE_EARLY_CHECK, AFTER_CREATE_EARLY, AFTER_CREATE_OPENING_CHECK, AFTER_CREATE_OPENING, AFTER_CREATE_OPEN_CHECK, OPEN_NOT_AVAILABLE, OPEN_YOURSELF, OPEN_EARLY_YOURSELF, AFTER_CREATE_OPEN, changedNote, MAY_WORDS, MAY_FIX, EXISTING_MAX, STOP_WORDS, OTHER_INTENT, CJK, words, sha2563, DATA_NO_SHA_NOTE, DATA_QUERY_IGNORED_NOTE, DATA_WRITE_KEYS, NOT_SENT_NOTE, DUPLICATE_FIX, REPLY_TOO_LONG_FIX, cleanPath, now, Tools;
12427
12803
  var init_tools2 = __esm({
@@ -12431,7 +12807,10 @@ var init_tools2 = __esm({
12431
12807
  init_workspace_files();
12432
12808
  init_harness_profiles();
12433
12809
  init_harness_skill();
12810
+ init_ownership();
12434
12811
  init_paths();
12812
+ init_project();
12813
+ init_settings2();
12435
12814
  init_servers();
12436
12815
  init_store();
12437
12816
  init_type_packages();
@@ -12481,7 +12860,7 @@ var init_tools2 = __esm({
12481
12860
  OTHER_INTENT = "other";
12482
12861
  CJK = new RegExp("\\p{Script=Han}", "u");
12483
12862
  words = (text3) => ` ${text3.toLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim()} `;
12484
- sha2563 = (bytes) => createHash8("sha256").update(bytes).digest("hex");
12863
+ sha2563 = (bytes) => createHash9("sha256").update(bytes).digest("hex");
12485
12864
  DATA_NO_SHA_NOTE = "This type's server reports no sha256 for documents, so if_match cannot protect writes here: read right before you write.";
12486
12865
  DATA_QUERY_IGNORED_NOTE = "This type's server does not run queries: docs holds the whole collection, unfiltered.";
12487
12866
  DATA_WRITE_KEYS = ["op", "path", "collection", "doc_id", "data", "file_path", "if_match", "field", "old", "new"];
@@ -12760,17 +13139,19 @@ ${rules}` };
12760
13139
  const wanted = significant(text3);
12761
13140
  if (!wanted.size) return [];
12762
13141
  const me = sessionKeyOf(caller2);
12763
- const workspace = caller2.workspace ? resolve16(caller2.workspace) : null;
13142
+ const workspace = caller2.workspace ? resolve19(caller2.workspace) : null;
12764
13143
  const mine = (a) => !!a.owner && sessionKeyOf(a.owner) === me;
12765
- return this.o.store.list().filter((a) => a.type === type.id && this.reachable(a, workspace) && (mine(a) || reuse === "workspace" && !!workspace && inFolder(a.root, workspace))).map((a) => ({ a, score: [...significant(a.title)].filter((w) => wanted.has(w)).length })).filter(({ score }) => score > 0).sort((x, y) => y.score - x.score || String(y.a.updatedAt).localeCompare(String(x.a.updatedAt))).slice(0, EXISTING_MAX).map(({ a }) => ({ url: artifactUrl(a.id), title: a.title, type: a.type, updatedAt: a.updatedAt, root: a.root, mine: mine(a) }));
13144
+ const inProject = this.projectScope(workspace);
13145
+ return this.o.store.list().filter((a) => a.type === type.id && this.reachable(a, workspace) && (mine(a) || reuse === "workspace" && inProject(a))).map((a) => ({ a, score: [...significant(a.title)].filter((w) => wanted.has(w)).length })).filter(({ score }) => score > 0).sort((x, y) => y.score - x.score || String(y.a.updatedAt).localeCompare(String(x.a.updatedAt))).slice(0, EXISTING_MAX).map(({ a }) => ({ url: artifactUrl(a.id), title: a.title, type: a.type, updatedAt: a.updatedAt, root: a.root, mine: mine(a) }));
12766
13146
  }
12767
13147
  /** The caller's artifacts (theirs, or under their workspace) of the types `type` builds on (`openArtifact.uses`), newest first. */
12768
13148
  relatedTo(type, caller2) {
12769
13149
  if (!type.uses.length) return [];
12770
13150
  const me = sessionKeyOf(caller2);
12771
- const workspace = caller2.workspace ? resolve16(caller2.workspace) : null;
13151
+ const workspace = caller2.workspace ? resolve19(caller2.workspace) : null;
12772
13152
  const mine = (a) => !!a.owner && sessionKeyOf(a.owner) === me;
12773
- return this.o.store.list().filter((a) => type.uses.includes(a.type) && this.reachable(a, workspace) && (mine(a) || !!workspace && inFolder(a.root, workspace))).sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt))).slice(0, RELATED_MAX).map((a) => ({ url: artifactUrl(a.id), title: a.title, type: a.type, root: a.root, mine: mine(a), updatedAt: a.updatedAt }));
13153
+ const inProject = this.projectScope(workspace);
13154
+ return this.o.store.list().filter((a) => type.uses.includes(a.type) && this.reachable(a, workspace) && (mine(a) || inProject(a))).sort((a, b) => String(b.updatedAt).localeCompare(String(a.updatedAt))).slice(0, RELATED_MAX).map((a) => ({ url: artifactUrl(a.id), title: a.title, type: a.type, root: a.root, mine: mine(a), updatedAt: a.updatedAt }));
12774
13155
  }
12775
13156
  list(args, caller2) {
12776
13157
  const scope = args.scope ?? "mine";
@@ -12785,10 +13166,11 @@ ${rules}` };
12785
13166
  const offset = args.cursor === void 0 || args.cursor === "" ? 0 : Number(args.cursor);
12786
13167
  if (!Number.isInteger(offset) || offset < 0) throw new OpenArtifactError("invalid_argument", "cursor: the next_cursor of the previous page.");
12787
13168
  const me = sessionKeyOf(caller2);
12788
- const workspace = caller2.workspace ? resolve16(caller2.workspace) : null;
13169
+ const workspace = caller2.workspace ? resolve19(caller2.workspace) : null;
12789
13170
  const mine = (a) => !!a.owner && sessionKeyOf(a.owner) === me;
13171
+ const inProject = this.projectScope(workspace);
12790
13172
  const changed = (a) => !!a.lastUserEditAt && (!a.agentSeenAt || a.lastUserEditAt > a.agentSeenAt);
12791
- const shown = this.o.store.list().filter((a) => this.reachable(a, workspace) && (scope === "all" || mine(a) || !!workspace && inFolder(a.root, workspace))).filter((a) => (!typeId || a.type === typeId) && (!query || a.title.toLowerCase().includes(query)));
13173
+ const shown = this.o.store.list().filter((a) => this.reachable(a, workspace) && (scope === "all" || mine(a) || inProject(a))).filter((a) => (!typeId || a.type === typeId) && (!query || a.title.toLowerCase().includes(query)));
12792
13174
  const page = shown.slice(offset, offset + limit);
12793
13175
  const anyChanged = page.some(changed);
12794
13176
  return {
@@ -12812,22 +13194,79 @@ ${rules}` };
12812
13194
  };
12813
13195
  }
12814
13196
  /**
12815
- * The folder of a new or adopted artifact: `folder` (relative to the workspace), else `<workspace>/<artifactsDir>/<slug>`.
12816
- * A caller with no known workspace gets the home folder, never the daemon's own folder (which may be a plugin's).
13197
+ * Whether an artifact is one of the project's that a session in `workspace` works on: the record says so
13198
+ * (`project`, wherever its folder is), or its folder is in the workspace (records made before `project` was kept,
13199
+ * and folders the session made itself there).
13200
+ */
13201
+ projectScope(workspace) {
13202
+ if (!workspace) return () => false;
13203
+ const sameProject = projectMatcher(this.projectIn(workspace));
13204
+ return (record) => sameProject(record.project) || inFolder(record.root, workspace);
13205
+ }
13206
+ /** The project a session's new or adopted artifact is kept under (`ArtifactRecord.project`): none without a working folder. */
13207
+ projectFor(caller2) {
13208
+ return caller2.workspace && caller2.harness !== HOME_HARNESS ? this.projectIn(caller2.workspace) : null;
13209
+ }
13210
+ /**
13211
+ * The project of a workspace. A workspace-confined daemon looks at nothing outside the workspace, so there the
13212
+ * workspace is the project: no walk up to a checkout's top, and no settings file read.
13213
+ */
13214
+ projectIn(workspace) {
13215
+ return this.o.workspaceFoldersOnly ? resolve19(workspace) : projectOf(workspace).project;
13216
+ }
13217
+ /**
13218
+ * The folder of a new or adopted artifact: `folder` (relative to the workspace), else the folder {@link place}
13219
+ * chooses for `title`.
12817
13220
  */
12818
- resolveFolder(folder, caller2, title) {
13221
+ resolveFolder(folder, caller2, title, location2) {
13222
+ return this.place(folder, caller2, title, location2).root;
13223
+ }
13224
+ /**
13225
+ * Where a new artifact's folder goes.
13226
+ *
13227
+ * - `folder`: as given (absolute, or relative to the workspace).
13228
+ * - No working folder, or one inside the person's Open Artifact folder (the home page, an import):
13229
+ * `<that folder>/<artifactsDir>/<slug>`.
13230
+ * - Location `workspace`: `<the project's settings folder, else the workspace>/<artifactsDir>/<slug>` (the project's
13231
+ * folder when `artifactsDir` is the person's own entry for the project).
13232
+ * - Location `home`: `<Open Artifact folder>/<project>/<slug>`.
13233
+ *
13234
+ * The location is `wanted` (this call's `location`), else what {@link artifactsPlacement} finds; a workspace-confined
13235
+ * daemon keeps everything in the workspace. A folder that exists and is not empty gets `-2`, `-3`….
13236
+ *
13237
+ * `ignore`: the artifacts folder the daemon is about to make in a Git checkout only because the session's harness
13238
+ * keeps artifacts in the workspace (nobody chose it): it gets a `.gitignore`, so the checkout stays clean.
13239
+ */
13240
+ place(folder, caller2, title, wanted) {
12819
13241
  if (this.o.workspaceFoldersOnly && !caller2.workspace) {
12820
13242
  throw new OpenArtifactError("not_granted", "A local workspace is required to create or adopt a work.");
12821
13243
  }
12822
- const base = caller2.workspace ? resolve16(caller2.workspace) : homedir6();
12823
- const directory = this.o.workspaceFoldersOnly ? new WorkspaceDirectory(base) : null;
13244
+ const confined2 = this.o.workspaceFoldersOnly === true;
13245
+ const base = caller2.workspace ? resolve19(caller2.workspace) : null;
13246
+ const directory = confined2 && base ? new WorkspaceDirectory(base) : null;
12824
13247
  const folderPath = (candidate) => directory?.resolve(candidate) ?? candidate;
12825
- if (folder) return folderPath(resolve16(base, folder));
12826
- const dir = folderPath(join26(base, this.o.settings().artifactsDir || "artifacts"));
13248
+ if (folder) return { root: folderPath(resolve19(base ?? homedir8(), folder)) };
13249
+ const settings2 = this.o.settings();
13250
+ const home2 = resolve19(settings2.homeWorkspace);
12827
13251
  const slug = slugify(title);
12828
- let root = folderPath(join26(dir, slug));
12829
- for (let i = 2; existsSync16(root) && readdirSync13(root).length; i++) root = folderPath(join26(dir, `${slug}-${i}`));
12830
- return root;
13252
+ const unique = (dir) => {
13253
+ let root = folderPath(join30(dir, slug));
13254
+ for (let i = 2; existsSync19(root) && readdirSync14(root).length; i++) root = folderPath(join30(dir, `${slug}-${i}`));
13255
+ return root;
13256
+ };
13257
+ if (confined2 && wanted === "home") {
13258
+ throw new OpenArtifactError("not_granted", 'This app keeps artifacts in the workspace: location "home" is not available here.');
13259
+ }
13260
+ if (!base || confined2 || inFolder(base, home2)) return { root: unique(folderPath(join30(base ?? home2, settings2.artifactsDir || "artifacts"))) };
13261
+ const placement = artifactsPlacement(base, harnessProfile(caller2.harness).policy?.artifacts);
13262
+ const location2 = wanted ?? placement.location;
13263
+ if (location2 === "home") {
13264
+ const reserved = [placement.artifactsDir, settings2.artifactsDir || "artifacts"].map((dir) => dir.split(/[\\/]/).find(Boolean) ?? dir);
13265
+ return { root: unique(homeProjectDir(home2, placement.layers.info.project, reserved)) };
13266
+ }
13267
+ const parent = workspaceArtifactsDir(base, placement);
13268
+ const fallback = !wanted && placement.locationSource === "harness";
13269
+ return { root: unique(parent), ...fallback && placement.layers.info.gitRoot && !existsSync19(parent) ? { ignore: parent } : {} };
12831
13270
  }
12832
13271
  /** The type's actions, or `null` when they are not known; never fails. */
12833
13272
  async knownActions(type, start) {
@@ -12850,7 +13289,7 @@ ${rules}` };
12850
13289
  /** The note put before the type's own instructions: this artifact, and how the type's commands map to the tools. */
12851
13290
  hostNote(type, record, actions, opening) {
12852
13291
  const restricted = !type.trusted;
12853
- const script = restricted ? void 0 : ["cli.mjs", "artifact.mjs"].map((name) => join26(type.dir, "scripts", name)).find((file) => existsSync16(file));
13292
+ const script = restricted ? void 0 : ["cli.mjs", "artifact.mjs"].map((name) => join30(type.dir, "scripts", name)).find((file) => existsSync19(file));
12854
13293
  const declares = !!(type.entry && type.entry.kind !== "static" && type.entry.actions);
12855
13294
  const check = this.hasCheck(type, actions);
12856
13295
  const lines = [
@@ -12860,7 +13299,7 @@ ${rules}` };
12860
13299
  `- view it: ${this.o.viewUrl(record.id)}`,
12861
13300
  "",
12862
13301
  "# Running the type's commands here",
12863
- restricted ? `${type.scope === "installed" ? "This type was installed from a package" : "This type is in a project folder the person has not trusted yet"} (its folder is ${type.dir}). Do not run any of its files, its scripts included, with node or a shell: its page runs in the browser, and its actions run with Artifact call.` : `The instructions below were written for the type's own script. Its folder is ${type.dir}: "scripts/..." means ${join26(type.dir, "scripts")}/....`,
13302
+ restricted ? `${type.scope === "installed" ? "This type was installed from a package" : "This type is in a project folder the person has not trusted yet"} (its folder is ${type.dir}). Do not run any of its files, its scripts included, with node or a shell: its page runs in the browser, and its actions run with Artifact call.` : `The instructions below were written for the type's own script. Its folder is ${type.dir}: "scripts/..." means ${join30(type.dir, "scripts")}/....`,
12864
13303
  actions?.length ? "- The type's actions, run with Artifact call:" : null,
12865
13304
  ...(actions ?? []).map((a) => ` - ${a.name}: ${a.title} — Artifact {action: "call", url, name: "${a.name}"${argsShape(a.schema)}} (${a.effect ?? "write"})`),
12866
13305
  !actions && declares ? `- The type's actions (such as ${type.runtime === "frame" ? "snapshot, a picture of the page" : "check"}) run with Artifact {action: "call", url, name, args?}; Artifact {action: "read", url} lists them once its page has opened.` : null,
@@ -12901,8 +13340,12 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
12901
13340
  const capabilities = args.capabilities === void 0 ? void 0 : capabilitiesOf(args.capabilities, type);
12902
13341
  if (typeLocation(type).remote) await this.o.reach?.(type);
12903
13342
  const title = String(args.title ?? "").trim() || type.artifactTitle || type.title;
12904
- const root = this.resolveFolder(args.folder, caller2, title);
12905
- if (existsSync16(join26(root, ".artifact.json"))) {
13343
+ if (args.location !== void 0 && !ARTIFACTS_LOCATIONS.includes(args.location)) {
13344
+ throw new OpenArtifactError("invalid_argument", `location: "home" (the person's Open Artifact folder) or "workspace" (the working folder).`);
13345
+ }
13346
+ const placed = this.place(args.folder, caller2, title, args.location);
13347
+ const root = placed.root;
13348
+ if (existsSync19(join30(root, ".artifact.json"))) {
12906
13349
  const known = this.o.store.byRoot(root);
12907
13350
  if (known) throw new OpenArtifactError("conflict", `${root} is already the artifact ${artifactUrl(known.id)}.`, { fix: "Use that url, or give another folder." });
12908
13351
  }
@@ -12918,9 +13361,12 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
12918
13361
  owner,
12919
13362
  title,
12920
13363
  capabilities,
13364
+ project: this.projectFor(caller2),
12921
13365
  ...workspace ? { workspaceDirectory: workspace.identity } : {}
12922
13366
  });
12923
13367
  this.o.log(`created ${record.id} (${typeId}) at ${root} for ${sessionKeyOf(caller2) ?? "nobody"}`);
13368
+ if (placed.ignore) this.keepOutOfGit(placed.ignore);
13369
+ const outside = !!caller2.workspace && caller2.harness !== HOME_HARNESS && !inFolder(root, caller2.workspace);
12924
13370
  const auto = this.o.link?.created?.(record) === true;
12925
13371
  const actions = await this.knownActions(type, false);
12926
13372
  const check = this.hasCheck(type, actions);
@@ -12946,13 +13392,28 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
12946
13392
  source: typeSourceOf(type).source,
12947
13393
  next: opening === "after_first_write" ? check ? AFTER_CREATE_OPENING_CHECK : AFTER_CREATE_OPENING : opening === "now" ? check ? AFTER_CREATE_OPEN_CHECK : AFTER_CREATE_OPEN : openEarly ? check ? AFTER_CREATE_EARLY_CHECK : AFTER_CREATE_EARLY : check ? AFTER_CREATE_CHECK : AFTER_CREATE,
12948
13394
  ...isPageType(type) ? { capabilities: record.capabilities ?? {} } : {},
12949
- ...auto || capabilityNotes(record.capabilities).length ? { notes: [...auto ? [autoNote(this.o.link?.autoTarget?.() ?? null)] : [], ...capabilityNotes(record.capabilities)] } : {}
13395
+ ...auto || outside || capabilityNotes(record.capabilities).length ? { notes: [...outside ? [outsideNote(root)] : [], ...auto ? [autoNote(this.o.link?.autoTarget?.() ?? null)] : [], ...capabilityNotes(record.capabilities)] } : {}
12950
13396
  };
12951
13397
  }
13398
+ /**
13399
+ * Keeps a new artifacts folder in a Git checkout out of git: a `.gitignore` that ignores everything in it, itself
13400
+ * included. Only for a folder the daemon just made because the harness keeps artifacts in the workspace; a folder
13401
+ * the person, the project or the call chose is theirs to track.
13402
+ */
13403
+ keepOutOfGit(dir) {
13404
+ const file = join30(dir, ".gitignore");
13405
+ try {
13406
+ if (existsSync19(file)) return;
13407
+ writeFileSync9(file, "# Open Artifact keeps the artifacts made here out of git. Delete this file to track them.\n*\n");
13408
+ this.o.log(`wrote ${file}: the artifacts folder stays out of git`);
13409
+ } catch (error) {
13410
+ this.o.log(`could not write ${file}: ${error.message}`);
13411
+ }
13412
+ }
12952
13413
  /** A file's sha256, `null` when there is none. */
12953
13414
  hashOf(file) {
12954
13415
  try {
12955
- return statSync12(file).isFile() ? sha2563(readFileSync18(file)) : null;
13416
+ return statSync14(file).isFile() ? sha2563(readFileSync20(file)) : null;
12956
13417
  } catch {
12957
13418
  return null;
12958
13419
  }
@@ -13029,11 +13490,11 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13029
13490
  const written = [];
13030
13491
  for (const { clean, file, bytes } of plan) {
13031
13492
  if (bytes === null) {
13032
- rmSync9(file, { force: true });
13493
+ rmSync10(file, { force: true });
13033
13494
  written.push({ path: clean, deleted: true });
13034
13495
  continue;
13035
13496
  }
13036
- mkdirSync7(dirname11(file), { recursive: true });
13497
+ mkdirSync8(dirname14(file), { recursive: true });
13037
13498
  writeFileSync9(file, bytes);
13038
13499
  written.push({ path: clean, bytes: bytes.length, sha256: sha2563(bytes) });
13039
13500
  }
@@ -13080,20 +13541,20 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13080
13541
  if (out2.length >= MAX_LIST) return;
13081
13542
  let entries;
13082
13543
  try {
13083
- entries = readdirSync13(directory?.resolve(dir) ?? dir, { withFileTypes: true });
13544
+ entries = readdirSync14(directory?.resolve(dir) ?? dir, { withFileTypes: true });
13084
13545
  } catch {
13085
13546
  return;
13086
13547
  }
13087
13548
  for (const e of entries.sort((a, b) => a.name.localeCompare(b.name))) {
13088
13549
  if (e.name.startsWith(".") || e.name === "node_modules") continue;
13089
13550
  const r = rel ? `${rel}/${e.name}` : e.name;
13090
- if (e.isDirectory()) walk(join26(dir, e.name), r);
13551
+ if (e.isDirectory()) walk(join30(dir, e.name), r);
13091
13552
  else if (out2.length < MAX_LIST) {
13092
13553
  try {
13093
- const requested = join26(dir, e.name);
13554
+ const requested = join30(dir, e.name);
13094
13555
  const file = directory?.resolve(requested) ?? requested;
13095
- const bytes = statSync12(file).size;
13096
- out2.push({ path: r, bytes, ...hashes && bytes <= MAX_LIST_HASH ? { sha256: sha2563(readFileSync18(file)) } : {} });
13556
+ const bytes = statSync14(file).size;
13557
+ out2.push({ path: r, bytes, ...hashes && bytes <= MAX_LIST_HASH ? { sha256: sha2563(readFileSync20(file)) } : {} });
13097
13558
  } catch {
13098
13559
  }
13099
13560
  }
@@ -13106,10 +13567,10 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13106
13567
  readOne(record, path, budget, directory) {
13107
13568
  const requested = inside(record.root, path);
13108
13569
  const file = directory?.resolve(requested) ?? requested;
13109
- if (!existsSync16(file)) throw new OpenArtifactError("not_found", `No file ${path} in ${record.root}.`);
13110
- const stat2 = statSync12(file);
13570
+ if (!existsSync19(file)) throw new OpenArtifactError("not_found", `No file ${path} in ${record.root}.`);
13571
+ const stat2 = statSync14(file);
13111
13572
  if (stat2.isDirectory()) return { path, files: this.listFiles(file, true, directory) };
13112
- const buffer = readFileSync18(file);
13573
+ const buffer = readFileSync20(file);
13113
13574
  const hash = sha2563(buffer);
13114
13575
  if (buffer.subarray(0, 8e3).includes(0)) return { path, bytes: stat2.size, sha256: hash, binary: true, note: "A binary file: read it from disk if you need it." };
13115
13576
  if (budget <= 0) return { path, bytes: stat2.size, sha256: hash, note: "Not read: this result is full. Read it on its own." };
@@ -13277,20 +13738,20 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13277
13738
  if (!type) throw new OpenArtifactError("type_missing", `The type ${record.type} is not installed.`);
13278
13739
  if (!type.entry || type.entry.kind === "static" || !type.entry.actions) throw missing ?? new OpenArtifactError("unsupported", `${type.id} has no actions.`);
13279
13740
  const forward = !!this.o.link?.forwards(record, type, name);
13280
- const location = typeLocation(type);
13281
- if (location.remote && !forward) {
13741
+ const location2 = typeLocation(type);
13742
+ if (location2.remote && !forward) {
13282
13743
  const local = localPathIn(args, "args", record.root);
13283
13744
  if (local) {
13284
13745
  throw new OpenArtifactError(
13285
13746
  "unsupported",
13286
- `${type.title || type.id} runs on another computer (${location.origin}): ${name} cannot take ${local.at}, a path on this computer (${local.path}). Paths here are not sent to other computers.`,
13747
+ `${type.title || type.id} runs on another computer (${location2.origin}): ${name} cannot take ${local.at}, a path on this computer (${local.path}). Paths here are not sent to other computers.`,
13287
13748
  { fix: "Pass the content itself (as data or text in the arguments) instead of a file path. To bring a file in, use a type that runs on this computer." }
13288
13749
  );
13289
13750
  }
13290
13751
  }
13291
- const confined = caller2 ? this.workspaceDirectory(caller2) : null;
13292
- if (confined) {
13293
- const outside = pathOutside(args, "args", confined);
13752
+ const confined2 = caller2 ? this.workspaceDirectory(caller2) : null;
13753
+ if (confined2) {
13754
+ const outside = pathOutside(args, "args", confined2);
13294
13755
  if (outside) {
13295
13756
  throw new OpenArtifactError("not_granted", `${name} cannot take ${outside.at} (${outside.path}): it is outside this session's workspace.`, {
13296
13757
  fix: "Use a file inside the workspace, or pass the content itself in the arguments."
@@ -13328,7 +13789,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13328
13789
  if (own && caller2 && effect === "write") this.o.ownership?.wrote(record.id, caller2);
13329
13790
  return result;
13330
13791
  } catch (error) {
13331
- if (name === "open-artifact.db.write" && !forward && !location.remote && error instanceof OpenArtifactError && error.status === 409 && error.code === "conflict" && error.current !== void 0) {
13792
+ if (name === "open-artifact.db.write" && !forward && !location2.remote && error instanceof OpenArtifactError && error.status === 409 && error.code === "conflict" && error.current !== void 0) {
13332
13793
  const { current, ...body } = errorBody(error);
13333
13794
  return { error: body, current, executionStatus: "not_executed" };
13334
13795
  }
@@ -13377,7 +13838,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13377
13838
  }
13378
13839
  if (!args.folder) throw new OpenArtifactError("invalid_argument", "adopt takes url (an artifact) or folder (one to add).");
13379
13840
  const root = this.resolveFolder(args.folder, caller2);
13380
- if (!existsSync16(root)) throw new OpenArtifactError("not_found", `No folder ${root}.`);
13841
+ if (!existsSync19(root)) throw new OpenArtifactError("not_found", `No folder ${root}.`);
13381
13842
  const known = this.o.store.byRoot(root);
13382
13843
  if (known) return this.adopt({ url: artifactUrl(known.id) }, caller2);
13383
13844
  this.allow(caller2, "create", "Artifact adopt of a folder");
@@ -13389,7 +13850,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13389
13850
  if (marker === null) {
13390
13851
  typeId = this.o.types.list(caller2.workspace).find((t) => t.detect.some((rel) => {
13391
13852
  try {
13392
- return existsSync16(files2.resolve(rel));
13853
+ return existsSync19(files2.resolve(rel));
13393
13854
  } catch {
13394
13855
  return false;
13395
13856
  }
@@ -13400,7 +13861,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13400
13861
  }
13401
13862
  if (!typeId) throw new OpenArtifactError("invalid_argument", `Which type is ${root}? Give type_url.`);
13402
13863
  const type = this.o.types.get(typeId, caller2.workspace);
13403
- const title = args.title || contentTitle(files2, type?.titleFrom ?? null) || basename6(root);
13864
+ const title = args.title || contentTitle(files2, type?.titleFrom ?? null) || basename7(root);
13404
13865
  const capabilities = isPageType(type) ? markerCapabilities(files2) : void 0;
13405
13866
  const marked = markerTypeUid(files2);
13406
13867
  const record = this.o.store.create({
@@ -13413,6 +13874,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13413
13874
  owner: caller2,
13414
13875
  title,
13415
13876
  capabilities,
13877
+ project: this.projectFor(caller2),
13416
13878
  ...workspace ? { workspaceDirectory: workspace.identity } : {}
13417
13879
  });
13418
13880
  const auto = this.o.link?.created?.(record) === true;
@@ -13433,11 +13895,11 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13433
13895
  const noStore = new OpenArtifactError("unsupported", `${record.type} keeps no document store: write its files with Artifact publish.`);
13434
13896
  const db = (name, a) => this.action(record, name, a, noStore, caller2);
13435
13897
  const docPath = args.path ?? (args.collection && args.doc_id ? `${args.collection}/${args.doc_id}` : args.collection);
13436
- const base = caller2.workspace ? resolve16(caller2.workspace) : record.root;
13898
+ const base = caller2.workspace ? resolve19(caller2.workspace) : record.root;
13437
13899
  const writeOf = (w) => {
13438
13900
  const out2 = {};
13439
13901
  for (const key of DATA_WRITE_KEYS) if (w[key] !== void 0) out2[key] = w[key];
13440
- if (typeof out2.file_path === "string" && out2.file_path) out2.file_path = resolve16(base, out2.file_path);
13902
+ if (typeof out2.file_path === "string" && out2.file_path) out2.file_path = resolve19(base, out2.file_path);
13441
13903
  return out2;
13442
13904
  };
13443
13905
  const write = async (writes) => {
@@ -13485,9 +13947,9 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13485
13947
  }
13486
13948
  /** A read's result written to a JSON file: the agent reads it from disk instead of its context. */
13487
13949
  dataToFile(record, result, outFile, base, workspace) {
13488
- const file = workspace ? workspace.resolve(resolve16(base, outFile)) : resolve16(base, outFile);
13489
- if (file === record.root || file.startsWith(record.root + sep10)) throw new OpenArtifactError("bad_path", "out_file goes outside the artifact folder: a file there would become part of the artifact.");
13490
- mkdirSync7(dirname11(file), { recursive: true });
13950
+ const file = workspace ? workspace.resolve(resolve19(base, outFile)) : resolve19(base, outFile);
13951
+ if (file === record.root || file.startsWith(record.root + sep12)) throw new OpenArtifactError("bad_path", "out_file goes outside the artifact folder: a file there would become part of the artifact.");
13952
+ mkdirSync8(dirname14(file), { recursive: true });
13491
13953
  const { notes, url: _url, third_party_notice: notice, ...data } = result;
13492
13954
  const text3 = `${JSON.stringify(data, null, 2)}
13493
13955
  `;
@@ -13573,8 +14035,8 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13573
14035
  const touched = /* @__PURE__ */ new Set();
13574
14036
  const records = this.o.store.list();
13575
14037
  for (const p of paths) {
13576
- const abs = resolve16(caller2.workspace ?? "/", p);
13577
- const record = records.find((a) => abs === a.root || abs.startsWith(a.root + sep10));
14038
+ const abs = resolve19(caller2.workspace ?? "/", p);
14039
+ const record = records.find((a) => abs === a.root || abs.startsWith(a.root + sep12));
13578
14040
  if (record && !touched.has(record.id)) {
13579
14041
  touched.add(record.id);
13580
14042
  this.o.store.update(record.id, { agentSeenAt: now() });
@@ -13589,14 +14051,14 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
13589
14051
  });
13590
14052
 
13591
14053
  // packages/daemon/src/ws.ts
13592
- import { createHash as createHash9 } from "node:crypto";
14054
+ import { createHash as createHash10 } from "node:crypto";
13593
14055
  function acceptWebSocket(request, socket, head, protocol) {
13594
14056
  const key = request.headers["sec-websocket-key"];
13595
14057
  if (typeof key !== "string" || String(request.headers.upgrade).toLowerCase() !== "websocket") {
13596
14058
  socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
13597
14059
  return null;
13598
14060
  }
13599
- const accept = createHash9("sha1").update(key + GUID).digest("base64");
14061
+ const accept = createHash10("sha1").update(key + GUID).digest("base64");
13600
14062
  const asked = String(request.headers["sec-websocket-protocol"] ?? "").split(",").map((p) => p.trim()).filter(Boolean);
13601
14063
  const lines = ["HTTP/1.1 101 Switching Protocols", "Upgrade: websocket", "Connection: Upgrade", `Sec-WebSocket-Accept: ${accept}`];
13602
14064
  if (protocol && asked.includes(protocol)) lines.push(`Sec-WebSocket-Protocol: ${protocol}`);
@@ -13752,15 +14214,15 @@ __export(daemon_exports, {
13752
14214
  });
13753
14215
  import { randomBytes as randomBytes10 } from "node:crypto";
13754
14216
  import { EventEmitter as EventEmitter5 } from "node:events";
13755
- import { appendFileSync as appendFileSync3, cpSync as cpSync3, createReadStream, existsSync as existsSync17, mkdirSync as mkdirSync8, openSync as openSync4, readFileSync as readFileSync19, readdirSync as readdirSync14, rmSync as rmSync10, statSync as statSync13, watch as watch3, writeFileSync as writeFileSync10, writeSync, closeSync as closeSync4 } from "node:fs";
14217
+ import { appendFileSync as appendFileSync3, cpSync as cpSync3, createReadStream, existsSync as existsSync20, mkdirSync as mkdirSync9, openSync as openSync4, readFileSync as readFileSync21, readdirSync as readdirSync15, rmSync as rmSync11, statSync as statSync15, watch as watch3, writeFileSync as writeFileSync10, writeSync, closeSync as closeSync4 } from "node:fs";
13756
14218
  import { createServer as createServer2 } from "node:http";
13757
14219
  import { userInfo } from "node:os";
13758
- import { basename as basename7, dirname as dirname12, extname as extname4, isAbsolute as isAbsolute7, join as join27, resolve as resolve17, sep as sep11 } from "node:path";
14220
+ import { basename as basename8, dirname as dirname15, extname as extname4, isAbsolute as isAbsolute11, join as join31, resolve as resolve20, sep as sep13 } from "node:path";
13759
14221
  import { Readable } from "node:stream";
13760
14222
  import { fileURLToPath as fileURLToPath5 } from "node:url";
13761
14223
  function defaultUiDir(name) {
13762
14224
  const fromEnv = name === "shell" ? process.env.OPEN_ARTIFACT_SHELL_DIR : process.env.OPEN_ARTIFACT_HOME_DIR;
13763
- return fromEnv ? resolve17(fromEnv) : resolve17(here, "..", "..", "..", "dist", "daemon", name);
14225
+ return fromEnv ? resolve20(fromEnv) : resolve20(here, "..", "..", "..", "dist", "daemon", name);
13764
14226
  }
13765
14227
  function isContentPath(rel) {
13766
14228
  const parts = rel.split("/");
@@ -13770,7 +14232,7 @@ function hasContent(root, rel = "", depth = 0) {
13770
14232
  if (depth > 4) return false;
13771
14233
  let entries;
13772
14234
  try {
13773
- entries = readdirSync14(join27(root, rel), { withFileTypes: true });
14235
+ entries = readdirSync15(join31(root, rel), { withFileTypes: true });
13774
14236
  } catch {
13775
14237
  return false;
13776
14238
  }
@@ -13907,6 +14369,7 @@ var init_daemon2 = __esm({
13907
14369
  init_remote_archive();
13908
14370
  init_client2();
13909
14371
  init_src2();
14372
+ init_config();
13910
14373
  init_settings2();
13911
14374
  init_store();
13912
14375
  init_tools2();
@@ -13916,7 +14379,7 @@ var init_daemon2 = __esm({
13916
14379
  init_ws();
13917
14380
  init_package();
13918
14381
  DATA_REFRESH_MS = 15 * 6e4;
13919
- here = dirname12(fileURLToPath5(import.meta.url));
14382
+ here = dirname15(fileURLToPath5(import.meta.url));
13920
14383
  VERSION3 = package_default.version ?? "0.0.0";
13921
14384
  BOOT_PLACEHOLDER = "/*__OPEN_ARTIFACT_BOOT__*/null";
13922
14385
  UI_PATHS = { shell: "/_open-artifact/shell/", home: "/_open-artifact/home/" };
@@ -14077,8 +14540,8 @@ var init_daemon2 = __esm({
14077
14540
  this.wantPort = options.port ?? this.settings.serverPort;
14078
14541
  this.idleMs = options.idleMs ?? Number(process.env.OPEN_ARTIFACT_IDLE_MS ?? 30 * 6e4);
14079
14542
  this.quiet = options.quiet ?? false;
14080
- this.shellDir = resolve17(options.shellDir ?? defaultUiDir("shell"));
14081
- this.homeDir = resolve17(options.homeDir ?? defaultUiDir("home"));
14543
+ this.shellDir = resolve20(options.shellDir ?? defaultUiDir("shell"));
14544
+ this.homeDir = resolve20(options.homeDir ?? defaultUiDir("home"));
14082
14545
  this.logFile = files.daemonLog();
14083
14546
  const log = (line) => this.log(line);
14084
14547
  this.types = new TypeRegistry(() => this.settings, options.builtinTypesDir !== void 0 ? { builtinDir: options.builtinTypesDir } : {});
@@ -14338,15 +14801,15 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
14338
14801
  writeSync(fd, String(process.pid));
14339
14802
  closeSync4(fd);
14340
14803
  } catch {
14341
- const other = Number(readFileSync19(lock, "utf8"));
14342
- let alive2 = false;
14804
+ const other = Number(readFileSync21(lock, "utf8"));
14805
+ let alive3 = false;
14343
14806
  try {
14344
14807
  process.kill(other, 0);
14345
- alive2 = other !== process.pid;
14808
+ alive3 = other !== process.pid;
14346
14809
  } catch {
14347
- alive2 = false;
14810
+ alive3 = false;
14348
14811
  }
14349
- if (alive2) throw new OpenArtifactError("conflict", `Another open-artifact daemon (pid ${other}) runs for ${openArtifactHome2()}.`);
14812
+ if (alive3) throw new OpenArtifactError("conflict", `Another open-artifact daemon (pid ${other}) runs for ${openArtifactHome2()}.`);
14350
14813
  writeFileSync10(lock, String(process.pid), { mode: 384 });
14351
14814
  }
14352
14815
  let port = this.wantPort;
@@ -14356,7 +14819,7 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
14356
14819
  break;
14357
14820
  } catch (error) {
14358
14821
  if (error.code !== "EADDRINUSE" || i >= 20 || port === 0) {
14359
- rmSync10(lock, { force: true });
14822
+ rmSync11(lock, { force: true });
14360
14823
  throw error;
14361
14824
  }
14362
14825
  port += 1;
@@ -14579,9 +15042,9 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
14579
15042
  this.server.close();
14580
15043
  this.server.closeAllConnections?.();
14581
15044
  const state = readJson(files.daemon(), null);
14582
- if (state?.pid === process.pid) rmSync10(files.daemon(), { force: true });
15045
+ if (state?.pid === process.pid) rmSync11(files.daemon(), { force: true });
14583
15046
  try {
14584
- if (Number(readFileSync19(files.lock(), "utf8")) === process.pid) rmSync10(files.lock(), { force: true });
15047
+ if (Number(readFileSync21(files.lock(), "utf8")) === process.pid) rmSync11(files.lock(), { force: true });
14585
15048
  } catch {
14586
15049
  }
14587
15050
  this.log(`daemon ${VERSION3} stopped (${reason})`);
@@ -14707,15 +15170,15 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
14707
15170
  } catch {
14708
15171
  return this.notFound(req, res);
14709
15172
  }
14710
- this.sendFile(req, res, file, file.includes(`${sep11}assets${sep11}`) ? "public, max-age=31536000, immutable" : "no-cache");
15173
+ this.sendFile(req, res, file, file.includes(`${sep13}assets${sep13}`) ? "public, max-age=31536000, immutable" : "no-cache");
14711
15174
  }
14712
15175
  sendFile(req, res, file, cache) {
14713
15176
  let stat2;
14714
15177
  try {
14715
- stat2 = statSync13(file);
15178
+ stat2 = statSync15(file);
14716
15179
  if (stat2.isDirectory()) {
14717
- file = join27(file, "index.html");
14718
- stat2 = statSync13(file);
15180
+ file = join31(file, "index.html");
15181
+ stat2 = statSync15(file);
14719
15182
  }
14720
15183
  } catch {
14721
15184
  return this.notFound(req, res);
@@ -14738,7 +15201,7 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
14738
15201
  homePage(req, res) {
14739
15202
  req.resume();
14740
15203
  try {
14741
- sendHtml(res, readFileSync19(join27(this.homeDir, "index.html"), "utf8"));
15204
+ sendHtml(res, readFileSync21(join31(this.homeDir, "index.html"), "utf8"));
14742
15205
  return;
14743
15206
  } catch {
14744
15207
  }
@@ -14766,7 +15229,7 @@ ${rows}
14766
15229
  /** What the Shell's boot says before the page is opened: everything but `page`, `pageUrl`, `pageKind` and `problem`. */
14767
15230
  bootOf(record) {
14768
15231
  const type = this.typeOf(record);
14769
- const empty = !!type?.detect.length && !type.detect.some((rel) => existsSync17(join27(record.root, rel)));
15232
+ const empty2 = !!type?.detect.length && !type.detect.some((rel) => existsSync20(join31(record.root, rel)));
14770
15233
  const typeTitle = type?.title ?? record.type;
14771
15234
  return {
14772
15235
  id: record.id,
@@ -14779,8 +15242,8 @@ ${rows}
14779
15242
  pageUrl: null,
14780
15243
  pageKind: null,
14781
15244
  problem: null,
14782
- empty,
14783
- prompt: empty ? takeOverPrompt(record, typeTitle) : null,
15245
+ empty: empty2,
15246
+ prompt: empty2 ? takeOverPrompt(record, typeTitle) : null,
14784
15247
  owner: record.owner ? { harness: record.owner.harness, key: sessionKeyOf(record.owner) } : null,
14785
15248
  agentName: this.agentNameOf(record),
14786
15249
  userName: safeUserName(),
@@ -14856,7 +15319,7 @@ ${rows}
14856
15319
  const record = this.touchOpened(found2);
14857
15320
  let template = null;
14858
15321
  try {
14859
- template = readFileSync19(join27(this.shellDir, "index.html"), "utf8");
15322
+ template = readFileSync21(join31(this.shellDir, "index.html"), "utf8");
14860
15323
  } catch {
14861
15324
  }
14862
15325
  let boot;
@@ -14890,7 +15353,7 @@ ${rows}
14890
15353
  const walk = (dir, rel, depth) => {
14891
15354
  let entries;
14892
15355
  try {
14893
- entries = readdirSync14(dir, { withFileTypes: true });
15356
+ entries = readdirSync15(dir, { withFileTypes: true });
14894
15357
  } catch {
14895
15358
  return;
14896
15359
  }
@@ -14898,12 +15361,12 @@ ${rows}
14898
15361
  if (seen++ > 4e3) return;
14899
15362
  const path = rel ? `${rel}/${entry.name}` : entry.name;
14900
15363
  if (!isContentPath(path) || entry.name === "node_modules" || entry.name === "exports") continue;
14901
- const full = join27(dir, entry.name);
15364
+ const full = join31(dir, entry.name);
14902
15365
  if (entry.isDirectory()) {
14903
15366
  if (depth < 5) walk(full, path, depth + 1);
14904
15367
  } else {
14905
15368
  try {
14906
- newest = Math.max(newest, statSync13(full).mtimeMs);
15369
+ newest = Math.max(newest, statSync15(full).mtimeMs);
14907
15370
  } catch {
14908
15371
  }
14909
15372
  }
@@ -14921,18 +15384,18 @@ ${rows}
14921
15384
  const walk = (dir, depth) => {
14922
15385
  let entries;
14923
15386
  try {
14924
- entries = readdirSync14(dir, { withFileTypes: true });
15387
+ entries = readdirSync15(dir, { withFileTypes: true });
14925
15388
  } catch {
14926
15389
  return;
14927
15390
  }
14928
15391
  for (const entry of entries) {
14929
15392
  if (seen++ > 2e4) return;
14930
- const full = join27(dir, entry.name);
15393
+ const full = join31(dir, entry.name);
14931
15394
  if (entry.isDirectory()) {
14932
15395
  if (depth < 8 && entry.name !== "node_modules") walk(full, depth + 1);
14933
15396
  } else if (entry.isFile()) {
14934
15397
  try {
14935
- bytes += statSync13(full).size;
15398
+ bytes += statSync15(full).size;
14936
15399
  } catch {
14937
15400
  }
14938
15401
  }
@@ -14975,11 +15438,11 @@ ${rows}
14975
15438
  /** A folder a Library call names (absolute or `~/...`), resolved; it must exist and be a folder. */
14976
15439
  folderArg(value) {
14977
15440
  const given = typeof value === "string" ? value.trim() : "";
14978
- if (!given || !isAbsolute7(given) && !given.startsWith("~")) throw new OpenArtifactError("invalid_argument", "folder: an absolute path (or ~/...).");
14979
- const root = resolve17(expandHome(given));
15441
+ if (!given || !isAbsolute11(given) && !given.startsWith("~")) throw new OpenArtifactError("invalid_argument", "folder: an absolute path (or ~/...).");
15442
+ const root = resolve20(expandHome(given));
14980
15443
  let dir = false;
14981
15444
  try {
14982
- dir = statSync13(root).isDirectory();
15445
+ dir = statSync15(root).isDirectory();
14983
15446
  } catch {
14984
15447
  }
14985
15448
  if (!dir) throw new OpenArtifactError("not_found", `No folder ${root}.`);
@@ -14994,6 +15457,7 @@ ${rows}
14994
15457
  typeRelease: record.typeRelease,
14995
15458
  typeUid: record.typeUid ?? null,
14996
15459
  owner: record.owner,
15460
+ project: record.project ?? null,
14997
15461
  ...workspace ? { workspaceDirectory: workspace } : {}
14998
15462
  };
14999
15463
  if (record.type === "docs") {
@@ -15011,15 +15475,15 @@ ${rows}
15011
15475
  return this.store.create({ ...inherited, root: copy.root, title: copy.name });
15012
15476
  }
15013
15477
  const directory = workspace ? new WorkspaceDirectory(workspace.root, workspace) : void 0;
15014
- const parent = directory?.root === source ? source : dirname12(source);
15015
- const base = basename7(source) || "work";
15016
- const target = (name2) => directory?.resolve(join27(parent, name2), false) ?? join27(parent, name2);
15478
+ const parent = directory?.root === source ? source : dirname15(source);
15479
+ const base = basename8(source) || "work";
15480
+ const target = (name2) => directory?.resolve(join31(parent, name2), false) ?? join31(parent, name2);
15017
15481
  let root = target(`${base}-copy`);
15018
15482
  const skip = (name2) => name2.startsWith(".") || name2 === "history" || name2 === "exports" || name2 === "node_modules" || name2 === "_agent";
15019
- const children = readdirSync14(source).filter((name2) => !skip(name2));
15483
+ const children = readdirSync15(source).filter((name2) => !skip(name2));
15020
15484
  for (let n = 2; ; n++) {
15021
15485
  try {
15022
- mkdirSync8(root);
15486
+ mkdirSync9(root);
15023
15487
  break;
15024
15488
  } catch (error) {
15025
15489
  if (error.code !== "EEXIST") throw error;
@@ -15028,7 +15492,7 @@ ${rows}
15028
15492
  }
15029
15493
  const files2 = directory ? new WorkspaceDirectory(source) : void 0;
15030
15494
  for (const name2 of children) {
15031
- cpSync3(join27(source, name2), join27(root, name2), {
15495
+ cpSync3(join31(source, name2), join31(root, name2), {
15032
15496
  recursive: true,
15033
15497
  errorOnExist: false,
15034
15498
  ...files2 ? { dereference: true, filter: (path) => {
@@ -15040,11 +15504,11 @@ ${rows}
15040
15504
  return this.store.create({ ...inherited, root, title: `Copy of ${record.title}`.slice(0, 200) });
15041
15505
  }
15042
15506
  thumbnailFile(id) {
15043
- return join27(files.thumbnails(), `${id}.jpg`);
15507
+ return join31(files.thumbnails(), `${id}.jpg`);
15044
15508
  }
15045
15509
  /** The content stamp a thumbnail was taken at, or `null`. */
15046
15510
  thumbnailOf(id) {
15047
- return readJson(join27(files.thumbnails(), `${id}.json`), null)?.v ?? null;
15511
+ return readJson(join31(files.thumbnails(), `${id}.json`), null)?.v ?? null;
15048
15512
  }
15049
15513
  /** One artifact as lists show it. */
15050
15514
  artifactView(record) {
@@ -15059,7 +15523,8 @@ ${rows}
15059
15523
  typeMissing: !type,
15060
15524
  root: record.root,
15061
15525
  // Moved or renamed outside Open Artifact (or deleted): the record still names the old place.
15062
- folderMissing: !existsSync17(record.root),
15526
+ folderMissing: !existsSync20(record.root),
15527
+ project: record.project ?? null,
15063
15528
  view_url: this.viewUrl(record.id),
15064
15529
  page_url: this.pages.get(record.id)?.page_url ?? this.viewUrl(record.id),
15065
15530
  owner: record.owner ? { harness: record.owner.harness, session: record.owner.session, workspace: record.owner.workspace, ...live } : null,
@@ -15105,12 +15570,12 @@ ${rows}
15105
15570
  /** The project types of the folders this computer knows, but `skip` (whose types the answer lists already). */
15106
15571
  projectTypes(skip) {
15107
15572
  const known = [...this.harnesses.workspaces(), ...this.settings.trustedProjects ?? [], this.settings.homeWorkspace, ...this.typeProjects];
15108
- const folders = new Set(known.map((d) => resolve17(d)));
15573
+ const folders = new Set(known.map((d) => resolve20(d)));
15109
15574
  const out2 = [];
15110
15575
  for (const dir of folders) {
15111
- if (skip && resolve17(skip) === dir) continue;
15576
+ if (skip && resolve20(skip) === dir) continue;
15112
15577
  const root = this.types.roots(dir).find((r) => r.scope === "project");
15113
- if (!root || !existsSync17(root.root)) continue;
15578
+ if (!root || !existsSync20(root.root)) continue;
15114
15579
  const types3 = this.types.list(dir, { includeShadowed: true }).filter((t) => t.scope === "project");
15115
15580
  if (types3.length) out2.push({ dir, root: root.root, trusted: root.trusted, types: types3.map((t) => this.typeView(t)) });
15116
15581
  }
@@ -15173,9 +15638,9 @@ ${rows}
15173
15638
  }
15174
15639
  if (name === LIBRARY_ROUTES.typesPreview || name === LIBRARY_ROUTES.import) return this.packageCall(req, res, name);
15175
15640
  const body = await readJsonBody(req);
15176
- const workspace = typeof body.workspace === "string" && isAbsolute7(body.workspace) ? resolve17(body.workspace) : null;
15641
+ const workspace = typeof body.workspace === "string" && isAbsolute11(body.workspace) ? resolve20(body.workspace) : null;
15177
15642
  const project = typeof body.project === "string" && body.project ? body.project : null;
15178
- if (project !== null && !isAbsolute7(project)) throw new OpenArtifactError("invalid_argument", "project: the project folder, as an absolute path.");
15643
+ if (project !== null && !isAbsolute11(project)) throw new OpenArtifactError("invalid_argument", "project: the project folder, as an absolute path.");
15179
15644
  const o = { settings: this.settings, registry: this.types, workspace: workspace ?? (body.scope === "project" ? project : null) ?? this.settings.homeWorkspace };
15180
15645
  const changed = () => {
15181
15646
  this.settings = loadSettings(this.preset);
@@ -15186,24 +15651,24 @@ ${rows}
15186
15651
  case R.typesNew: {
15187
15652
  const made = newType({ id: body.id, scope: body.scope, template: body.template, name: body.name, project }, o);
15188
15653
  this.log(`audit: made the type ${made.id} (${made.scope}, ${String(body.template ?? "page")}) at ${made.dir}, asked by ${this.askedBy(req, name)}`);
15189
- if (made.scope === "project" && project) this.typeProjects.add(resolve17(project));
15654
+ if (made.scope === "project" && project) this.typeProjects.add(resolve20(project));
15190
15655
  changed();
15191
15656
  return sendJson(res, 200, made);
15192
15657
  }
15193
15658
  case R.typesFrom: {
15194
15659
  if (body.path !== void 0) {
15195
15660
  if (!this.hasToken(req)) throw new OpenArtifactError("not_granted", `${R.typesFrom} with a path is for the command line: open-artifact types from <path> --id <id>.`, { status: 403 });
15196
- if (typeof body.path !== "string" || !isAbsolute7(body.path)) throw new OpenArtifactError("invalid_argument", "path: the saved page (a folder or an .html file), as an absolute path.");
15661
+ if (typeof body.path !== "string" || !isAbsolute11(body.path)) throw new OpenArtifactError("invalid_argument", "path: the saved page (a folder or an .html file), as an absolute path.");
15197
15662
  const made2 = typeFromSaved(body.path, { id: body.id, scope: body.scope, name: body.name, project }, o);
15198
15663
  this.log(`audit: made the type ${made2.id} from the saved page ${made2.source} at ${made2.dir}, asked by ${this.askedBy(req, name)}`);
15199
- if (made2.scope === "project" && project) this.typeProjects.add(resolve17(project));
15664
+ if (made2.scope === "project" && project) this.typeProjects.add(resolve20(project));
15200
15665
  changed();
15201
15666
  return sendJson(res, 200, made2);
15202
15667
  }
15203
15668
  const record = this.store.require(body.artifact);
15204
15669
  const made = typeFromPage(record, this.typeOf(record), { id: body.id, scope: body.scope, name: body.name, project }, o);
15205
15670
  this.log(`audit: made the type ${made.id} from ${record.id} at ${made.dir}, asked by ${this.askedBy(req, name)}`);
15206
- if (made.scope === "project" && project) this.typeProjects.add(resolve17(project));
15671
+ if (made.scope === "project" && project) this.typeProjects.add(resolve20(project));
15207
15672
  changed();
15208
15673
  return sendJson(res, 200, made);
15209
15674
  }
@@ -15320,7 +15785,7 @@ ${rows}
15320
15785
  bytes = raw;
15321
15786
  body = { name: url.searchParams.get("name") ?? void 0, as: url.searchParams.get("as") ?? void 0, folder: url.searchParams.get("folder") ?? void 0 };
15322
15787
  }
15323
- const label = typeof body.name === "string" && body.name ? (json ? basename7(body.name) : body.name).slice(0, 1e3) : preview ? "the package" : "the archive";
15788
+ const label = typeof body.name === "string" && body.name ? (json ? basename8(body.name) : body.name).slice(0, 1e3) : preview ? "the package" : "the archive";
15324
15789
  if (preview) {
15325
15790
  const as = typeof body.as === "string" && body.as ? body.as : null;
15326
15791
  if (!bytes) {
@@ -15335,14 +15800,14 @@ ${rows}
15335
15800
  const workspace = this.settings.homeWorkspace ?? null;
15336
15801
  const read = await readArtifactArchive(bytes, label, { registry: this.types, workspace });
15337
15802
  const folder = typeof body.folder === "string" && body.folder ? body.folder : void 0;
15338
- if (folder && !isAbsolute7(folder)) throw new OpenArtifactError("invalid_argument", "folder: where to put it, as an absolute path.");
15339
- const base = folder ? resolve17(folder) : this.tools.resolveFolder(void 0, { harness: "home", session: null, workspace }, read.top);
15803
+ if (folder && !isAbsolute11(folder)) throw new OpenArtifactError("invalid_argument", "folder: where to put it, as an absolute path.");
15804
+ const base = folder ? resolve20(folder) : this.tools.resolveFolder(void 0, { harness: "home", session: null, workspace }, read.top);
15340
15805
  let dest = base;
15341
- if (!folder) for (let n = 2; existsSync17(dest); n++) dest = `${base}-${n}`;
15806
+ if (!folder) for (let n = 2; existsSync20(dest); n++) dest = `${base}-${n}`;
15342
15807
  const unpacked = await unpackArtifactArchive(bytes, read, dest);
15343
15808
  const record = await this.adoptFolder(unpacked.root);
15344
15809
  if (!record) {
15345
- rmSync10(unpacked.root, { recursive: true, force: true });
15810
+ rmSync11(unpacked.root, { recursive: true, force: true });
15346
15811
  throw new OpenArtifactError("bad_archive", `${label} could not be added as an artifact.`);
15347
15812
  }
15348
15813
  this.log(`audit: imported ${label} as ${record.id} (${read.type.id}${read.marker.typeUid ? `, uid ${read.marker.typeUid}` : ""}) at ${record.root}, asked by ${this.askedBy(req, name)}`);
@@ -15399,7 +15864,7 @@ ${rows}
15399
15864
  let timer;
15400
15865
  try {
15401
15866
  const watcher = watch3(record.root, { recursive: true, persistent: false }, (_event, name) => {
15402
- const rel = String(name ?? "").split(sep11).join("/");
15867
+ const rel = String(name ?? "").split(sep13).join("/");
15403
15868
  if (!rel || rel.split("/").some((part) => part.startsWith("."))) return;
15404
15869
  changed.add(rel);
15405
15870
  clearTimeout(timer);
@@ -15459,11 +15924,11 @@ ${rows}
15459
15924
  if (parts.some((part) => part.startsWith("."))) return this.notFound(req, res);
15460
15925
  let file;
15461
15926
  try {
15462
- file = parts.length ? inside(resolve17(base), parts.join("/")) : resolve17(base);
15927
+ file = parts.length ? inside(resolve20(base), parts.join("/")) : resolve20(base);
15463
15928
  } catch {
15464
15929
  return this.notFound(req, res);
15465
15930
  }
15466
- if (existsSync17(file) && !realInside(base, file)) return this.notFound(req, res);
15931
+ if (existsSync20(file) && !realInside(base, file)) return this.notFound(req, res);
15467
15932
  if (!type.trusted) res.setHeader("Content-Security-Policy", installedTypeCsp(type.network));
15468
15933
  this.sendFile(req, res, file, "no-cache");
15469
15934
  }
@@ -15805,6 +16270,18 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
15805
16270
  const answer = { openInDesktop: this.settings.openInDesktop === true };
15806
16271
  return sendJson(res, 200, answer);
15807
16272
  }
16273
+ case R.configSet: {
16274
+ if (get2) throw new OpenArtifactError("invalid_argument", `${R.configSet} is a write (POST).`);
16275
+ const refusal = this.originRefusal(req, name) ?? (req.headers["x-open-artifact-agent"] ? "Changing an Open Artifact setting is for the person to decide: they run open-artifact config set in their own terminal." : null);
16276
+ if (refusal) {
16277
+ req.resume();
16278
+ return sendJson(res, 403, { code: "not_granted", message: refusal });
16279
+ }
16280
+ const done = configSet(await readJsonBody(req));
16281
+ this.settings = loadSettings(this.preset);
16282
+ this.log(`audit: ${done.value === null ? "removed" : "set"} ${done.key}${done.value === null ? "" : ` = ${JSON.stringify(done.value)}`} in ${done.file}${done.scope === "local" ? ` (for ${done.project})` : ""}, asked by ${this.askedBy(req, name)}`);
16283
+ return sendJson(res, 200, done);
16284
+ }
15808
16285
  case R.embed: {
15809
16286
  const answer = { ...this.harnesses.embed.origins(), hosts: this.harnesses.embed.hostOrigins() };
15810
16287
  return sendJson(res, 200, answer);
@@ -15840,7 +16317,7 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
15840
16317
  if (get2) {
15841
16318
  let image2;
15842
16319
  try {
15843
- image2 = readFileSync19(this.thumbnailFile(record.id));
16320
+ image2 = readFileSync21(this.thumbnailFile(record.id));
15844
16321
  } catch {
15845
16322
  throw new OpenArtifactError("not_found", "No thumbnail yet.");
15846
16323
  }
@@ -15856,7 +16333,7 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
15856
16333
  const v = url.searchParams.get("v") || this.contentAt(record);
15857
16334
  ensureDir(files.thumbnails());
15858
16335
  writeFileSync10(this.thumbnailFile(record.id), image);
15859
- writeJson(join27(files.thumbnails(), `${record.id}.json`), { v, at: (/* @__PURE__ */ new Date()).toISOString() });
16336
+ writeJson(join31(files.thumbnails(), `${record.id}.json`), { v, at: (/* @__PURE__ */ new Date()).toISOString() });
15860
16337
  return sendJson(res, 200, { thumbnail: v });
15861
16338
  }
15862
16339
  case R.restore: {
@@ -15883,7 +16360,7 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
15883
16360
  const typeId = String(body.type ?? "").replace(/^open-artifact:\/\/type\//, "");
15884
16361
  if (!typeId) throw new OpenArtifactError("invalid_argument", "type: the type id (or open-artifact://type/<id>) to create from.");
15885
16362
  const folder = typeof body.folder === "string" && body.folder.trim() ? body.folder.trim() : void 0;
15886
- if (folder && !isAbsolute7(folder) && !folder.startsWith("~")) throw new OpenArtifactError("invalid_argument", "folder: an absolute path (or ~/...).");
16363
+ if (folder && !isAbsolute11(folder) && !folder.startsWith("~")) throw new OpenArtifactError("invalid_argument", "folder: an absolute path (or ~/...).");
15887
16364
  const caller2 = { harness: HOME_HARNESS, session: null, workspace: this.settings.homeWorkspace };
15888
16365
  const blank = body.blank === true;
15889
16366
  const made = await this.tools.call(
@@ -15905,9 +16382,9 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
15905
16382
  } catch (error) {
15906
16383
  this.closePage(record);
15907
16384
  this.store.remove(record.id);
15908
- rmSync10(join27(files.trash(), `${record.id}.json`), { force: true });
16385
+ rmSync11(join31(files.trash(), `${record.id}.json`), { force: true });
15909
16386
  try {
15910
- if (readdirSync14(record.root).every((name2) => name2 === ".artifact.json")) rmSync10(record.root, { recursive: true, force: true });
16387
+ if (readdirSync15(record.root).every((name2) => name2 === ".artifact.json")) rmSync11(record.root, { recursive: true, force: true });
15911
16388
  } catch {
15912
16389
  }
15913
16390
  throw error;
@@ -15933,9 +16410,9 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
15933
16410
  const root = this.folderArg(body.folder);
15934
16411
  const known = this.store.byRoot(root);
15935
16412
  if (known) return sendJson(res, 200, this.artifactView(known));
15936
- const marked = readJson(join27(root, ".artifact.json"), null);
16413
+ const marked = readJson(join31(root, ".artifact.json"), null);
15937
16414
  const of = typeof marked?.id === "string" ? this.store.get(marked.id) : null;
15938
- if (of && !existsSync17(of.root)) {
16415
+ if (of && !existsSync20(of.root)) {
15939
16416
  throw new OpenArtifactError("conflict", `${root} is the folder of ${of.id} ("${of.title}"), which the library has at ${of.root}, a folder that is gone.`, {
15940
16417
  fix: `Relocate that artifact instead: ${LIBRARY_ROUTES.relocate} { id: "${of.id}", folder: "${root}" }.`
15941
16418
  });
@@ -15951,7 +16428,7 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
15951
16428
  const body = await readJsonBody(req);
15952
16429
  const record = this.store.require(body.id ?? body.url);
15953
16430
  const root = this.folderArg(body.folder);
15954
- const marked = readJson(join27(root, ".artifact.json"), null);
16431
+ const marked = readJson(join31(root, ".artifact.json"), null);
15955
16432
  if (!marked) throw new OpenArtifactError("invalid_argument", `${root} has no .artifact.json: it is not an artifact's folder.`);
15956
16433
  if (marked.id !== record.id) {
15957
16434
  throw new OpenArtifactError("conflict", `${root} is not the folder of ${record.id}: its .artifact.json names ${typeof marked.id === "string" ? marked.id : "no id"}.`, {
@@ -15960,7 +16437,7 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
15960
16437
  }
15961
16438
  const other = this.store.byRoot(root);
15962
16439
  if (other && other.id !== record.id) throw new OpenArtifactError("conflict", `${root} is already the folder of ${other.id}.`);
15963
- if (resolve17(record.root) === root) return sendJson(res, 200, this.artifactView(record));
16440
+ if (resolve20(record.root) === root) return sendJson(res, 200, this.artifactView(record));
15964
16441
  this.closePage(record);
15965
16442
  this.shellOpens.delete(record.id);
15966
16443
  this.contentStamps.delete(record.root);
@@ -16090,7 +16567,7 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
16090
16567
  }
16091
16568
  case "artifacts.publish": {
16092
16569
  const body = await readJsonBody(req);
16093
- const folder = typeof body.folder === "string" && body.folder ? resolve17(expandHome(body.folder)) : null;
16570
+ const folder = typeof body.folder === "string" && body.folder ? resolve20(expandHome(body.folder)) : null;
16094
16571
  let record = folder ? this.store.byRoot(folder) : this.store.require(body.id ?? body.url);
16095
16572
  let adopted = false;
16096
16573
  if (!record && folder && body.adopt === true) {
@@ -16245,9 +16722,9 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
16245
16722
 
16246
16723
  // packages/daemon/src/bin/open-artifact.ts
16247
16724
  init_src();
16248
- import { execFileSync } from "node:child_process";
16249
- import { existsSync as existsSync18, readFileSync as readFileSync20, realpathSync as realpathSync5 } from "node:fs";
16250
- import { resolve as resolvePath, sep as sep12 } from "node:path";
16725
+ import { execFileSync as execFileSync2 } from "node:child_process";
16726
+ import { existsSync as existsSync21, readFileSync as readFileSync22, realpathSync as realpathSync5 } from "node:fs";
16727
+ import { resolve as resolvePath, sep as sep14 } from "node:path";
16251
16728
  import { createInterface as createInterface2 } from "node:readline";
16252
16729
 
16253
16730
  // packages/daemon/src/agent-session.ts
@@ -16319,6 +16796,8 @@ var ACT_TEXT = {
16319
16796
  "type-disable": { what: "Turning a type off", panel: "switch it off in the Types tab of the home page" },
16320
16797
  "type-trust": { what: "Trusting a project's types", panel: "trust the project in the Types tab of the home page" },
16321
16798
  "type-untrust": { what: "Taking back the trust in a project's types", panel: "run the command" },
16799
+ // Where artifacts go and the like: standing configuration of this computer or of a repository.
16800
+ "config-set": { what: "Changing an Open Artifact setting", panel: "run the command" },
16322
16801
  // Another publisher's type, whose instructions agents will be given: the person reads it and decides.
16323
16802
  "type-install": { what: "Installing a type", panel: "install it from the Types tab of the home page, where they read it first" },
16324
16803
  "type-update": { what: "Updating an installed type", panel: "update it from the Types tab of the home page" },
@@ -16558,6 +17037,7 @@ function remoteRemovedText(removed) {
16558
17037
  }
16559
17038
 
16560
17039
  // packages/daemon/src/bin/open-artifact.ts
17040
+ init_config();
16561
17041
  init_settings2();
16562
17042
  init_types();
16563
17043
  init_type_authoring2();
@@ -16569,8 +17049,8 @@ init_package();
16569
17049
  init_harness_skill();
16570
17050
  init_settings2();
16571
17051
  init_types();
16572
- import { existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "node:fs";
16573
- import { join as join15, resolve as resolve13 } from "node:path";
17052
+ import { existsSync as existsSync11, mkdirSync as mkdirSync5, readFileSync as readFileSync10, writeFileSync as writeFileSync5 } from "node:fs";
17053
+ import { join as join18, resolve as resolve15 } from "node:path";
16574
17054
  var VERSION2 = package_default.version ?? "0.0.0";
16575
17055
  function renderSkillFor(options) {
16576
17056
  const form = options.form ?? "full";
@@ -16578,7 +17058,7 @@ function renderSkillFor(options) {
16578
17058
  const registry = new TypeRegistry(loadSettings);
16579
17059
  try {
16580
17060
  const harness = options.harness || "cli";
16581
- const workspace = resolve13(options.workspace ?? process.cwd());
17061
+ const workspace = resolve15(options.workspace ?? process.cwd());
16582
17062
  const params = { form, ...options.command ? { command: options.command } : {} };
16583
17063
  return skillFor(params, {
16584
17064
  harness,
@@ -16596,16 +17076,16 @@ function installSkillFile(options) {
16596
17076
  throw new OpenArtifactError("invalid_argument", "--command <name>: lowercase letters, digits, - and _, without the slash.");
16597
17077
  }
16598
17078
  const skill = renderSkillFor(options);
16599
- const folder = join15(resolve13(options.dir), skill.name);
16600
- const file = join15(folder, "SKILL.md");
16601
- if (existsSync9(file)) {
16602
- const text3 = readFileSync9(file, "utf8");
17079
+ const folder = join18(resolve15(options.dir), skill.name);
17080
+ const file = join18(folder, "SKILL.md");
17081
+ if (existsSync11(file)) {
17082
+ const text3 = readFileSync10(file, "utf8");
16603
17083
  if (!options.force && !skillFileKey(text3, SKILL_GENERATED_BY)) {
16604
17084
  throw new OpenArtifactError("conflict", `${file} was not written by Open Artifact: it stays.`, { fix: "Pass --force to replace it, or choose another --dir or --command." });
16605
17085
  }
16606
17086
  if (skillFileKey(text3, "etag") === skill.etag) return { file, written: false, etag: skill.etag, reason: "unchanged" };
16607
17087
  }
16608
- mkdirSync4(folder, { recursive: true });
17088
+ mkdirSync5(folder, { recursive: true });
16609
17089
  writeFileSync5(file, renderedSkillFile(skill));
16610
17090
  return { file, written: true, etag: skill.etag };
16611
17091
  }
@@ -16707,6 +17187,7 @@ async function runDoctor(options) {
16707
17187
  home: openArtifactHome2(),
16708
17188
  harness: options.harness ?? null,
16709
17189
  session: options.session ?? null,
17190
+ workspace: options.workspace ?? null,
16710
17191
  env,
16711
17192
  daemon: () => daemon3 ??= readDaemon().catch(() => null)
16712
17193
  };
@@ -16735,17 +17216,17 @@ function doctorText(report) {
16735
17216
  // packages/daemon/src/doctor-checks.ts
16736
17217
  init_src2();
16737
17218
  init_src();
16738
- import { accessSync, constants as constants2, existsSync as existsSync11, readFileSync as readFileSync11, statSync as statSync8 } from "node:fs";
16739
- import { join as join19 } from "node:path";
17219
+ import { accessSync as accessSync2, constants as constants3, existsSync as existsSync14, readFileSync as readFileSync13, statSync as statSync10 } from "node:fs";
17220
+ import { join as join23 } from "node:path";
16740
17221
 
16741
17222
  // packages/daemon/src/doctor-conformance.ts
16742
17223
  init_src2();
16743
17224
  init_harness_profiles();
16744
17225
  init_paths();
16745
17226
  init_package();
16746
- import { mkdtempSync, rmSync as rmSync5 } from "node:fs";
17227
+ import { mkdtempSync, rmSync as rmSync6 } from "node:fs";
16747
17228
  import { tmpdir } from "node:os";
16748
- import { join as join17 } from "node:path";
17229
+ import { join as join20 } from "node:path";
16749
17230
  var CONFORMANCE_TITLE = "open-artifact doctor test";
16750
17231
  var CONFORMANCE_WAKE_TEXT = "open-artifact doctor is checking that a request from the page reaches you. Nothing to do: reply in one line that you got it.";
16751
17232
  var TOOLS2 = ["Artifact", "ArtifactData", "ArtifactComments"];
@@ -16911,8 +17392,8 @@ var toolsStep = {
16911
17392
  const create = run.quickstart.create;
16912
17393
  if (!create?.type_url) throw new Error(`quickstart answered no create call for ${type.id}`);
16913
17394
  run.typeUrl = String(create.type_url);
16914
- run.folder = mkdtempSync(join17(tmpdir(), "open-artifact-doctor-"));
16915
- const made = await call(run, context, "Artifact", { ...create, title: CONFORMANCE_TITLE, folder: join17(run.folder, "artifact"), open: "never" });
17395
+ run.folder = mkdtempSync(join20(tmpdir(), "open-artifact-doctor-"));
17396
+ const made = await call(run, context, "Artifact", { ...create, title: CONFORMANCE_TITLE, folder: join20(run.folder, "artifact"), open: "never" });
16916
17397
  const url = String(made.url ?? "");
16917
17398
  run.artifact = { url, id: url.split("/").pop() ?? "" };
16918
17399
  const detail = await api(run.state, "artifact", void 0, { query: { id: run.artifact.id } });
@@ -17025,7 +17506,7 @@ var rulesStep = {
17025
17506
  run.probe = `doctor-probe-${Math.random().toString(36).slice(2, 10)}`;
17026
17507
  try {
17027
17508
  await run.client.attach({ session: run.probe, ...run.workspace ? { workspace: run.workspace } : {}, role: refused.role });
17028
- const args = refused.need === "create" ? { action: "publish", type_url: run.typeUrl, title: `${CONFORMANCE_TITLE} (probe)`, folder: join17(run.folder, "probe"), open: "never" } : refused.need === "modify" ? { action: "publish", url: run.artifact.url, files: { "doctor-probe.txt": "probe" } } : { action: "delete", url: run.artifact.url };
17509
+ const args = refused.need === "create" ? { action: "publish", type_url: run.typeUrl, title: `${CONFORMANCE_TITLE} (probe)`, folder: join20(run.folder, "probe"), open: "never" } : refused.need === "modify" ? { action: "publish", url: run.artifact.url, files: { "doctor-probe.txt": "probe" } } : { action: "delete", url: run.artifact.url };
17029
17510
  try {
17030
17511
  const made = await call(run, context, "Artifact", args, run.probe);
17031
17512
  if (typeof made.url === "string" && refused.need === "create") run.extra.push(made.url);
@@ -17115,7 +17596,7 @@ var cleanup = {
17115
17596
  if (run.probe && run.client) await run.client.detach({ session: run.probe }).catch(() => void 0);
17116
17597
  if (run.folder) {
17117
17598
  try {
17118
- rmSync5(run.folder, { recursive: true, force: true });
17599
+ rmSync6(run.folder, { recursive: true, force: true });
17119
17600
  removed.push(run.folder);
17120
17601
  } catch (error) {
17121
17602
  left.push(`${run.folder} (${message(error)})`);
@@ -17129,6 +17610,203 @@ var cleanup = {
17129
17610
  };
17130
17611
  var CONFORMANCE_CHECKS = [discovery, profileStep, sessionStep, toolsStep, commandsStep, openStep, wakeStep, rulesStep, contextStep, registrationStep, cleanup];
17131
17612
 
17613
+ // packages/daemon/src/doctor-location.ts
17614
+ init_src();
17615
+ init_harness_profiles();
17616
+ init_paths();
17617
+ init_project();
17618
+ init_settings2();
17619
+ import { accessSync, constants as constants2, existsSync as existsSync13, readFileSync as readFileSync12, statSync as statSync8 } from "node:fs";
17620
+ import { homedir as homedir6 } from "node:os";
17621
+ import { dirname as dirname11, isAbsolute as isAbsolute7, join as join21, relative as relative8, resolve as resolve17 } from "node:path";
17622
+ var isObject6 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
17623
+ var confined = (env) => env.OPEN_ARTIFACT_WORKSPACE_FOLDERS_ONLY === "1";
17624
+ function within3(dir, folder) {
17625
+ if (samePath(dir, folder)) return true;
17626
+ const path = relative8(resolve17(folder), resolve17(dir));
17627
+ return !!path && !path.startsWith("..") && !isAbsolute7(path);
17628
+ }
17629
+ var expand = (path) => path === "~" ? homedir6() : path.startsWith("~/") || path.startsWith("~\\") ? join21(homedir6(), path.slice(2)) : path;
17630
+ var readText = (file) => {
17631
+ try {
17632
+ return readFileSync12(file, "utf8");
17633
+ } catch {
17634
+ return null;
17635
+ }
17636
+ };
17637
+ var WRITABLE = {
17638
+ "claude-code": {
17639
+ fix: (dir) => `Let Claude Code write there: claude --add-dir ${dir}, or add it to permissions.additionalDirectories in ~/.claude/settings.json (its auto mode needs neither).`,
17640
+ allowedIn: (dir, workspace, env) => {
17641
+ const own = join21(env.CLAUDE_CONFIG_DIR || join21(homedir6(), ".claude"), "settings.json");
17642
+ const candidates = [own, ...workspace ? [join21(workspace, ".claude", "settings.json"), join21(workspace, ".claude", "settings.local.json")] : []];
17643
+ for (const file of candidates) {
17644
+ const text3 = readText(file);
17645
+ if (!text3) continue;
17646
+ try {
17647
+ const listed3 = JSON.parse(text3)?.permissions?.additionalDirectories;
17648
+ if (!Array.isArray(listed3)) continue;
17649
+ if (listed3.some((entry) => typeof entry === "string" && isAbsolute7(expand(entry)) && within3(dir, expand(entry)))) return file;
17650
+ } catch {
17651
+ }
17652
+ }
17653
+ return null;
17654
+ }
17655
+ },
17656
+ codex: {
17657
+ fix: (dir) => `Let Codex write there: codex --add-dir ${dir}, or sandbox_workspace_write.writable_roots = ["${dir}"] in ~/.codex/config.toml.`,
17658
+ allowedIn: (dir, _workspace, env) => {
17659
+ const file = join21(env.CODEX_HOME || join21(homedir6(), ".codex"), "config.toml");
17660
+ const text3 = readText(file);
17661
+ if (!text3) return null;
17662
+ for (const [, list] of text3.matchAll(/^\s*writable_roots\s*=\s*\[([^\]]*)\]/gm)) {
17663
+ for (const [, double, single] of list.matchAll(/"([^"]*)"|'([^']*)'/g)) {
17664
+ const entry = expand(double ?? single ?? "");
17665
+ if (isAbsolute7(entry) && within3(dir, entry)) return file;
17666
+ }
17667
+ }
17668
+ return null;
17669
+ }
17670
+ },
17671
+ copilot: {
17672
+ fix: (dir) => `Start Copilot CLI with copilot --add-dir ${dir} (doctor cannot see how it was started).`
17673
+ },
17674
+ cursor: {
17675
+ fix: () => "cursor-agent refuses writes outside the working folder unless it runs with --force: keep artifacts in the workspace there (open-artifact config set artifactsLocation workspace)."
17676
+ }
17677
+ };
17678
+ var WHO = {
17679
+ local: () => "your setting for this project",
17680
+ project: () => "the project's settings file",
17681
+ user: () => "your setting",
17682
+ environment: () => "the environment",
17683
+ harness: (harness) => `the default of ${harness}`,
17684
+ default: () => "the default"
17685
+ };
17686
+ var location = {
17687
+ id: "artifacts-location",
17688
+ title: "Where artifacts go",
17689
+ run: ({ harness, workspace, env }) => {
17690
+ const settings2 = loadSettings();
17691
+ const home2 = resolve17(settings2.homeWorkspace);
17692
+ const profile = harness && HARNESS_NAME.test(harness) ? harnessProfile(harness) : null;
17693
+ const app = profile?.title ?? harness;
17694
+ const whose = `A session of ${app ?? "an app without a profile"}${workspace ? ` in ${workspace}` : ""}`;
17695
+ if (confined(env)) {
17696
+ return { status: "ok", message: `${whose} keeps new artifacts in its workspace, under ${settings2.artifactsDir || "artifacts"}/: this daemon is confined to workspaces (OPEN_ARTIFACT_WORKSPACE_FOLDERS_ONLY=1)` };
17697
+ }
17698
+ let where2;
17699
+ let source;
17700
+ let folder = null;
17701
+ if (workspace && !within3(workspace, home2)) {
17702
+ const placement = artifactsPlacement(workspace, profile?.policy?.artifacts);
17703
+ where2 = placement.location;
17704
+ source = placement.locationSource;
17705
+ folder = workspaceArtifactsDir(workspace, placement);
17706
+ } else {
17707
+ const user = artifactsLocationOf(savedSettings().artifactsLocation);
17708
+ [where2, source] = user ? [user, "user"] : profile?.policy?.artifacts ? [profile.policy.artifacts, "harness"] : ["home", "default"];
17709
+ }
17710
+ const why = `artifactsLocation ${where2}: ${WHO[source](harness)}`;
17711
+ if (where2 === "workspace") {
17712
+ return { status: "ok", message: `${whose} keeps new artifacts in the workspace, ${folder ?? `<workspace>/${settings2.artifactsDir || "artifacts"}`}/<slug> (${why})` };
17713
+ }
17714
+ const message4 = `${whose} keeps new artifacts under your Open Artifact folder, ${join21(home2, "<project>", "<slug>")} (${why})`;
17715
+ const limit = harness && profile?.policy?.artifacts === "workspace" ? WRITABLE[harness] : void 0;
17716
+ if (!limit) return { status: "ok", message: message4 };
17717
+ const allowed = limit.allowedIn?.(home2, workspace, env);
17718
+ if (allowed) return { status: "ok", message: `${message4}; ${app} may write there (${allowed})` };
17719
+ return { status: "warn", message: `${message4}, which is outside the folder ${app} lets its agent write`, fix: limit.fix(home2) };
17720
+ }
17721
+ };
17722
+ var describe = (settings2) => {
17723
+ const set = PROJECT_SETTINGS_KEYS.filter((key) => settings2[key] !== void 0).map((key) => `${key} ${settings2[key]}`);
17724
+ return set.length ? set.join(", ") : "sets nothing";
17725
+ };
17726
+ var projectSettings = {
17727
+ id: "project-settings",
17728
+ title: "Project settings",
17729
+ applies: ({ workspace, env }) => !!workspace && !confined(env),
17730
+ run: ({ workspace }) => {
17731
+ const { layers } = artifactsPlacement(workspace);
17732
+ const found2 = [];
17733
+ const only = `a project sets only ${PROJECT_SETTINGS_KEYS.join(" and ")}, and artifactsDir is a relative path inside it`;
17734
+ if (!layers.file) found2.push({ status: "ok", message: `Project ${layers.info.project}: no settings file of its own` });
17735
+ else if (layers.fileBroken) found2.push({ status: "warn", message: `Project settings ${layers.file} is not a JSON object: nothing of it is used`, fix: `Fix or remove ${layers.file}.` });
17736
+ else if (layers.projectIgnored.length) {
17737
+ found2.push({
17738
+ status: "warn",
17739
+ message: `Project settings ${layers.file}: ${describe(layers.project)}; not used: ${layers.projectIgnored.join(", ")} (${only})`,
17740
+ fix: `Remove ${layers.projectIgnored.length === 1 ? "that key" : "those keys"} from the file; your own settings go in ${files.settings()} (open-artifact config set).`
17741
+ });
17742
+ } else found2.push({ status: "ok", message: `Project settings ${layers.file}: ${describe(layers.project)}` });
17743
+ if (layers.localKey !== null) {
17744
+ found2.push(
17745
+ layers.localIgnored.length ? {
17746
+ status: "warn",
17747
+ message: `Your settings for the project ${layers.info.project}: ${describe(layers.local)}; not used: ${layers.localIgnored.join(", ")} (${only})`,
17748
+ fix: `Remove ${layers.localIgnored.length === 1 ? "that key" : "those keys"} from the project's entry under "projects" in ${files.settings()}.`
17749
+ } : { status: "ok", message: `Your settings for the project ${layers.info.project}: ${describe(layers.local)}` }
17750
+ );
17751
+ }
17752
+ return found2;
17753
+ }
17754
+ };
17755
+ var projectEntries = {
17756
+ id: "settings-projects",
17757
+ title: "Settings for single projects",
17758
+ run: () => {
17759
+ const entries = savedSettings().projects;
17760
+ if (entries === void 0) return [];
17761
+ const file = files.settings();
17762
+ if (!isObject6(entries)) return [{ status: "warn", message: `"projects" in ${file} is not an object: nothing of it is used`, fix: `Remove "projects" from ${file}; open-artifact config set <key> <value> --local writes it again.` }];
17763
+ const keys = Object.keys(entries);
17764
+ const unusable2 = keys.filter((key) => !projectPath(key));
17765
+ const gone = keys.filter((key) => {
17766
+ const path = projectPath(key);
17767
+ return !!path && !existsSync13(path);
17768
+ });
17769
+ const found2 = [];
17770
+ if (unusable2.length) {
17771
+ found2.push({ status: "warn", message: `"projects" in ${file} names ${unusable2.length === 1 ? "a project" : "projects"} by something that is not an absolute path: ${unusable2.join(", ")}`, fix: `Name each project by its folder (absolute, or ~/...) in ${file}.` });
17772
+ }
17773
+ if (gone.length) {
17774
+ found2.push({
17775
+ status: "warn",
17776
+ message: `"projects" in ${file} keeps settings for ${gone.length === 1 ? "a folder that is" : `${gone.length} folders that are`} gone: ${gone.join(", ")}`,
17777
+ fix: `Remove ${gone.length === 1 ? "that entry" : "those entries"} from "projects" in ${file}; in a project that moved, set it again with open-artifact config set <key> <value> --local.`
17778
+ });
17779
+ }
17780
+ const kept = keys.length - unusable2.length - gone.length;
17781
+ if (!found2.length) found2.push({ status: "ok", message: `Your own settings for ${kept} project${kept === 1 ? "" : "s"} ("projects" in ${file})` });
17782
+ return found2;
17783
+ }
17784
+ };
17785
+ var homeWorkspace = {
17786
+ id: "home-workspace",
17787
+ title: "Open Artifact folder",
17788
+ run: () => {
17789
+ const folder = resolve17(loadSettings().homeWorkspace);
17790
+ const fix = `Give your user write access to it, or choose another folder: open-artifact config set homeWorkspace <folder>.`;
17791
+ const writable = (dir) => {
17792
+ try {
17793
+ accessSync(dir, constants2.W_OK);
17794
+ return true;
17795
+ } catch {
17796
+ return false;
17797
+ }
17798
+ };
17799
+ if (existsSync13(folder)) {
17800
+ if (!statSync8(folder).isDirectory()) return { status: "fail", message: `The Open Artifact folder ${folder} is not a folder`, fix: `Move that file away, or choose another folder: open-artifact config set homeWorkspace <folder>.` };
17801
+ return writable(folder) ? { status: "ok", message: `Open Artifact folder ${folder}` } : { status: "fail", message: `The Open Artifact folder ${folder} is not writable`, fix };
17802
+ }
17803
+ let parent = dirname11(folder);
17804
+ while (!existsSync13(parent) && dirname11(parent) !== parent) parent = dirname11(parent);
17805
+ return writable(parent) ? { status: "ok", message: `Open Artifact folder ${folder} (not made yet: the first artifact kept there makes it)` } : { status: "fail", message: `The Open Artifact folder ${folder} cannot be made: ${parent} is not writable`, fix };
17806
+ }
17807
+ };
17808
+ var LOCATION_CHECKS = [homeWorkspace, location, projectSettings, projectEntries];
17809
+
17132
17810
  // packages/daemon/src/doctor-remote.ts
17133
17811
  init_src2();
17134
17812
  init_src();
@@ -17179,8 +17857,8 @@ var remoteTypes = {
17179
17857
  let remote2;
17180
17858
  try {
17181
17859
  remote2 = registry.list(process.cwd()).filter((t) => t.enabled).flatMap((t) => {
17182
- const location = entryLocation(t.entry);
17183
- return location.remote && t.entry?.kind === "url" ? [{ id: t.id, title: t.title || t.id, entry: t.entry, origin: location.origin }] : [];
17860
+ const location2 = entryLocation(t.entry);
17861
+ return location2.remote && t.entry?.kind === "url" ? [{ id: t.id, title: t.title || t.id, entry: t.entry, origin: location2.origin }] : [];
17184
17862
  });
17185
17863
  } finally {
17186
17864
  registry.close();
@@ -17239,9 +17917,9 @@ var home = {
17239
17917
  id: "home",
17240
17918
  title: "Open Artifact home",
17241
17919
  run: ({ home: home2 }) => {
17242
- if (!existsSync11(home2)) return { status: "warn", message: `The home ${home2} does not exist yet`, fix: "Nothing to do: it is made when the daemon first starts (open-artifact daemon ensure)." };
17920
+ if (!existsSync14(home2)) return { status: "warn", message: `The home ${home2} does not exist yet`, fix: "Nothing to do: it is made when the daemon first starts (open-artifact daemon ensure)." };
17243
17921
  try {
17244
- accessSync(home2, constants2.W_OK);
17922
+ accessSync2(home2, constants3.W_OK);
17245
17923
  } catch {
17246
17924
  return { status: "fail", message: `The home ${home2} is not writable`, fix: `Give your user write access to ${home2} (or set OPEN_ARTIFACT_HOME to a folder of yours).` };
17247
17925
  }
@@ -17257,7 +17935,7 @@ var daemon = {
17257
17935
  const found2 = [{ status: "ok", message: `Daemon ${state.version ?? "?"} running at ${state.url} (pid ${state.pid})` }];
17258
17936
  if (process.platform !== "win32") {
17259
17937
  try {
17260
- const mode2 = statSync8(files.daemon()).mode & 511;
17938
+ const mode2 = statSync10(files.daemon()).mode & 511;
17261
17939
  if (mode2 & 63) return [...found2, { status: "fail", message: `daemon.json (which holds the token) is readable by others (mode ${mode2.toString(8)})`, fix: `chmod 600 ${files.daemon()}` }];
17262
17940
  } catch {
17263
17941
  }
@@ -17363,17 +18041,17 @@ var settings = {
17363
18041
  id: "settings",
17364
18042
  title: "Settings",
17365
18043
  run: ({ home: home2 }) => {
17366
- const file = join19(home2, "settings.json");
17367
- if (!existsSync11(file)) return { status: "ok", message: "Settings: the defaults (no settings.json)" };
18044
+ const file = join23(home2, "settings.json");
18045
+ if (!existsSync14(file)) return { status: "ok", message: "Settings: the defaults (no settings.json)" };
17368
18046
  try {
17369
- JSON.parse(readFileSync11(file, "utf8"));
18047
+ JSON.parse(readFileSync13(file, "utf8"));
17370
18048
  return { status: "ok", message: `Settings: ${file}` };
17371
18049
  } catch (error) {
17372
18050
  return { status: "fail", message: `settings.json is not valid JSON (${error.message})`, fix: `Fix or remove ${file}; until then the defaults apply.` };
17373
18051
  }
17374
18052
  }
17375
18053
  };
17376
- var DOCTOR_CHECKS = [node, home, settings, daemon, nodeChildren2, runtime, types, harnessProfileCheck, harnessAdapter, tools, ...REMOTE_CHECKS, ...CONFORMANCE_CHECKS];
18054
+ var DOCTOR_CHECKS = [node, home, settings, daemon, nodeChildren2, runtime, types, harnessProfileCheck, harnessAdapter, tools, ...LOCATION_CHECKS, ...REMOTE_CHECKS, ...CONFORMANCE_CHECKS];
17377
18055
 
17378
18056
  // packages/daemon/src/stdio-bridge.ts
17379
18057
  init_src();
@@ -17386,15 +18064,15 @@ async function runStdioBridge(options) {
17386
18064
  if (!HARNESS_NAME.test(harness)) throw new OpenArtifactError("invalid_argument", `--harness ${harness}: a harness name is lowercase letters, digits, . _ -.`);
17387
18065
  const write = (message4) => void output.write(`${JSON.stringify({ jsonrpc: "2.0", ...message4 })}
17388
18066
  `);
17389
- const fail = (id, error) => {
18067
+ const fail2 = (id, error) => {
17390
18068
  const body = errorBody(error);
17391
18069
  write({ id, error: { code: rpcErrorCode(body.code), message: body.message, data: body } });
17392
18070
  };
17393
18071
  const waiting = /* @__PURE__ */ new Map();
17394
18072
  let next = 1;
17395
- const callHost = (method, params) => new Promise((resolve18, reject) => {
18073
+ const callHost = (method, params) => new Promise((resolve21, reject) => {
17396
18074
  const id = `d${next++}`;
17397
- waiting.set(id, { resolve: resolve18, reject });
18075
+ waiting.set(id, { resolve: resolve21, reject });
17398
18076
  write({ id, method, params });
17399
18077
  });
17400
18078
  let client = null;
@@ -17467,9 +18145,9 @@ async function runStdioBridge(options) {
17467
18145
  try {
17468
18146
  message4 = JSON.parse(text3);
17469
18147
  } catch {
17470
- return fail(null, new OpenArtifactError("parse_error", "Not a JSON line."));
18148
+ return fail2(null, new OpenArtifactError("parse_error", "Not a JSON line."));
17471
18149
  }
17472
- if (!message4 || typeof message4 !== "object" || Array.isArray(message4)) return fail(null, new OpenArtifactError("invalid_argument", "One JSON-RPC object per line; batches are not accepted."));
18150
+ if (!message4 || typeof message4 !== "object" || Array.isArray(message4)) return fail2(null, new OpenArtifactError("invalid_argument", "One JSON-RPC object per line; batches are not accepted."));
17473
18151
  if (message4.method === void 0 && message4.id !== void 0 && message4.id !== null) {
17474
18152
  const pending = waiting.get(String(message4.id));
17475
18153
  if (!pending) return log(`stdio: an answer to ${String(message4.id)}, which was not asked`);
@@ -17478,7 +18156,7 @@ async function runStdioBridge(options) {
17478
18156
  else pending.resolve(message4.result ?? null);
17479
18157
  return;
17480
18158
  }
17481
- if (typeof message4.method !== "string") return fail(message4.id ?? null, new OpenArtifactError("invalid_argument", "A request needs a method."));
18159
+ if (typeof message4.method !== "string") return fail2(message4.id ?? null, new OpenArtifactError("invalid_argument", "A request needs a method."));
17482
18160
  const params = message4.params && typeof message4.params === "object" && !Array.isArray(message4.params) ? message4.params : {};
17483
18161
  const id = message4.id;
17484
18162
  void handle(message4.method, params).then(
@@ -17486,13 +18164,13 @@ async function runStdioBridge(options) {
17486
18164
  if (id !== void 0 && id !== null) write({ id, result: result ?? null });
17487
18165
  },
17488
18166
  (error) => {
17489
- if (id !== void 0 && id !== null) fail(id, error);
18167
+ if (id !== void 0 && id !== null) fail2(id, error);
17490
18168
  else log(`stdio: notification ${String(message4.method)} failed: ${error?.message ?? error}`);
17491
18169
  }
17492
18170
  );
17493
18171
  };
17494
18172
  const lines = createInterface({ input: options.input, crlfDelay: Infinity });
17495
- await new Promise((resolve18) => {
18173
+ await new Promise((resolve21) => {
17496
18174
  lines.on("line", (line) => {
17497
18175
  if (Buffer.byteLength(line) > MAX_LINE2) {
17498
18176
  log("stdio: a line over 64 MiB; ending");
@@ -17501,13 +18179,100 @@ async function runStdioBridge(options) {
17501
18179
  }
17502
18180
  onLine(line);
17503
18181
  });
17504
- lines.on("close", resolve18);
18182
+ lines.on("close", resolve21);
17505
18183
  });
17506
18184
  for (const pending of waiting.values()) pending.reject(new OpenArtifactError("disconnected", "The host closed stdin."));
17507
18185
  waiting.clear();
17508
18186
  client?.close();
17509
18187
  }
17510
18188
 
18189
+ // packages/daemon/src/lifeline.ts
18190
+ import { execFileSync } from "node:child_process";
18191
+ var SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ksh", "mksh", "fish", "tcsh", "csh", "ash", "busybox", "cmd", "powershell", "pwsh", "wsl"]);
18192
+ function programName(command) {
18193
+ const base = command.trim().split(/[\\/]/).pop() ?? "";
18194
+ return base.replace(/^-/, "").replace(/\.exe$/i, "").toLowerCase();
18195
+ }
18196
+ function isShell(name) {
18197
+ return SHELLS.has(programName(name));
18198
+ }
18199
+ function holders(chain, limit = 4) {
18200
+ const pids = [];
18201
+ for (const entry of chain.slice(0, limit)) {
18202
+ if (!(entry.pid > 1)) break;
18203
+ pids.push(entry.pid);
18204
+ if (!isShell(entry.name)) break;
18205
+ }
18206
+ return pids;
18207
+ }
18208
+ function processTable(text3) {
18209
+ const table = /* @__PURE__ */ new Map();
18210
+ for (const line of text3.split(/\r?\n/)) {
18211
+ const match = /^\s*(\d+)\s+(\d+)\s+(.*?)\s*$/.exec(line);
18212
+ if (match) table.set(Number(match[1]), [Number(match[2]), match[3]]);
18213
+ }
18214
+ return table;
18215
+ }
18216
+ function chainFrom(table, start, depth) {
18217
+ const chain = [];
18218
+ let pid = start;
18219
+ for (let i = 0; i < depth && pid > 1; i++) {
18220
+ const row = table.get(pid);
18221
+ if (!row) {
18222
+ chain.push({ pid, name: "" });
18223
+ break;
18224
+ }
18225
+ chain.push({ pid, name: row[1] });
18226
+ pid = row[0];
18227
+ }
18228
+ return chain;
18229
+ }
18230
+ function startedBy(start = process.ppid, depth = 4) {
18231
+ if (!(start > 1)) return [];
18232
+ try {
18233
+ if (process.platform === "win32") {
18234
+ const script = `$p=${start}; for($i=0;$i -lt ${depth} -and $p -gt 0;$i++){ $x=Get-CimInstance Win32_Process -Filter "ProcessId=$p" -ErrorAction SilentlyContinue; if(-not $x){break}; "$($x.ProcessId) $($x.ParentProcessId) $($x.Name)"; $p=$x.ParentProcessId }`;
18235
+ const text3 = execFileSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script], {
18236
+ encoding: "utf8",
18237
+ windowsHide: true,
18238
+ timeout: 15e3,
18239
+ stdio: ["ignore", "pipe", "ignore"]
18240
+ });
18241
+ const chain = chainFrom(processTable(text3), start, depth);
18242
+ if (chain.length) return chain;
18243
+ } else {
18244
+ const text3 = execFileSync("ps", ["-A", "-o", "pid=,ppid=,comm="], { encoding: "utf8", timeout: 15e3, stdio: ["ignore", "pipe", "ignore"] });
18245
+ const chain = chainFrom(processTable(text3), start, depth);
18246
+ if (chain.length) return chain;
18247
+ }
18248
+ } catch {
18249
+ }
18250
+ return [{ pid: start, name: "" }];
18251
+ }
18252
+ function alive2(pid) {
18253
+ try {
18254
+ process.kill(pid, 0);
18255
+ return true;
18256
+ } catch (error) {
18257
+ return error.code === "EPERM";
18258
+ }
18259
+ }
18260
+ function exitWithHolders(options = {}) {
18261
+ const parent = process.ppid;
18262
+ const pids = options.pids ?? holders(startedBy(parent, 4));
18263
+ const gone = options.gone ?? (() => process.exit(0));
18264
+ if (!pids.length) return () => void 0;
18265
+ const timer = setInterval(() => {
18266
+ const orphaned = process.platform !== "win32" && process.ppid !== parent;
18267
+ if (orphaned || pids.some((pid) => !alive2(pid))) {
18268
+ clearInterval(timer);
18269
+ gone();
18270
+ }
18271
+ }, options.everyMs ?? 2e3);
18272
+ timer.unref();
18273
+ return () => clearInterval(timer);
18274
+ }
18275
+
17511
18276
  // packages/daemon/src/bin/open-artifact.ts
17512
18277
  init_package();
17513
18278
  var argv = process.argv.slice(2);
@@ -17538,6 +18303,15 @@ open-artifact hook <event> [--harness <name>] harness hooks: SessionStart
17538
18303
  open-artifact watch [--harness <name>] print a line whenever comments wait for this session (a harness monitor)
17539
18304
  open-artifact chatgpt [--port <n>] [--workspace <dir>] [--rotate] the tools over HTTP for ChatGPT on the web (behind an HTTPS tunnel)
17540
18305
  open-artifact home print the Open Artifact home folder
18306
+ open-artifact config [list] [--workspace <dir>] [--harness <name>] the settings in effect here (JSON): each value, who
18307
+ set it (you for this project, the project, you, the app, nobody),
18308
+ and what of the project's settings file is not used
18309
+ open-artifact config get <key> [--workspace <dir>] one value in effect
18310
+ open-artifact config set <key> <value> [--project | --local] set artifactsLocation (home | workspace), artifactsDir,
18311
+ homeWorkspace or serverPort in your settings.json; --project: in
18312
+ this project's .agents/open-artifact/settings.json (for everyone
18313
+ who uses the repository); --local: for you, in this project only
18314
+ open-artifact config unset <key> [--project | --local] remove it there, so the next source decides
17541
18315
  open-artifact skill render [--command <name>] [--harness <name>] [--form entry|full] [--workspace <dir>] [--json]
17542
18316
  the /open-artifact skill as that harness gets it (its command, rules…)
17543
18317
  open-artifact skill install --command <name> --dir <skills folder> [--harness <name>] [--form entry|full] [--force]
@@ -17553,7 +18327,9 @@ open-artifact runtime update [--version <x.y.z>] install the newest compatib
17553
18327
  open-artifact runtime pin <range> | --clear keep the runtime within a version range, e.g. ^0.14
17554
18328
  open-artifact runtime policy [auto|prompt|bundled|default] the update policy in effect and where it comes from; a word
17555
18329
  sets yours (default removes it)
17556
- open-artifact doctor [--harness <name>] [--json] check this computer's setup; exits non-zero when a check fails
18330
+ open-artifact doctor [--harness <name>] [--workspace <dir>] [--json] check this computer's setup, and where a session
18331
+ of that app in this folder keeps new artifacts; exits non-zero
18332
+ when a check fails
17557
18333
  open-artifact doctor --harness <name> --session <id> [--json] also run the host's conformance steps as that session
17558
18334
  (makes and removes a test artifact, asks the session once)
17559
18335
  open-artifact remote add <name> <https://host> [--insecure-http] [--no-browser] link this computer to a cloud host (signs
@@ -17606,7 +18382,7 @@ function ownWorkspace() {
17606
18382
  const plugins = [env.OPEN_ARTIFACT_PLUGIN_DIR, env.PLUGIN_ROOT, env.CLAUDE_PLUGIN_ROOT, env.CURSOR_PLUGIN_ROOT].filter((dir) => !!dir);
17607
18383
  return plugins.some((dir) => {
17608
18384
  const root = real(dir);
17609
- return cwd === root || cwd.startsWith(root + sep12);
18385
+ return cwd === root || cwd.startsWith(root + sep14);
17610
18386
  }) ? null : process.cwd();
17611
18387
  }
17612
18388
  function ancestors(start = process.ppid, depth = 4) {
@@ -17615,7 +18391,7 @@ function ancestors(start = process.ppid, depth = 4) {
17615
18391
  for (let i = 0; i < depth && pid > 1; i++) {
17616
18392
  pids.push(pid);
17617
18393
  try {
17618
- pid = Number(execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8" }).trim());
18394
+ pid = Number(execFileSync2("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8" }).trim());
17619
18395
  } catch {
17620
18396
  break;
17621
18397
  }
@@ -17702,6 +18478,8 @@ function wakeNotice(url, title) {
17702
18478
  return `The person sent comments or requests from the artifact "${title}". Call ArtifactComments {action: "read", url: "${url}"} to receive them, then handle them.`;
17703
18479
  }
17704
18480
  async function watch4() {
18481
+ process.stdout.on("error", () => process.exit(0));
18482
+ exitWithHolders();
17705
18483
  const harness = flag("harness", process.env.OPEN_ARTIFACT_HARNESS ?? "mcp");
17706
18484
  const session = sessionFromEnv(harness);
17707
18485
  const daemon3 = async () => {
@@ -17802,7 +18580,7 @@ async function hook(event) {
17802
18580
  if (!event) die("hook <event>");
17803
18581
  let input = {};
17804
18582
  try {
17805
- const text3 = readFileSync20(0, "utf8");
18583
+ const text3 = readFileSync22(0, "utf8");
17806
18584
  input = text3.trim() ? JSON.parse(text3) : {};
17807
18585
  } catch {
17808
18586
  input = {};
@@ -17955,7 +18733,7 @@ async function importCommand(file) {
17955
18733
  let bytes;
17956
18734
  const path = resolvePath(file);
17957
18735
  try {
17958
- bytes = readFileSync20(path);
18736
+ bytes = readFileSync22(path);
17959
18737
  } catch (error) {
17960
18738
  die(`import: cannot read ${path} (${error.message})`);
17961
18739
  }
@@ -18157,7 +18935,7 @@ async function types2(sub) {
18157
18935
  const [target] = argv;
18158
18936
  if (!target || !id) die("types from <page artifact url|id | saved page folder|.html> --id <id> [--scope user|project] [--name <name>]");
18159
18937
  const cwd = process.cwd();
18160
- const saved = !/^(art_|open-artifact:\/\/)/.test(target) && existsSync18(resolvePath(target));
18938
+ const saved = !/^(art_|open-artifact:\/\/)/.test(target) && existsSync21(resolvePath(target));
18161
18939
  const from = saved ? { path: resolvePath(target) } : { artifact: target };
18162
18940
  return out(await daemonCall(LIBRARY_ROUTES.typesFrom, { ...from, id, scope, name, project: cwd, workspace: cwd }));
18163
18941
  }
@@ -18261,7 +19039,7 @@ function harnessCommand(sub) {
18261
19039
  personOnly("harness-add", `open-artifact harness add ${resolvePath(file)}`);
18262
19040
  let raw;
18263
19041
  try {
18264
- raw = JSON.parse(readFileSync20(resolvePath(file), "utf8"));
19042
+ raw = JSON.parse(readFileSync22(resolvePath(file), "utf8"));
18265
19043
  } catch (error) {
18266
19044
  die(`harness add: cannot read ${file} as JSON (${error.message})`);
18267
19045
  }
@@ -18288,6 +19066,44 @@ function harnessCommand(sub) {
18288
19066
  die("harness add <profile.json> | list [--json] | remove <name>");
18289
19067
  }
18290
19068
  }
19069
+ async function config(sub) {
19070
+ const take = (name) => {
19071
+ const i = argv.indexOf(`--${name}`);
19072
+ if (i >= 0) argv.splice(i, 1);
19073
+ return i >= 0;
19074
+ };
19075
+ const workspace = resolvePath(flag("workspace") ?? process.cwd());
19076
+ switch (sub) {
19077
+ case void 0:
19078
+ case "list":
19079
+ case "get": {
19080
+ const harness = flag("harness") ?? process.env.OPEN_ARTIFACT_HARNESS ?? AGENT?.harness ?? null;
19081
+ const listed3 = configList(workspace, harness, harness ? harnessProfile(harness).policy?.artifacts : void 0);
19082
+ if (sub !== "get") return out(listed3);
19083
+ const [key] = argv;
19084
+ if (!key) die("config get <key>");
19085
+ const found2 = listed3.values[key];
19086
+ if (!found2) die(`${key} is not a key config knows. Keys: ${CONFIG_KEYS.join(", ")}.`);
19087
+ return out(typeof found2.value === "string" ? found2.value : JSON.stringify(found2.value));
19088
+ }
19089
+ case "set":
19090
+ case "unset": {
19091
+ const project = take("project");
19092
+ const local = take("local");
19093
+ if (project && local) die("--project (the repository's file, for everyone) or --local (yours, for this project): not both.");
19094
+ const [key, value] = argv;
19095
+ if (!key || sub === "set" && value === void 0) die(sub === "set" ? "config set <key> <value> [--project | --local]" : "config unset <key> [--project | --local]");
19096
+ const scope = project ? "project" : local ? "local" : "user";
19097
+ personOnly("config-set", `open-artifact config ${sub} ${key}${sub === "set" ? ` ${value}` : ""}${project ? " --project" : local ? " --local" : ""}`);
19098
+ const request = { key, value: sub === "set" ? value : null, scope, workspace };
19099
+ const done = await daemonCall(LIBRARY_ROUTES.configSet, request);
19100
+ const where2 = done.scope === "project" ? `this project's settings (${done.file})` : done.scope === "local" ? `your settings for the project ${done.project} (${done.file})` : `your settings (${done.file})`;
19101
+ return out(done.value === null ? `${done.key} removed from ${where2}.` : `${done.key} = ${typeof done.value === "string" ? done.value : JSON.stringify(done.value)} in ${where2}.`);
19102
+ }
19103
+ default:
19104
+ die("config [list] | get <key> | set <key> <value> [--project | --local] | unset <key> [--project | --local]");
19105
+ }
19106
+ }
18291
19107
  async function main() {
18292
19108
  const [command, sub] = argv.splice(0, 2);
18293
19109
  switch (command) {
@@ -18327,6 +19143,12 @@ async function main() {
18327
19143
  return chatgpt();
18328
19144
  case "home":
18329
19145
  return out(openArtifactHome2());
19146
+ case "config":
19147
+ if (sub?.startsWith("--")) {
19148
+ argv.unshift(sub);
19149
+ return config("list");
19150
+ }
19151
+ return config(sub);
18330
19152
  case "skill":
18331
19153
  return out(
18332
19154
  skillCommand(sub, (name) => flag(name), (name) => {
@@ -18354,7 +19176,7 @@ async function main() {
18354
19176
  case "doctor": {
18355
19177
  if (sub) argv.unshift(sub);
18356
19178
  const json = argv.includes("--json");
18357
- const report = await runDoctor({ checks: DOCTOR_CHECKS, harness: flag("harness") ?? null, session: flag("session") ?? null });
19179
+ const report = await runDoctor({ checks: DOCTOR_CHECKS, harness: flag("harness") ?? null, session: flag("session") ?? null, workspace: resolvePath(flag("workspace") ?? process.cwd()) });
18358
19180
  out(json ? report : doctorText(report));
18359
19181
  if (!report.ok) process.exitCode = 1;
18360
19182
  return;