dsh-open-artifact 0.16.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/lib/client.js +1 -1
- package/lib/index.js +7 -4
- package/package.json +1 -1
- package/skills/open-artifact/SKILL.md +6 -3
- package/vendor/frame-host/frame-host.mjs +169 -45
- package/vendor/open-artifact.mjs +659 -378
- package/vendor/runtime.json +1 -1
- package/vendor/type-server/cli.mjs +1400 -1150
package/vendor/open-artifact.mjs
CHANGED
|
@@ -1311,7 +1311,10 @@ beyond it (running commands, sending things, opening links).`;
|
|
|
1311
1311
|
\`changed\`, \`read\` lists the files they touched in \`changed_files\`, and \`notes\` say so: read those files again
|
|
1312
1312
|
before writing. When you write through the tools, pass the \`sha256\` you read as \`if_match\`
|
|
1313
1313
|
(\`Artifact {action: "publish", url, files, if_match}\`; \`ArtifactData\` \`set\` and \`delete\` of an existing document
|
|
1314
|
-
need it). On a \`conflict\`, merge your change into \`current\` and write again
|
|
1314
|
+
need it). On a \`conflict\`, merge your change into \`current\` and write again; \`executionStatus: "not_executed"\` on
|
|
1315
|
+
it means nothing was written.`,
|
|
1316
|
+
`Some apps keep you to your workspace: there a folder or a file path outside it (an action's \`file\` or \`out\`,
|
|
1317
|
+
ArtifactData's \`file_path\` or \`out_file\`) answers \`not_granted\`. Use a path inside the workspace instead.`,
|
|
1315
1318
|
`To share it, \`Artifact {action: "open", url, panel: "share"}\` opens its Share panel for the person; to export
|
|
1316
1319
|
(PDF, PPTX, PNG, …), \`panel: "export"\`. Only the person changes how an artifact is shared; never make share links
|
|
1317
1320
|
yourself.`,
|
|
@@ -2149,12 +2152,12 @@ var init_declaration = __esm({
|
|
|
2149
2152
|
const value = this.value();
|
|
2150
2153
|
if (key !== "__proto__") Object.defineProperty(out2, key, { value, enumerable: true, configurable: true, writable: true });
|
|
2151
2154
|
this.skip();
|
|
2152
|
-
const
|
|
2153
|
-
if (
|
|
2155
|
+
const sep13 = s[this.i];
|
|
2156
|
+
if (sep13 === ",") {
|
|
2154
2157
|
this.i++;
|
|
2155
2158
|
continue;
|
|
2156
2159
|
}
|
|
2157
|
-
if (
|
|
2160
|
+
if (sep13 === "}") continue;
|
|
2158
2161
|
this.fail(`\`,\` or \`}\` is expected, not ${this.describe()}`);
|
|
2159
2162
|
}
|
|
2160
2163
|
}
|
|
@@ -2183,12 +2186,12 @@ var init_declaration = __esm({
|
|
|
2183
2186
|
if (c === "." && s.startsWith("...", this.i)) this.fail("A spread is not literal data");
|
|
2184
2187
|
out2.push(this.value());
|
|
2185
2188
|
this.skip();
|
|
2186
|
-
const
|
|
2187
|
-
if (
|
|
2189
|
+
const sep13 = s[this.i];
|
|
2190
|
+
if (sep13 === ",") {
|
|
2188
2191
|
this.i++;
|
|
2189
2192
|
continue;
|
|
2190
2193
|
}
|
|
2191
|
-
if (
|
|
2194
|
+
if (sep13 === "]") continue;
|
|
2192
2195
|
this.fail(`\`,\` or \`]\` is expected, not ${this.describe()}`);
|
|
2193
2196
|
}
|
|
2194
2197
|
}
|
|
@@ -3147,7 +3150,7 @@ var init_package = __esm({
|
|
|
3147
3150
|
"packages/daemon/package.json"() {
|
|
3148
3151
|
package_default = {
|
|
3149
3152
|
name: "@open-artifact/daemon",
|
|
3150
|
-
version: "0.16.
|
|
3153
|
+
version: "0.16.1",
|
|
3151
3154
|
private: true,
|
|
3152
3155
|
type: "module",
|
|
3153
3156
|
description: "The Open Artifact daemon (`open-artifact`): type registry, artifact library, type servers, agent tools, wake routing, the Harness API, MCP and the Shell.",
|
|
@@ -3159,9 +3162,9 @@ var init_package = __esm({
|
|
|
3159
3162
|
"./client": "./src/client.ts"
|
|
3160
3163
|
},
|
|
3161
3164
|
dependencies: {
|
|
3162
|
-
"@open-artifact/harness-kit": "0.16.
|
|
3163
|
-
"@open-artifact/protocol": "0.16.
|
|
3164
|
-
"@open-artifact/server-sdk": "0.16.
|
|
3165
|
+
"@open-artifact/harness-kit": "0.16.1",
|
|
3166
|
+
"@open-artifact/protocol": "0.16.1",
|
|
3167
|
+
"@open-artifact/server-sdk": "0.16.1"
|
|
3165
3168
|
},
|
|
3166
3169
|
license: "Apache-2.0"
|
|
3167
3170
|
};
|
|
@@ -4485,21 +4488,125 @@ var init_harness_skill = __esm({
|
|
|
4485
4488
|
}
|
|
4486
4489
|
});
|
|
4487
4490
|
|
|
4491
|
+
// packages/protocol/src/workspace-files.ts
|
|
4492
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
4493
|
+
import { lstatSync, readFileSync as readFileSync6, realpathSync as realpathSync3, renameSync as renameSync2, statSync as statSync3, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
4494
|
+
import { basename as basename2, dirname as dirname6, isAbsolute as isAbsolute2, join as join10, relative as relative3, resolve as resolve8, sep as sep4 } from "node:path";
|
|
4495
|
+
function includesPath(root, target) {
|
|
4496
|
+
const path = relative3(root, target);
|
|
4497
|
+
return path !== ".." && !path.startsWith(".." + sep4) && !isAbsolute2(path);
|
|
4498
|
+
}
|
|
4499
|
+
function artifactDirectory({ root, workspaceDirectory }) {
|
|
4500
|
+
const workspace = workspaceDirectory ? new WorkspaceDirectory(workspaceDirectory.root, workspaceDirectory) : void 0;
|
|
4501
|
+
return new WorkspaceDirectory(workspace?.resolve(root) ?? root);
|
|
4502
|
+
}
|
|
4503
|
+
function readSharingState(files2) {
|
|
4504
|
+
return files2.readJson(SHARING_FILE, null);
|
|
4505
|
+
}
|
|
4506
|
+
var forbidden, WorkspaceDirectory, SHARING_FILE;
|
|
4507
|
+
var init_workspace_files = __esm({
|
|
4508
|
+
"packages/protocol/src/workspace-files.ts"() {
|
|
4509
|
+
"use strict";
|
|
4510
|
+
init_errors();
|
|
4511
|
+
forbidden = () => new OpenArtifactError("not_granted", "File is outside the authorized workspace.", { status: 403 });
|
|
4512
|
+
WorkspaceDirectory = class {
|
|
4513
|
+
root;
|
|
4514
|
+
givenRoot;
|
|
4515
|
+
device;
|
|
4516
|
+
inode;
|
|
4517
|
+
constructor(root, identity) {
|
|
4518
|
+
this.givenRoot = resolve8(root);
|
|
4519
|
+
this.root = realpathSync3(this.givenRoot);
|
|
4520
|
+
const stat2 = statSync3(this.root, { bigint: true });
|
|
4521
|
+
if (!stat2.isDirectory()) throw forbidden();
|
|
4522
|
+
this.device = stat2.dev;
|
|
4523
|
+
this.inode = stat2.ino;
|
|
4524
|
+
if (identity && (identity.root !== this.root || identity.device !== this.device.toString() || identity.inode !== this.inode.toString())) throw forbidden();
|
|
4525
|
+
}
|
|
4526
|
+
get identity() {
|
|
4527
|
+
return { root: this.root, device: this.device.toString(), inode: this.inode.toString() };
|
|
4528
|
+
}
|
|
4529
|
+
/** Read optional metadata from a checked file. */
|
|
4530
|
+
readJson(input, fallback) {
|
|
4531
|
+
try {
|
|
4532
|
+
return JSON.parse(readFileSync6(this.resolve(input), "utf8"));
|
|
4533
|
+
} catch {
|
|
4534
|
+
return fallback;
|
|
4535
|
+
}
|
|
4536
|
+
}
|
|
4537
|
+
/** Atomically replace a metadata entry inside this directory. */
|
|
4538
|
+
writeJson(input, value, mode2) {
|
|
4539
|
+
const file = this.resolve(input, false);
|
|
4540
|
+
const tmp = `${file}.${randomBytes2(8).toString("hex")}.tmp`;
|
|
4541
|
+
writeFileSync2(tmp, `${JSON.stringify(value, null, 2)}
|
|
4542
|
+
`, { flag: "wx", ...mode2 === void 0 ? {} : { mode: mode2 } });
|
|
4543
|
+
try {
|
|
4544
|
+
renameSync2(tmp, file);
|
|
4545
|
+
} catch (error) {
|
|
4546
|
+
try {
|
|
4547
|
+
unlinkSync(tmp);
|
|
4548
|
+
} catch {
|
|
4549
|
+
}
|
|
4550
|
+
throw error;
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
/**
|
|
4554
|
+
* Check both the directory identity and the path. New files inherit the nearest existing parent's boundary. A path
|
|
4555
|
+
* spelled through a link to the workspace (macOS's `/var` for `/private/var`) is judged by where it really leads.
|
|
4556
|
+
*/
|
|
4557
|
+
resolve(input, followLeaf = true) {
|
|
4558
|
+
const directory = lstatSync(this.root, { bigint: true });
|
|
4559
|
+
if (!directory.isDirectory() || directory.dev !== this.device || directory.ino !== this.inode) throw forbidden();
|
|
4560
|
+
const path = resolve8(this.givenRoot, input);
|
|
4561
|
+
const target = includesPath(this.givenRoot, path) ? resolve8(this.root, relative3(this.givenRoot, path)) : path;
|
|
4562
|
+
const outside = !includesPath(this.root, target);
|
|
4563
|
+
const tail = [];
|
|
4564
|
+
let ancestor = target;
|
|
4565
|
+
if (!followLeaf && target !== this.root) {
|
|
4566
|
+
tail.push(basename2(target));
|
|
4567
|
+
ancestor = dirname6(target);
|
|
4568
|
+
}
|
|
4569
|
+
let real;
|
|
4570
|
+
try {
|
|
4571
|
+
for (; ; ) {
|
|
4572
|
+
try {
|
|
4573
|
+
lstatSync(ancestor);
|
|
4574
|
+
break;
|
|
4575
|
+
} catch (error) {
|
|
4576
|
+
if (error.code !== "ENOENT" || ancestor === this.root || dirname6(ancestor) === ancestor) throw error;
|
|
4577
|
+
tail.unshift(basename2(ancestor));
|
|
4578
|
+
ancestor = dirname6(ancestor);
|
|
4579
|
+
}
|
|
4580
|
+
}
|
|
4581
|
+
real = realpathSync3(ancestor);
|
|
4582
|
+
} catch (error) {
|
|
4583
|
+
if (outside) throw forbidden();
|
|
4584
|
+
throw error;
|
|
4585
|
+
}
|
|
4586
|
+
const actual = join10(real, ...tail);
|
|
4587
|
+
if (!includesPath(this.root, actual)) throw forbidden();
|
|
4588
|
+
return actual;
|
|
4589
|
+
}
|
|
4590
|
+
};
|
|
4591
|
+
SHARING_FILE = ".sharing.json";
|
|
4592
|
+
}
|
|
4593
|
+
});
|
|
4594
|
+
|
|
4488
4595
|
// packages/daemon/src/store.ts
|
|
4489
|
-
import { createHash as createHash2, randomBytes as
|
|
4596
|
+
import { createHash as createHash2, randomBytes as randomBytes3 } from "node:crypto";
|
|
4490
4597
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
4491
|
-
import { existsSync as existsSync6, readdirSync as readdirSync6, renameSync as
|
|
4492
|
-
import { join as
|
|
4598
|
+
import { existsSync as existsSync6, readdirSync as readdirSync6, renameSync as renameSync3 } from "node:fs";
|
|
4599
|
+
import { join as join11, resolve as resolve9 } from "node:path";
|
|
4493
4600
|
function newArtifactId() {
|
|
4494
4601
|
const time = Date.now().toString(36).padStart(9, "0");
|
|
4495
|
-
return `art_${time}${
|
|
4602
|
+
return `art_${time}${randomBytes3(8).toString("hex")}`;
|
|
4496
4603
|
}
|
|
4497
4604
|
function slugify(text3) {
|
|
4498
4605
|
const slug = String(text3 ?? "").normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9一-鿿]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 48);
|
|
4499
4606
|
return slug || "artifact";
|
|
4500
4607
|
}
|
|
4501
4608
|
function hashWorkspace(workspace) {
|
|
4502
|
-
return createHash2("sha1").update(
|
|
4609
|
+
return createHash2("sha1").update(resolve9(workspace)).digest("hex").slice(0, 12);
|
|
4503
4610
|
}
|
|
4504
4611
|
function sessionKeyOf(ref) {
|
|
4505
4612
|
return sessionKey(ref, hashWorkspace);
|
|
@@ -4522,15 +4629,18 @@ var init_store = __esm({
|
|
|
4522
4629
|
"use strict";
|
|
4523
4630
|
init_src();
|
|
4524
4631
|
init_paths();
|
|
4632
|
+
init_workspace_files();
|
|
4525
4633
|
MAX_USER_EDITS = 200;
|
|
4526
4634
|
ArtifactStore = class extends EventEmitter2 {
|
|
4527
|
-
|
|
4635
|
+
enforceWorkspaceDirectories;
|
|
4636
|
+
constructor(enforceWorkspaceDirectories = false) {
|
|
4528
4637
|
super();
|
|
4638
|
+
this.enforceWorkspaceDirectories = enforceWorkspaceDirectories;
|
|
4529
4639
|
ensureDir(files.artifacts());
|
|
4530
4640
|
}
|
|
4531
4641
|
/** The record file of an id. */
|
|
4532
4642
|
fileOf(id) {
|
|
4533
|
-
return
|
|
4643
|
+
return join11(files.artifacts(), `${id}.json`);
|
|
4534
4644
|
}
|
|
4535
4645
|
/** The record of an id, or `null`. */
|
|
4536
4646
|
get(id) {
|
|
@@ -4559,7 +4669,7 @@ var init_store = __esm({
|
|
|
4559
4669
|
const out2 = [];
|
|
4560
4670
|
for (const name of names) {
|
|
4561
4671
|
if (!name.endsWith(".json")) continue;
|
|
4562
|
-
const record = readJson(
|
|
4672
|
+
const record = readJson(join11(files.artifacts(), name), null);
|
|
4563
4673
|
if (record?.id) out2.push(record);
|
|
4564
4674
|
}
|
|
4565
4675
|
return out2.sort(
|
|
@@ -4568,8 +4678,8 @@ var init_store = __esm({
|
|
|
4568
4678
|
}
|
|
4569
4679
|
/** The record whose folder is `root`, or `null`. */
|
|
4570
4680
|
byRoot(root) {
|
|
4571
|
-
const wanted =
|
|
4572
|
-
return this.list().find((a) =>
|
|
4681
|
+
const wanted = resolve9(root);
|
|
4682
|
+
return this.list().find((a) => resolve9(a.root) === wanted) ?? null;
|
|
4573
4683
|
}
|
|
4574
4684
|
/** Writes a record and emits `changed`. */
|
|
4575
4685
|
save(record) {
|
|
@@ -4581,9 +4691,13 @@ var init_store = __esm({
|
|
|
4581
4691
|
create(fields) {
|
|
4582
4692
|
const now2 = (/* @__PURE__ */ new Date()).toISOString();
|
|
4583
4693
|
const owner = fields.owner ?? null;
|
|
4694
|
+
const identity = fields.workspaceDirectory;
|
|
4695
|
+
if (this.enforceWorkspaceDirectories && !identity) throw new OpenArtifactError("not_granted", "An authorized workspace is required.");
|
|
4696
|
+
const workspace = identity ? new WorkspaceDirectory(identity.root, identity) : void 0;
|
|
4584
4697
|
const record = {
|
|
4585
4698
|
id: newArtifactId(),
|
|
4586
|
-
root:
|
|
4699
|
+
root: workspace?.resolve(fields.root) ?? resolve9(fields.root),
|
|
4700
|
+
...identity ? { workspaceDirectory: identity } : {},
|
|
4587
4701
|
type: fields.type,
|
|
4588
4702
|
typeSource: fields.typeSource ?? null,
|
|
4589
4703
|
typeRelease: fields.typeRelease ?? null,
|
|
@@ -4608,7 +4722,8 @@ var init_store = __esm({
|
|
|
4608
4722
|
...fields.typeUid && fields.typeFrom ? { typeSource: fields.typeFrom } : {},
|
|
4609
4723
|
...fields.capabilities ? { capabilities: fields.capabilities } : {}
|
|
4610
4724
|
};
|
|
4611
|
-
|
|
4725
|
+
if (workspace) new WorkspaceDirectory(workspace.resolve(record.root)).writeJson(".artifact.json", marker);
|
|
4726
|
+
else writeJson(join11(record.root, ".artifact.json"), marker);
|
|
4612
4727
|
return this.save(record);
|
|
4613
4728
|
}
|
|
4614
4729
|
/**
|
|
@@ -4618,13 +4733,26 @@ var init_store = __esm({
|
|
|
4618
4733
|
setCapabilities(id, capabilities) {
|
|
4619
4734
|
const record = this.get(id);
|
|
4620
4735
|
if (!record) throw new OpenArtifactError("not_found", `No artifact ${id}.`);
|
|
4621
|
-
const
|
|
4622
|
-
const marker = readJson(
|
|
4736
|
+
const folder = new WorkspaceDirectory(this.authorizedRoot(record));
|
|
4737
|
+
const marker = folder.readJson(".artifact.json", null) ?? { type: record.type, id: record.id, release: record.typeRelease };
|
|
4623
4738
|
const { capabilities: _old, ...rest } = marker;
|
|
4624
|
-
writeJson(
|
|
4739
|
+
folder.writeJson(".artifact.json", capabilities ? { ...rest, capabilities } : rest);
|
|
4625
4740
|
const { capabilities: _was, ...kept } = record;
|
|
4626
4741
|
return this.save({ ...kept, ...capabilities ? { capabilities } : {}, updatedAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
4627
4742
|
}
|
|
4743
|
+
/**
|
|
4744
|
+
* The real folder of an artifact. One made in a workspace-confined daemon ({@link ArtifactRecord.workspaceDirectory})
|
|
4745
|
+
* resolves inside the workspace it was made in, and fails `not_granted` when that folder was moved, replaced or now
|
|
4746
|
+
* leads outside it; in a confined daemon, an artifact with no workspace fails too.
|
|
4747
|
+
*/
|
|
4748
|
+
authorizedRoot(record) {
|
|
4749
|
+
const identity = record.workspaceDirectory;
|
|
4750
|
+
if (!identity) {
|
|
4751
|
+
if (this.enforceWorkspaceDirectories) throw new OpenArtifactError("not_granted", "This artifact needs an authorized workspace.");
|
|
4752
|
+
return record.root;
|
|
4753
|
+
}
|
|
4754
|
+
return new WorkspaceDirectory(identity.root, identity).resolve(record.root);
|
|
4755
|
+
}
|
|
4628
4756
|
/** Merges `patch` into a record; `updatedAt` moves unless the patch sets it. */
|
|
4629
4757
|
update(id, patch) {
|
|
4630
4758
|
const record = this.get(id);
|
|
@@ -4634,9 +4762,9 @@ var init_store = __esm({
|
|
|
4634
4762
|
/** Puts back a record {@link remove} took out of the list (Undo). */
|
|
4635
4763
|
restore(id) {
|
|
4636
4764
|
if (!id || !ARTIFACT_ID.test(id)) return null;
|
|
4637
|
-
const from =
|
|
4765
|
+
const from = join11(files.trash(), `${id}.json`);
|
|
4638
4766
|
if (!existsSync6(from)) return null;
|
|
4639
|
-
|
|
4767
|
+
renameSync3(from, this.fileOf(id));
|
|
4640
4768
|
const record = this.get(id);
|
|
4641
4769
|
if (record) this.emit("changed", record);
|
|
4642
4770
|
return record;
|
|
@@ -4646,7 +4774,7 @@ var init_store = __esm({
|
|
|
4646
4774
|
const record = this.get(id);
|
|
4647
4775
|
if (!record) return false;
|
|
4648
4776
|
const trash = ensureDir(files.trash());
|
|
4649
|
-
|
|
4777
|
+
renameSync3(this.fileOf(id), join11(trash, `${id}.json`));
|
|
4650
4778
|
this.emit("changed", { ...record, removed: true });
|
|
4651
4779
|
return true;
|
|
4652
4780
|
}
|
|
@@ -4721,7 +4849,7 @@ var init_harness_view = __esm({
|
|
|
4721
4849
|
|
|
4722
4850
|
// packages/daemon/src/harness.ts
|
|
4723
4851
|
import { spawn as spawn2 } from "node:child_process";
|
|
4724
|
-
import { randomBytes as
|
|
4852
|
+
import { randomBytes as randomBytes4 } from "node:crypto";
|
|
4725
4853
|
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
4726
4854
|
function recentSessionMaxAgeMs() {
|
|
4727
4855
|
const fromEnv = Number(process.env.OPEN_ARTIFACT_RECENT_SESSION_MS);
|
|
@@ -4784,7 +4912,7 @@ var init_harness2 = __esm({
|
|
|
4784
4912
|
RECENT_SESSION_MS = 2 * 60 * 6e4;
|
|
4785
4913
|
DESKTOP_HARNESS = "open-artifact-desktop";
|
|
4786
4914
|
SocketConnection = class {
|
|
4787
|
-
id =
|
|
4915
|
+
id = randomBytes4(6).toString("hex");
|
|
4788
4916
|
harness = null;
|
|
4789
4917
|
caps = {};
|
|
4790
4918
|
authed = false;
|
|
@@ -4864,7 +4992,7 @@ var init_harness2 = __esm({
|
|
|
4864
4992
|
}
|
|
4865
4993
|
};
|
|
4866
4994
|
PollConnection = class {
|
|
4867
|
-
id = `poll-${
|
|
4995
|
+
id = `poll-${randomBytes4(6).toString("hex")}`;
|
|
4868
4996
|
harness;
|
|
4869
4997
|
caps;
|
|
4870
4998
|
authed = true;
|
|
@@ -5686,8 +5814,8 @@ var init_settings2 = __esm({
|
|
|
5686
5814
|
|
|
5687
5815
|
// packages/daemon/src/type-authoring.ts
|
|
5688
5816
|
import { randomUUID } from "node:crypto";
|
|
5689
|
-
import { cpSync, existsSync as existsSync7, lstatSync, mkdirSync as mkdirSync3, readFileSync as
|
|
5690
|
-
import { basename as
|
|
5817
|
+
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";
|
|
5818
|
+
import { basename as basename3, extname, join as join12, relative as relative4, resolve as resolve10, sep as sep5 } from "node:path";
|
|
5691
5819
|
function checkNewTypeId(id) {
|
|
5692
5820
|
const value = typeof id === "string" ? id.trim() : "";
|
|
5693
5821
|
if (!TYPE_ID.test(value) || value !== value.toLowerCase()) {
|
|
@@ -5700,12 +5828,12 @@ function checkNewTypeId(id) {
|
|
|
5700
5828
|
return value;
|
|
5701
5829
|
}
|
|
5702
5830
|
function authoringRoot(settings2, scope, project) {
|
|
5703
|
-
if (scope === "user") return
|
|
5831
|
+
if (scope === "user") return resolve10(settings2.typeRoots.user);
|
|
5704
5832
|
if (!project) throw new OpenArtifactError("invalid_argument", "A project type needs the project folder.");
|
|
5705
|
-
return
|
|
5833
|
+
return resolve10(project, settings2.typeRoots.project);
|
|
5706
5834
|
}
|
|
5707
5835
|
function makeFolder(root, id) {
|
|
5708
|
-
const dir =
|
|
5836
|
+
const dir = join12(root, id);
|
|
5709
5837
|
if (existsSync7(dir)) throw new OpenArtifactError("conflict", `${dir} is there already: pick another id, or change that type.`);
|
|
5710
5838
|
mkdirSync3(root, { recursive: true });
|
|
5711
5839
|
try {
|
|
@@ -5718,9 +5846,9 @@ function makeFolder(root, id) {
|
|
|
5718
5846
|
}
|
|
5719
5847
|
function writeAll(dir, written) {
|
|
5720
5848
|
for (const [rel, text3] of Object.entries(written)) {
|
|
5721
|
-
const file =
|
|
5722
|
-
mkdirSync3(
|
|
5723
|
-
|
|
5849
|
+
const file = join12(dir, rel);
|
|
5850
|
+
mkdirSync3(join12(file, ".."), { recursive: true });
|
|
5851
|
+
writeFileSync3(file, text3);
|
|
5724
5852
|
}
|
|
5725
5853
|
return Object.keys(written).sort();
|
|
5726
5854
|
}
|
|
@@ -5737,7 +5865,7 @@ function newType(args, o) {
|
|
|
5737
5865
|
const scope = scopeOf(args.scope);
|
|
5738
5866
|
const template = templateOf(args.template);
|
|
5739
5867
|
const name = nameOf(args.name, id);
|
|
5740
|
-
const project = typeof args.project === "string" && args.project ?
|
|
5868
|
+
const project = typeof args.project === "string" && args.project ? resolve10(args.project) : o.workspace ?? null;
|
|
5741
5869
|
const dir = makeFolder(authoringRoot(o.settings, scope, project), id);
|
|
5742
5870
|
const uid = randomUUID();
|
|
5743
5871
|
try {
|
|
@@ -5963,13 +6091,13 @@ function checkType(dir, o) {
|
|
|
5963
6091
|
const add = (p, level) => {
|
|
5964
6092
|
(level === "error" ? errors : warnings).push({ level, ...p });
|
|
5965
6093
|
};
|
|
5966
|
-
const id =
|
|
6094
|
+
const id = basename3(dir);
|
|
5967
6095
|
const forShare = o.forShare === true;
|
|
5968
6096
|
const out2 = () => ({ ok: errors.length === 0, id, dir, forShare, errors, warnings, ...caps ? { capabilities: caps } : {} });
|
|
5969
6097
|
let caps;
|
|
5970
6098
|
let st;
|
|
5971
6099
|
try {
|
|
5972
|
-
st =
|
|
6100
|
+
st = statSync4(dir);
|
|
5973
6101
|
} catch {
|
|
5974
6102
|
add({ code: "not_found", message: `${dir} is not there.` }, "error");
|
|
5975
6103
|
return out2();
|
|
@@ -5979,17 +6107,17 @@ function checkType(dir, o) {
|
|
|
5979
6107
|
return out2();
|
|
5980
6108
|
}
|
|
5981
6109
|
const builtinRoot = o.registry.roots().find((r) => r.scope === "builtin")?.root ?? null;
|
|
5982
|
-
const isBuiltin = builtinRoot !== null &&
|
|
6110
|
+
const isBuiltin = builtinRoot !== null && resolve10(dir) === resolve10(builtinRoot, id);
|
|
5983
6111
|
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");
|
|
5984
6112
|
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");
|
|
5985
6113
|
else if (RESERVED_TYPE_IDS.includes(id)) add({ code: "id_reserved", message: `${id} is reserved. Rename the folder.` }, "error");
|
|
5986
|
-
const manifestFile =
|
|
6114
|
+
const manifestFile = join12(dir, "artifact-type.json");
|
|
5987
6115
|
let manifest = null;
|
|
5988
6116
|
if (!existsSync7(manifestFile)) {
|
|
5989
6117
|
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");
|
|
5990
6118
|
} else {
|
|
5991
6119
|
try {
|
|
5992
|
-
const parsed = JSON.parse(
|
|
6120
|
+
const parsed = JSON.parse(readFileSync7(manifestFile, "utf8"));
|
|
5993
6121
|
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");
|
|
5994
6122
|
else manifest = parsed;
|
|
5995
6123
|
} catch (error) {
|
|
@@ -6004,7 +6132,7 @@ function checkType(dir, o) {
|
|
|
6004
6132
|
if (typeof manifest.version !== "string" || !manifest.version) add({ code: "version_missing", file: "artifact-type.json", message: 'There is no "version".' }, "warning");
|
|
6005
6133
|
}
|
|
6006
6134
|
}
|
|
6007
|
-
const info = readTypeFolder(dir, { root:
|
|
6135
|
+
const info = readTypeFolder(dir, { root: resolve10(dir, ".."), scope: "user", trusted: true });
|
|
6008
6136
|
if (info) {
|
|
6009
6137
|
for (const problem of info.problems) {
|
|
6010
6138
|
if (problem.startsWith("artifact-type.json is not valid JSON")) continue;
|
|
@@ -6014,9 +6142,9 @@ function checkType(dir, o) {
|
|
|
6014
6142
|
} else if (TYPE_ID.test(id)) {
|
|
6015
6143
|
add({ code: "not_a_type", message: "This folder has neither index.html nor artifact-type.json." }, "error");
|
|
6016
6144
|
}
|
|
6017
|
-
const indexFile =
|
|
6145
|
+
const indexFile = join12(dir, "index.html");
|
|
6018
6146
|
if (existsSync7(indexFile)) {
|
|
6019
|
-
const html =
|
|
6147
|
+
const html = readFileSync7(indexFile, "utf8");
|
|
6020
6148
|
if (DECLARATION_LINE.test(html) || declarationSource(html)) {
|
|
6021
6149
|
try {
|
|
6022
6150
|
const decl = readStaticDeclaration(html);
|
|
@@ -6053,18 +6181,18 @@ function checkType(dir, o) {
|
|
|
6053
6181
|
}
|
|
6054
6182
|
if (manifest?.skill !== false) {
|
|
6055
6183
|
const skillName = typeof manifest?.skill === "string" ? manifest.skill : "SKILL.md";
|
|
6056
|
-
const skillFile2 =
|
|
6057
|
-
if (!skillFile2.startsWith(
|
|
6184
|
+
const skillFile2 = resolve10(dir, skillName);
|
|
6185
|
+
if (!skillFile2.startsWith(resolve10(dir) + sep5) || !existsSync7(skillFile2)) {
|
|
6058
6186
|
add({ code: "skill_missing", file: skillName, message: `There is no ${skillName}: agents would not know how to make one.` }, "error");
|
|
6059
6187
|
} else {
|
|
6060
|
-
const fm = readFrontmatter(
|
|
6188
|
+
const fm = readFrontmatter(readFileSync7(skillFile2, "utf8"));
|
|
6061
6189
|
for (const field of ["name", "description"]) {
|
|
6062
6190
|
if (!fm[field]?.trim()) add({ code: "skill_frontmatter", file: skillName, message: `${skillName} has no "${field}" in its frontmatter.` }, "error");
|
|
6063
6191
|
}
|
|
6064
6192
|
}
|
|
6065
6193
|
}
|
|
6066
6194
|
const listed3 = o.registry.list(o.workspace ?? void 0, { includeShadowed: true });
|
|
6067
|
-
const self = listed3.find((t) =>
|
|
6195
|
+
const self = listed3.find((t) => resolve10(t.dir) === resolve10(dir));
|
|
6068
6196
|
if (self) {
|
|
6069
6197
|
if (self.shadowedBy) add({ code: "shadowed", message: `A ${self.shadowedBy} type of the same id wins over this one.` }, "warning");
|
|
6070
6198
|
const hidden = listed3.filter((t) => t.id === id && t !== self && t.shadowedBy);
|
|
@@ -6092,9 +6220,9 @@ function packageFolderEntries(dir) {
|
|
|
6092
6220
|
const out2 = [];
|
|
6093
6221
|
const walk = (folder) => {
|
|
6094
6222
|
for (const name of readdirSync7(folder).sort()) {
|
|
6095
|
-
const full =
|
|
6096
|
-
const rel =
|
|
6097
|
-
const st =
|
|
6223
|
+
const full = join12(folder, name);
|
|
6224
|
+
const rel = relative4(dir, full).split(sep5).join("/");
|
|
6225
|
+
const st = lstatSync2(full);
|
|
6098
6226
|
if (st.isDirectory()) {
|
|
6099
6227
|
out2.push({ path: `${rel}/`, kind: "dir", size: 0 });
|
|
6100
6228
|
if (!name.startsWith(".")) walk(full);
|
|
@@ -6105,10 +6233,10 @@ function packageFolderEntries(dir) {
|
|
|
6105
6233
|
return out2;
|
|
6106
6234
|
}
|
|
6107
6235
|
function typeDirOf(target, registry, workspace, cwd = process.cwd()) {
|
|
6108
|
-
if (target === "." || target === ".." || target.includes("/") || target.includes(
|
|
6236
|
+
if (target === "." || target === ".." || target.includes("/") || target.includes(sep5)) return resolve10(cwd, target);
|
|
6109
6237
|
const type = registry.list(workspace ?? void 0, { includeShadowed: false }).find((t) => t.id === target);
|
|
6110
6238
|
if (type) return type.dir;
|
|
6111
|
-
if (existsSync7(
|
|
6239
|
+
if (existsSync7(resolve10(cwd, target, "artifact-type.json")) || existsSync7(resolve10(cwd, target, "index.html"))) return resolve10(cwd, target);
|
|
6112
6240
|
throw new OpenArtifactError("not_found", `No type ${target}.`, { fix: "open-artifact types list shows the types; or give the folder (./my-type)." });
|
|
6113
6241
|
}
|
|
6114
6242
|
function typeFromPage(record, type, args, o) {
|
|
@@ -6117,7 +6245,7 @@ function typeFromPage(record, type, args, o) {
|
|
|
6117
6245
|
}
|
|
6118
6246
|
const html = (() => {
|
|
6119
6247
|
try {
|
|
6120
|
-
return
|
|
6248
|
+
return readFileSync7(join12(record.root, "index.html"), "utf8");
|
|
6121
6249
|
} catch {
|
|
6122
6250
|
throw new OpenArtifactError("not_found", `${record.title} has no index.html yet.`);
|
|
6123
6251
|
}
|
|
@@ -6125,7 +6253,7 @@ function typeFromPage(record, type, args, o) {
|
|
|
6125
6253
|
const id = checkNewTypeId(args.id);
|
|
6126
6254
|
const scope = scopeOf(args.scope);
|
|
6127
6255
|
const name = nameOf(args.name ?? record.title, id);
|
|
6128
|
-
const project = typeof args.project === "string" && args.project ?
|
|
6256
|
+
const project = typeof args.project === "string" && args.project ? resolve10(args.project) : o.workspace ?? null;
|
|
6129
6257
|
const capabilities = record.capabilities && typeof record.capabilities === "object" ? record.capabilities : {};
|
|
6130
6258
|
const dir = makeFolder(authoringRoot(o.settings, scope, project), id);
|
|
6131
6259
|
const uid = randomUUID();
|
|
@@ -6163,10 +6291,10 @@ files).
|
|
|
6163
6291
|
`
|
|
6164
6292
|
};
|
|
6165
6293
|
const filesOut = writeAll(dir, written);
|
|
6166
|
-
const own =
|
|
6167
|
-
if (existsSync7(own) &&
|
|
6168
|
-
cpSync(own,
|
|
6169
|
-
for (const f of listFiles(
|
|
6294
|
+
const own = join12(record.root, "artifact-type");
|
|
6295
|
+
if (existsSync7(own) && statSync4(own).isDirectory()) {
|
|
6296
|
+
cpSync(own, join12(dir, "artifact-type"), { recursive: true, dereference: false, filter: (src) => !basename3(src).startsWith(".") && !lstatSync2(src).isSymbolicLink() });
|
|
6297
|
+
for (const f of listFiles(join12(dir, "artifact-type"))) filesOut.push(`artifact-type/${f}`);
|
|
6170
6298
|
}
|
|
6171
6299
|
const skipped = skippedOf(record.root);
|
|
6172
6300
|
const check = checkType(dir, { ...o, workspace: scope === "project" ? project : o.workspace });
|
|
@@ -6269,13 +6397,13 @@ function iconOf(folder, meta) {
|
|
|
6269
6397
|
const icon = meta?.icon;
|
|
6270
6398
|
const file = icon && typeof icon === "object" && !Array.isArray(icon) ? icon.file : void 0;
|
|
6271
6399
|
if (file === void 0) return null;
|
|
6272
|
-
if (typeof file !== "string" || !file || file !==
|
|
6400
|
+
if (typeof file !== "string" || !file || file !== basename3(file) || file.startsWith(".") || file.includes("\\") || file.includes("\0")) {
|
|
6273
6401
|
return { problem: `metadata.json names the icon ${JSON.stringify(file)}: an icon is a file name in the folder; not copied.` };
|
|
6274
6402
|
}
|
|
6275
6403
|
if (!ICON_TYPES.has(extname(file).toLowerCase())) return { problem: `The icon ${file} is not an image Open Artifact shows (${[...ICON_TYPES].join(", ")}); not copied.` };
|
|
6276
6404
|
let st;
|
|
6277
6405
|
try {
|
|
6278
|
-
st =
|
|
6406
|
+
st = lstatSync2(join12(folder, file));
|
|
6279
6407
|
} catch {
|
|
6280
6408
|
return { problem: `metadata.json names the icon ${file}, which is not in the folder; not copied.` };
|
|
6281
6409
|
}
|
|
@@ -6284,19 +6412,19 @@ function iconOf(folder, meta) {
|
|
|
6284
6412
|
return { file };
|
|
6285
6413
|
}
|
|
6286
6414
|
function typeFromSaved(path, args, o) {
|
|
6287
|
-
const source =
|
|
6415
|
+
const source = resolve10(path);
|
|
6288
6416
|
let st;
|
|
6289
6417
|
try {
|
|
6290
|
-
st =
|
|
6418
|
+
st = statSync4(source);
|
|
6291
6419
|
} catch {
|
|
6292
6420
|
throw new OpenArtifactError("not_found", `${source} is not there.`);
|
|
6293
6421
|
}
|
|
6294
6422
|
const folder = st.isDirectory() ? source : null;
|
|
6295
|
-
const indexFile = folder ?
|
|
6423
|
+
const indexFile = folder ? join12(folder, "index.html") : source;
|
|
6296
6424
|
if (!folder && !/\.html?$/i.test(source)) throw new OpenArtifactError("invalid_argument", `${source} is neither a folder nor an .html file.`);
|
|
6297
6425
|
let indexSt;
|
|
6298
6426
|
try {
|
|
6299
|
-
indexSt =
|
|
6427
|
+
indexSt = statSync4(indexFile);
|
|
6300
6428
|
} catch {
|
|
6301
6429
|
throw new OpenArtifactError("not_found", `${folder} has no index.html.`);
|
|
6302
6430
|
}
|
|
@@ -6304,17 +6432,17 @@ function typeFromSaved(path, args, o) {
|
|
|
6304
6432
|
if (indexSt.size > TYPE_PACKAGE_LIMITS.fileBytes) throw new OpenArtifactError("too_large", `${indexFile} is over ${TYPE_PACKAGE_LIMITS.fileBytes / 1024 / 1024} MB.`);
|
|
6305
6433
|
const id = checkNewTypeId(args.id);
|
|
6306
6434
|
const scope = scopeOf(args.scope);
|
|
6307
|
-
const project = typeof args.project === "string" && args.project ?
|
|
6308
|
-
const original =
|
|
6435
|
+
const project = typeof args.project === "string" && args.project ? resolve10(args.project) : o.workspace ?? null;
|
|
6436
|
+
const original = readFileSync7(indexFile, "utf8");
|
|
6309
6437
|
const stripped = stripFrameRuntime(original);
|
|
6310
6438
|
const used = capabilitiesUsed(stripped);
|
|
6311
6439
|
const { html, declared } = withInferredCapabilities(stripped, id, used.inferred);
|
|
6312
6440
|
const capabilities = declared ? { inferred: [], stubbed: [], unknown: used.unknown, declared } : used;
|
|
6313
6441
|
const notes = [];
|
|
6314
6442
|
let meta = null;
|
|
6315
|
-
if (folder && existsSync7(
|
|
6443
|
+
if (folder && existsSync7(join12(folder, "metadata.json"))) {
|
|
6316
6444
|
try {
|
|
6317
|
-
const parsed = JSON.parse(
|
|
6445
|
+
const parsed = JSON.parse(readFileSync7(join12(folder, "metadata.json"), "utf8"));
|
|
6318
6446
|
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) meta = parsed;
|
|
6319
6447
|
else notes.push("metadata.json is not a JSON object: it was not read.");
|
|
6320
6448
|
} catch {
|
|
@@ -6363,7 +6491,7 @@ artifact of this type is a folder, \`<root>\`, whose files and data the page rea
|
|
|
6363
6491
|
`, "index.html": html, "SKILL.md": skill };
|
|
6364
6492
|
const filesOut = writeAll(dir, written);
|
|
6365
6493
|
if (icon?.file) {
|
|
6366
|
-
cpSync(
|
|
6494
|
+
cpSync(join12(folder, icon.file), join12(dir, icon.file));
|
|
6367
6495
|
filesOut.push(icon.file);
|
|
6368
6496
|
}
|
|
6369
6497
|
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() : [];
|
|
@@ -6401,7 +6529,7 @@ function listFiles(dir, base = "") {
|
|
|
6401
6529
|
const out2 = [];
|
|
6402
6530
|
for (const e of readdirSync7(dir, { withFileTypes: true })) {
|
|
6403
6531
|
const rel = base ? `${base}/${e.name}` : e.name;
|
|
6404
|
-
if (e.isDirectory()) out2.push(...listFiles(
|
|
6532
|
+
if (e.isDirectory()) out2.push(...listFiles(join12(dir, e.name), rel));
|
|
6405
6533
|
else out2.push(rel);
|
|
6406
6534
|
}
|
|
6407
6535
|
return out2;
|
|
@@ -6412,7 +6540,7 @@ function skippedOf(root) {
|
|
|
6412
6540
|
if (e.name === "index.html" || e.name === "artifact-type") continue;
|
|
6413
6541
|
if (e.isDirectory()) {
|
|
6414
6542
|
if (COLLAPSED.has(e.name) || e.name.startsWith(".")) out2.push(`${e.name}/`);
|
|
6415
|
-
else out2.push(...listFiles(
|
|
6543
|
+
else out2.push(...listFiles(join12(root, e.name), e.name));
|
|
6416
6544
|
} else out2.push(e.name);
|
|
6417
6545
|
}
|
|
6418
6546
|
return out2;
|
|
@@ -6434,9 +6562,9 @@ function setTypeEnabled(id, enabled) {
|
|
|
6434
6562
|
function setProjectTrusted(dir, trusted) {
|
|
6435
6563
|
const value = typeof dir === "string" ? dir.trim() : "";
|
|
6436
6564
|
if (!value || !value.startsWith("/") && !/^[A-Za-z]:[\\/]/.test(value)) throw new OpenArtifactError("invalid_argument", "dir: the project folder, as an absolute path.");
|
|
6437
|
-
const full =
|
|
6565
|
+
const full = resolve10(value);
|
|
6438
6566
|
const lists = savedLists();
|
|
6439
|
-
const next = lists.trustedProjects.filter((p) =>
|
|
6567
|
+
const next = lists.trustedProjects.filter((p) => resolve10(p) !== full);
|
|
6440
6568
|
if (trusted) next.push(full);
|
|
6441
6569
|
saveSettings({ trustedProjects: next });
|
|
6442
6570
|
return { ok: true, disabledTypes: lists.disabledTypes, trustedProjects: next };
|
|
@@ -6568,10 +6696,10 @@ description: >-
|
|
|
6568
6696
|
});
|
|
6569
6697
|
|
|
6570
6698
|
// packages/server-sdk/src/zip.ts
|
|
6571
|
-
import { randomBytes as
|
|
6699
|
+
import { randomBytes as randomBytes5 } from "node:crypto";
|
|
6572
6700
|
import { constants } from "node:fs";
|
|
6573
6701
|
import { lstat, mkdir, open, readdir, readFile, rename, rm, stat } from "node:fs/promises";
|
|
6574
|
-
import { basename as
|
|
6702
|
+
import { basename as basename4, dirname as dirname7, extname as extname2, join as join13, resolve as resolve11, sep as sep6 } from "node:path";
|
|
6575
6703
|
import { promisify } from "node:util";
|
|
6576
6704
|
import { deflateRaw as deflateRawCallback, inflateRaw as inflateRawCallback, inflateRawSync } from "node:zlib";
|
|
6577
6705
|
function view(bytes) {
|
|
@@ -6637,9 +6765,9 @@ function archiveKeeps(path) {
|
|
|
6637
6765
|
return true;
|
|
6638
6766
|
}
|
|
6639
6767
|
async function archiveEntries(root, skip = []) {
|
|
6640
|
-
const top =
|
|
6641
|
-
const folder =
|
|
6642
|
-
const skipped = new Set(skip.map((file) =>
|
|
6768
|
+
const top = resolve11(root);
|
|
6769
|
+
const folder = basename4(top) || "artifact";
|
|
6770
|
+
const skipped = new Set(skip.map((file) => resolve11(file)));
|
|
6643
6771
|
const entries = [];
|
|
6644
6772
|
const walk = async (dir, rel) => {
|
|
6645
6773
|
let names;
|
|
@@ -6653,7 +6781,7 @@ async function archiveEntries(root, skip = []) {
|
|
|
6653
6781
|
const name = dirent.name;
|
|
6654
6782
|
const inner = rel ? `${rel}/${name}` : name;
|
|
6655
6783
|
if (!keepsStep(rel, name, inner)) continue;
|
|
6656
|
-
const file =
|
|
6784
|
+
const file = join13(dir, name);
|
|
6657
6785
|
if (skipped.has(file)) continue;
|
|
6658
6786
|
if (dirent.isDirectory()) await walk(file, inner);
|
|
6659
6787
|
else if (dirent.isFile()) {
|
|
@@ -6756,7 +6884,7 @@ async function writeZip(entries, write) {
|
|
|
6756
6884
|
}
|
|
6757
6885
|
function archiveFileName(root, now2 = /* @__PURE__ */ new Date()) {
|
|
6758
6886
|
const day = `${now2.getFullYear()}-${String(now2.getMonth() + 1).padStart(2, "0")}-${String(now2.getDate()).padStart(2, "0")}`;
|
|
6759
|
-
return `${
|
|
6887
|
+
return `${basename4(resolve11(root)) || "artifact"}-${day}.zip`;
|
|
6760
6888
|
}
|
|
6761
6889
|
function attachmentHeader(name) {
|
|
6762
6890
|
const ascii = name.replace(/[^\x20-\x7e]|["\\]/g, "_");
|
|
@@ -6894,9 +7022,9 @@ async function writeNewFile(file, data, mode2 = 420) {
|
|
|
6894
7022
|
}
|
|
6895
7023
|
}
|
|
6896
7024
|
async function unpackZip(bytes, files2, dest, maxBytes) {
|
|
6897
|
-
const target =
|
|
6898
|
-
await mkdir(
|
|
6899
|
-
const temp =
|
|
7025
|
+
const target = resolve11(dest);
|
|
7026
|
+
await mkdir(dirname7(target), { recursive: true });
|
|
7027
|
+
const temp = join13(dirname7(target), `.${basename4(target)}.${randomBytes5(6).toString("hex")}.unpack`);
|
|
6900
7028
|
await mkdir(temp);
|
|
6901
7029
|
try {
|
|
6902
7030
|
let total = 0;
|
|
@@ -6904,9 +7032,9 @@ async function unpackZip(bytes, files2, dest, maxBytes) {
|
|
|
6904
7032
|
const data = await unpackZipFile(bytes, item);
|
|
6905
7033
|
total += data.length;
|
|
6906
7034
|
if (total > maxBytes) throw new ZipRefusal("too_large", `It unpacks to more than ${maxBytes} bytes.`);
|
|
6907
|
-
const file =
|
|
6908
|
-
if (!file.startsWith(temp +
|
|
6909
|
-
await mkdir(
|
|
7035
|
+
const file = resolve11(temp, ...item.path.split("/"));
|
|
7036
|
+
if (!file.startsWith(temp + sep6)) throw new ZipRefusal("invalid", `${item.path} would land outside its folder.`);
|
|
7037
|
+
await mkdir(dirname7(file), { recursive: true });
|
|
6910
7038
|
await writeNewFile(file, data, item.mode);
|
|
6911
7039
|
}
|
|
6912
7040
|
return { temp, files: files2.length, bytes: total };
|
|
@@ -7080,8 +7208,8 @@ var init_type_package2 = __esm({
|
|
|
7080
7208
|
|
|
7081
7209
|
// packages/daemon/src/type-packages.ts
|
|
7082
7210
|
import { createHash as createHash4 } from "node:crypto";
|
|
7083
|
-
import { existsSync as existsSync8, readFileSync as
|
|
7084
|
-
import { basename as
|
|
7211
|
+
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";
|
|
7212
|
+
import { basename as basename5, join as join14, resolve as resolve12, sep as sep7 } from "node:path";
|
|
7085
7213
|
function installedIndex() {
|
|
7086
7214
|
const read = readJson(files.typesIndex(), null);
|
|
7087
7215
|
const types3 = {};
|
|
@@ -7105,12 +7233,12 @@ ${check.errors.map((e) => ` - ${e.message}`).join("\n")}`, {
|
|
|
7105
7233
|
fix: `Fix what open-artifact types check ${dir} --for-share lists, then pack it again.`
|
|
7106
7234
|
});
|
|
7107
7235
|
}
|
|
7108
|
-
const manifest = JSON.parse(
|
|
7109
|
-
const id =
|
|
7236
|
+
const manifest = JSON.parse(readFileSync8(join14(dir, "artifact-type.json"), "utf8"));
|
|
7237
|
+
const id = basename5(resolve12(dir));
|
|
7110
7238
|
const version = String(manifest.version);
|
|
7111
7239
|
const entries = packageFolderEntries(dir).filter((e) => e.kind === "file").map((e) => {
|
|
7112
|
-
const file =
|
|
7113
|
-
const st =
|
|
7240
|
+
const file = join14(dir, ...e.path.split("/"));
|
|
7241
|
+
const st = statSync5(file);
|
|
7114
7242
|
return { name: `${id}/${e.path}`, file, size: st.size, mode: st.mode & 511, mtime: st.mtime };
|
|
7115
7243
|
});
|
|
7116
7244
|
const bytes = await zipBytes(entries);
|
|
@@ -7119,8 +7247,8 @@ ${check.errors.map((e) => ` - ${e.message}`).join("\n")}`, {
|
|
|
7119
7247
|
async function packType(dir, o) {
|
|
7120
7248
|
const packed = await packTypeBytes(dir, o);
|
|
7121
7249
|
const cwd = o.cwd ?? process.cwd();
|
|
7122
|
-
const where2 = o.out ?
|
|
7123
|
-
const file = existsSync8(where2) &&
|
|
7250
|
+
const where2 = o.out ? resolve12(cwd, o.out) : cwd;
|
|
7251
|
+
const file = existsSync8(where2) && statSync5(where2).isDirectory() ? join14(where2, packageFileName(packed.id, packed.version)) : where2;
|
|
7124
7252
|
writeFileAtomic(file, packed.bytes);
|
|
7125
7253
|
return { id: packed.id, version: packed.version, file, sha256: packed.sha256, bytes: packed.bytes.length, files: packed.files };
|
|
7126
7254
|
}
|
|
@@ -7134,7 +7262,7 @@ async function readTypePackage(bytes, source, o = {}) {
|
|
|
7134
7262
|
fix: `Install it under another id: open-artifact types install ${source} --as <id>.`
|
|
7135
7263
|
});
|
|
7136
7264
|
}
|
|
7137
|
-
const folder =
|
|
7265
|
+
const folder = join14(files.installedTypes(), id);
|
|
7138
7266
|
if (!known && existsSync8(folder)) {
|
|
7139
7267
|
throw new OpenArtifactError("conflict", `${folder} exists but is not in ${files.typesIndex()}: it was not installed by open-artifact types install.`, {
|
|
7140
7268
|
fix: `Move that folder away, or install this one under another id with --as <id>.`
|
|
@@ -7250,16 +7378,16 @@ function allowedUrl(address) {
|
|
|
7250
7378
|
}
|
|
7251
7379
|
async function loadTypePackage(target, cwd = process.cwd()) {
|
|
7252
7380
|
if (isAddress(target)) return { bytes: await fetchTypePackage(target), source: target };
|
|
7253
|
-
const file =
|
|
7381
|
+
const file = resolve12(cwd, target);
|
|
7254
7382
|
let st;
|
|
7255
7383
|
try {
|
|
7256
|
-
st =
|
|
7384
|
+
st = statSync5(file);
|
|
7257
7385
|
} catch {
|
|
7258
7386
|
throw new OpenArtifactError("not_found", `${file} is not there.`);
|
|
7259
7387
|
}
|
|
7260
7388
|
if (!st.isFile()) throw refuse(`${file} is not a file.`);
|
|
7261
7389
|
if (st.size > PACKAGE_DOWNLOAD_MAX) throw new OpenArtifactError("too_large", `${file} is ${st.size} bytes, more than a type package may be.`);
|
|
7262
|
-
return { bytes:
|
|
7390
|
+
return { bytes: readFileSync8(file), source: file };
|
|
7263
7391
|
}
|
|
7264
7392
|
async function installTypePackage(pkg, o = {}) {
|
|
7265
7393
|
const { preview } = pkg;
|
|
@@ -7269,7 +7397,7 @@ async function installTypePackage(pkg, o = {}) {
|
|
|
7269
7397
|
});
|
|
7270
7398
|
}
|
|
7271
7399
|
const root = ensureDir(files.installedTypes());
|
|
7272
|
-
const dest =
|
|
7400
|
+
const dest = join14(root, preview.id);
|
|
7273
7401
|
let unpacked;
|
|
7274
7402
|
try {
|
|
7275
7403
|
unpacked = await unpackZip(
|
|
@@ -7291,13 +7419,13 @@ ${listed2(again)}`);
|
|
|
7291
7419
|
const known = installedEntry(preview.id);
|
|
7292
7420
|
if (existsSync8(dest)) {
|
|
7293
7421
|
if (!known || known.uid !== preview.uid) throw new OpenArtifactError("conflict", `${dest} exists and is not an install of this type.`);
|
|
7294
|
-
aside =
|
|
7295
|
-
|
|
7422
|
+
aside = join14(root, `.${preview.id}.${Date.now().toString(36)}.old`);
|
|
7423
|
+
renameSync4(dest, aside);
|
|
7296
7424
|
}
|
|
7297
7425
|
await moveIntoPlace(temp, dest);
|
|
7298
7426
|
} catch (error) {
|
|
7299
7427
|
rmSync3(temp, { recursive: true, force: true });
|
|
7300
|
-
if (aside && !existsSync8(dest))
|
|
7428
|
+
if (aside && !existsSync8(dest)) renameSync4(aside, dest);
|
|
7301
7429
|
throw error;
|
|
7302
7430
|
}
|
|
7303
7431
|
if (aside) rmSync3(aside, { recursive: true, force: true });
|
|
@@ -7318,13 +7446,13 @@ ${listed2(again)}`);
|
|
|
7318
7446
|
function uninstallType(id) {
|
|
7319
7447
|
if (!TYPE_ID.test(id)) throw refuse(`${JSON.stringify(id)} is not a type id.`);
|
|
7320
7448
|
const index = installedIndex();
|
|
7321
|
-
const dir =
|
|
7449
|
+
const dir = join14(files.installedTypes(), id);
|
|
7322
7450
|
if (!Object.hasOwn(index.types, id)) {
|
|
7323
7451
|
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." });
|
|
7324
7452
|
}
|
|
7325
7453
|
if (existsSync8(dir)) {
|
|
7326
|
-
const aside =
|
|
7327
|
-
|
|
7454
|
+
const aside = join14(files.installedTypes(), `.${id}.${Date.now().toString(36)}.removed`);
|
|
7455
|
+
renameSync4(dir, aside);
|
|
7328
7456
|
rmSync3(aside, { recursive: true, force: true });
|
|
7329
7457
|
}
|
|
7330
7458
|
delete index.types[id];
|
|
@@ -7341,21 +7469,21 @@ function stagePackage(bytes, source) {
|
|
|
7341
7469
|
const now2 = Date.now();
|
|
7342
7470
|
for (const name of readdirSync8(dir)) {
|
|
7343
7471
|
try {
|
|
7344
|
-
if (now2 -
|
|
7472
|
+
if (now2 - statSync5(join14(dir, name)).mtimeMs > 36e5) rmSync3(join14(dir, name), { force: true });
|
|
7345
7473
|
} catch {
|
|
7346
7474
|
}
|
|
7347
7475
|
}
|
|
7348
7476
|
const hash = sha256(bytes);
|
|
7349
|
-
|
|
7350
|
-
|
|
7477
|
+
writeFileSync4(join14(dir, `${hash}${TYPE_PACKAGE_EXTENSION}`), bytes);
|
|
7478
|
+
writeFileSync4(join14(dir, `${hash}.json`), JSON.stringify({ source }));
|
|
7351
7479
|
return hash;
|
|
7352
7480
|
}
|
|
7353
7481
|
function stagedPackage(hash) {
|
|
7354
7482
|
if (!/^[0-9a-f]{64}$/.test(hash)) throw refuse("sha256 is the hex digest the preview gave.");
|
|
7355
7483
|
const dir = files.typesStaging();
|
|
7356
7484
|
try {
|
|
7357
|
-
const bytes =
|
|
7358
|
-
const { source } = JSON.parse(
|
|
7485
|
+
const bytes = readFileSync8(join14(dir, `${hash}${TYPE_PACKAGE_EXTENSION}`));
|
|
7486
|
+
const { source } = JSON.parse(readFileSync8(join14(dir, `${hash}.json`), "utf8"));
|
|
7359
7487
|
if (sha256(bytes) !== hash) throw new Error("changed");
|
|
7360
7488
|
return { bytes, source: String(source) };
|
|
7361
7489
|
} catch {
|
|
@@ -7364,11 +7492,11 @@ function stagedPackage(hash) {
|
|
|
7364
7492
|
}
|
|
7365
7493
|
function unstagePackage(hash) {
|
|
7366
7494
|
if (!/^[0-9a-f]{64}$/.test(hash)) return;
|
|
7367
|
-
for (const ext of [TYPE_PACKAGE_EXTENSION, ".json"]) rmSync3(
|
|
7495
|
+
for (const ext of [TYPE_PACKAGE_EXTENSION, ".json"]) rmSync3(join14(files.typesStaging(), `${hash}${ext}`), { force: true });
|
|
7368
7496
|
}
|
|
7369
7497
|
function typeCapabilities(dir) {
|
|
7370
7498
|
try {
|
|
7371
|
-
const decl = readStaticDeclaration(
|
|
7499
|
+
const decl = readStaticDeclaration(readFileSync8(join14(dir, "index.html"), "utf8"));
|
|
7372
7500
|
return decl ? Object.keys(decl.capabilities) : [];
|
|
7373
7501
|
} catch {
|
|
7374
7502
|
return [];
|
|
@@ -7383,7 +7511,7 @@ function typeSourceOf(type) {
|
|
|
7383
7511
|
function markerSourceOf(type) {
|
|
7384
7512
|
const { source, installedFrom } = typeSourceOf(type);
|
|
7385
7513
|
if (!installedFrom) return source;
|
|
7386
|
-
return isAddress(installedFrom) ? installedFrom :
|
|
7514
|
+
return isAddress(installedFrom) ? installedFrom : basename5(installedFrom);
|
|
7387
7515
|
}
|
|
7388
7516
|
function typeMismatch(record, type) {
|
|
7389
7517
|
if (!record.typeUid || !type) return null;
|
|
@@ -7427,11 +7555,11 @@ var init_type_packages = __esm({
|
|
|
7427
7555
|
});
|
|
7428
7556
|
|
|
7429
7557
|
// packages/daemon/src/runtime.ts
|
|
7430
|
-
import { createHash as createHash5, randomBytes as
|
|
7431
|
-
import { appendFileSync, chmodSync, cpSync as cpSync2, existsSync as existsSync10, mkdirSync as mkdirSync5, readdirSync as readdirSync9, readFileSync as
|
|
7558
|
+
import { createHash as createHash5, randomBytes as randomBytes6 } from "node:crypto";
|
|
7559
|
+
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";
|
|
7432
7560
|
import { cp } from "node:fs/promises";
|
|
7433
7561
|
import { homedir as homedir4 } from "node:os";
|
|
7434
|
-
import { dirname as
|
|
7562
|
+
import { dirname as dirname8, isAbsolute as isAbsolute3, join as join16, relative as relative5, resolve as resolve14, sep as sep8 } from "node:path";
|
|
7435
7563
|
import { gunzipSync } from "node:zlib";
|
|
7436
7564
|
function runtimeLog(line) {
|
|
7437
7565
|
try {
|
|
@@ -7463,7 +7591,7 @@ function saveRuntimeSettings(patch) {
|
|
|
7463
7591
|
function machinePolicyFile(env = process.env) {
|
|
7464
7592
|
if (env.OPEN_ARTIFACT_MACHINE_POLICY) return env.OPEN_ARTIFACT_MACHINE_POLICY;
|
|
7465
7593
|
if (process.platform === "darwin") return "/Library/Application Support/Open Artifact/policy.json";
|
|
7466
|
-
if (process.platform === "win32") return
|
|
7594
|
+
if (process.platform === "win32") return join16(env.ProgramData || "C:\\ProgramData", "Open Artifact", "policy.json");
|
|
7467
7595
|
return "/etc/open-artifact/policy.json";
|
|
7468
7596
|
}
|
|
7469
7597
|
function machineOff(env = process.env) {
|
|
@@ -7510,7 +7638,7 @@ function npmrc(file) {
|
|
|
7510
7638
|
const out2 = {};
|
|
7511
7639
|
let text3;
|
|
7512
7640
|
try {
|
|
7513
|
-
text3 =
|
|
7641
|
+
text3 = readFileSync10(file, "utf8");
|
|
7514
7642
|
} catch {
|
|
7515
7643
|
return out2;
|
|
7516
7644
|
}
|
|
@@ -7523,7 +7651,7 @@ function npmrc(file) {
|
|
|
7523
7651
|
function registryUrl(env = process.env) {
|
|
7524
7652
|
const scope = "@open-artifact:registry";
|
|
7525
7653
|
const lower = (name) => env[name] ?? env[name.toUpperCase()];
|
|
7526
|
-
const rc = npmrc(env.NPM_CONFIG_USERCONFIG || env.npm_config_userconfig ||
|
|
7654
|
+
const rc = npmrc(env.NPM_CONFIG_USERCONFIG || env.npm_config_userconfig || join16(homedir4(), ".npmrc"));
|
|
7527
7655
|
const named2 = env.OPEN_ARTIFACT_REGISTRY || runtimeSettings().registry || lower(`npm_config_${scope}`) || lower("npm_config_registry") || rc[scope] || rc.registry || DEFAULT_REGISTRY;
|
|
7528
7656
|
return named2.endsWith("/") ? named2 : `${named2}/`;
|
|
7529
7657
|
}
|
|
@@ -7746,25 +7874,25 @@ function readTarball(gz) {
|
|
|
7746
7874
|
return entries;
|
|
7747
7875
|
}
|
|
7748
7876
|
function writeEntries(entries, dest) {
|
|
7749
|
-
const root =
|
|
7877
|
+
const root = resolve14(dest);
|
|
7750
7878
|
mkdirSync5(root, { recursive: true });
|
|
7751
7879
|
for (const entry of entries) {
|
|
7752
|
-
const target =
|
|
7753
|
-
const rel =
|
|
7754
|
-
if (!rel || rel.startsWith("..") ||
|
|
7880
|
+
const target = resolve14(root, ...safeTarPath(entry.path));
|
|
7881
|
+
const rel = relative5(root, target);
|
|
7882
|
+
if (!rel || rel.startsWith("..") || isAbsolute3(rel)) throw new OpenArtifactError("bad_archive", `The package has a path outside its folder: ${entry.path}.`);
|
|
7755
7883
|
if (entry.type === "dir") {
|
|
7756
7884
|
mkdirSync5(target, { recursive: true, mode: 493 });
|
|
7757
7885
|
continue;
|
|
7758
7886
|
}
|
|
7759
|
-
mkdirSync5(
|
|
7760
|
-
|
|
7887
|
+
mkdirSync5(dirname8(target), { recursive: true, mode: 493 });
|
|
7888
|
+
writeFileSync6(target, entry.data, { mode: entry.mode & 73 ? 493 : 420 });
|
|
7761
7889
|
chmodSync(target, entry.mode & 73 ? 493 : 420);
|
|
7762
7890
|
}
|
|
7763
7891
|
}
|
|
7764
7892
|
function publishFolder(staging, version) {
|
|
7765
|
-
const target =
|
|
7893
|
+
const target = join16(sharedRuntimesOf(openArtifactHome2()), version);
|
|
7766
7894
|
try {
|
|
7767
|
-
|
|
7895
|
+
renameSync5(staging, target);
|
|
7768
7896
|
} catch (error) {
|
|
7769
7897
|
rmSync4(staging, { recursive: true, force: true });
|
|
7770
7898
|
if (!runtimeInfo(target)) throw error;
|
|
@@ -7773,11 +7901,11 @@ function publishFolder(staging, version) {
|
|
|
7773
7901
|
}
|
|
7774
7902
|
function stagingFolder(version) {
|
|
7775
7903
|
const root = ensureDir(sharedRuntimesOf(openArtifactHome2()));
|
|
7776
|
-
return
|
|
7904
|
+
return join16(root, `.staging-${version}-${process.pid}-${randomBytes6(4).toString("hex")}`);
|
|
7777
7905
|
}
|
|
7778
7906
|
async function installFromRegistry(manifest, registry) {
|
|
7779
7907
|
const version = manifest.version;
|
|
7780
|
-
const existing =
|
|
7908
|
+
const existing = join16(sharedRuntimesOf(openArtifactHome2()), version);
|
|
7781
7909
|
if (runtimeInfo(existing)) return existing;
|
|
7782
7910
|
const tarball = manifest.dist.tarball;
|
|
7783
7911
|
const response = await get(tarball, "application/octet-stream", 12e4);
|
|
@@ -7787,13 +7915,13 @@ async function installFromRegistry(manifest, registry) {
|
|
|
7787
7915
|
const staging = stagingFolder(version);
|
|
7788
7916
|
try {
|
|
7789
7917
|
writeEntries(entries, staging);
|
|
7790
|
-
const pkg = readJson(
|
|
7918
|
+
const pkg = readJson(join16(staging, "package.json"), null);
|
|
7791
7919
|
if (pkg?.name !== RUNTIME_PACKAGE || pkg.version !== version) {
|
|
7792
7920
|
throw new OpenArtifactError("bad_archive", `The tarball is not ${RUNTIME_PACKAGE}@${version} (its package.json says ${String(pkg?.name)}@${String(pkg?.version)}).`);
|
|
7793
7921
|
}
|
|
7794
7922
|
if (!runtimeInfo(staging)) throw new OpenArtifactError("bad_archive", "The tarball has no scripts/open-artifact.mjs.");
|
|
7795
7923
|
const record = { version, integrity: String(manifest.dist.integrity), tarball, registry, installedAt: (/* @__PURE__ */ new Date()).toISOString(), attestation: attestationOf(manifest) };
|
|
7796
|
-
|
|
7924
|
+
writeFileSync6(join16(staging, ".install.json"), `${JSON.stringify(record, null, 2)}
|
|
7797
7925
|
`);
|
|
7798
7926
|
const dir = publishFolder(staging, version);
|
|
7799
7927
|
runtimeLog(`installed ${RUNTIME_PACKAGE}@${version} in ${dir} (sha512 verified; attestation ${record.attestation.present ? "present, not verified" : "absent"})`);
|
|
@@ -7821,7 +7949,7 @@ function pruneShared(keep = []) {
|
|
|
7821
7949
|
for (const name of names) {
|
|
7822
7950
|
if (!name.startsWith(".staging-")) continue;
|
|
7823
7951
|
try {
|
|
7824
|
-
if (Date.now() -
|
|
7952
|
+
if (Date.now() - statSync6(join16(root, name)).mtimeMs > 60 * 6e4) rmSync4(join16(root, name), { recursive: true, force: true });
|
|
7825
7953
|
} catch {
|
|
7826
7954
|
}
|
|
7827
7955
|
}
|
|
@@ -7911,8 +8039,8 @@ function runtimeStatusText(status) {
|
|
|
7911
8039
|
}
|
|
7912
8040
|
function runtimeOfHello(value) {
|
|
7913
8041
|
const runtime2 = value;
|
|
7914
|
-
if (!runtime2 || typeof runtime2 !== "object" || typeof runtime2.dir !== "string" || !
|
|
7915
|
-
return { dir:
|
|
8042
|
+
if (!runtime2 || typeof runtime2 !== "object" || typeof runtime2.dir !== "string" || !isAbsolute3(runtime2.dir) || typeof runtime2.version !== "string" || !parseVersion(runtime2.version)) return null;
|
|
8043
|
+
return { dir: resolve14(runtime2.dir), version: runtime2.version, ...isPolicy(runtime2.update) ? { update: runtime2.update } : {} };
|
|
7916
8044
|
}
|
|
7917
8045
|
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;
|
|
7918
8046
|
var init_runtime = __esm({
|
|
@@ -7929,7 +8057,7 @@ var init_runtime = __esm({
|
|
|
7929
8057
|
MAX_METADATA = 32 << 20;
|
|
7930
8058
|
ADAPTER_MEMORY_MS = 90 * 24 * 60 * 6e4;
|
|
7931
8059
|
KEEP_SHARED = 3;
|
|
7932
|
-
runtimeCheckFile = () =>
|
|
8060
|
+
runtimeCheckFile = () => join16(openArtifactHome2(), "runtime-update.json");
|
|
7933
8061
|
POLICIES = ["auto", "prompt", "bundled"];
|
|
7934
8062
|
isPolicy = (value) => POLICIES.includes(value);
|
|
7935
8063
|
STRICTNESS = { auto: 0, prompt: 1, bundled: 2 };
|
|
@@ -7976,7 +8104,7 @@ var init_runtime = __esm({
|
|
|
7976
8104
|
/** Records a runtime in `runtimes.json` (one entry per folder) and copies it into the shared folder when it is the newest. */
|
|
7977
8105
|
register(record) {
|
|
7978
8106
|
this.writeFile((file) => {
|
|
7979
|
-
file.runtimes = [...file.runtimes.filter((r) =>
|
|
8107
|
+
file.runtimes = [...file.runtimes.filter((r) => resolve14(r.dir) !== resolve14(record.dir)), { ...record, seenAt: (/* @__PURE__ */ new Date()).toISOString() }];
|
|
7980
8108
|
});
|
|
7981
8109
|
this.adopt(record);
|
|
7982
8110
|
}
|
|
@@ -7986,12 +8114,12 @@ var init_runtime = __esm({
|
|
|
7986
8114
|
*/
|
|
7987
8115
|
adopt(record) {
|
|
7988
8116
|
const home2 = openArtifactHome2();
|
|
7989
|
-
if (this.copying || !existsSync10(
|
|
7990
|
-
if (
|
|
8117
|
+
if (this.copying || !existsSync10(join16(record.dir, "vendor", "open-artifact.mjs"))) return;
|
|
8118
|
+
if (resolve14(record.dir).startsWith(resolve14(sharedRuntimesOf(home2)) + sep8)) return;
|
|
7991
8119
|
const newest = sharedRuntimes(home2)[0]?.version;
|
|
7992
8120
|
if (newest && compareVersions(record.version, newest) <= 0) return;
|
|
7993
8121
|
const staging = stagingFolder(record.version);
|
|
7994
|
-
this.copying = cp(record.dir, staging, { recursive: true, verbatimSymlinks: true, filter: (from) => !from.split(
|
|
8122
|
+
this.copying = cp(record.dir, staging, { recursive: true, verbatimSymlinks: true, filter: (from) => !from.split(sep8).includes("node_modules") }).then(() => {
|
|
7995
8123
|
const dir = publishFolder(staging, record.version);
|
|
7996
8124
|
this.options.log(`runtime: kept a copy of ${record.harness ?? "a host"}'s runtime ${record.version} in ${dir}`);
|
|
7997
8125
|
pruneShared([record.version, this.options.version]);
|
|
@@ -8088,8 +8216,8 @@ var init_runtime = __esm({
|
|
|
8088
8216
|
// packages/daemon/src/node-children.ts
|
|
8089
8217
|
import { spawn as spawn3 } from "node:child_process";
|
|
8090
8218
|
import { EventEmitter as EventEmitter4 } from "node:events";
|
|
8091
|
-
import { realpathSync as
|
|
8092
|
-
import { isAbsolute as
|
|
8219
|
+
import { realpathSync as realpathSync4 } from "node:fs";
|
|
8220
|
+
import { isAbsolute as isAbsolute4, resolve as resolve15 } from "node:path";
|
|
8093
8221
|
import { PassThrough } from "node:stream";
|
|
8094
8222
|
import { Worker } from "node:worker_threads";
|
|
8095
8223
|
function modeFromEnv(env = process.env) {
|
|
@@ -8124,10 +8252,10 @@ function startChild(start) {
|
|
|
8124
8252
|
function threadEntry(args, cwd) {
|
|
8125
8253
|
const at = args.findIndex((arg) => !arg.startsWith("-"));
|
|
8126
8254
|
if (at < 0) throw new Error(`no script to run in ${JSON.stringify(args)}`);
|
|
8127
|
-
const given =
|
|
8255
|
+
const given = isAbsolute4(args[at]) ? args[at] : resolve15(cwd, args[at]);
|
|
8128
8256
|
let script = given;
|
|
8129
8257
|
try {
|
|
8130
|
-
script =
|
|
8258
|
+
script = realpathSync4(given);
|
|
8131
8259
|
} catch {
|
|
8132
8260
|
}
|
|
8133
8261
|
return { execArgv: args.slice(0, at), script, args: args.slice(at + 1) };
|
|
@@ -8253,9 +8381,9 @@ import(pathToFileURL(workerData.script).href).catch((error) => {
|
|
|
8253
8381
|
});
|
|
8254
8382
|
|
|
8255
8383
|
// packages/daemon/src/servers.ts
|
|
8256
|
-
import { randomBytes as
|
|
8257
|
-
import { createWriteStream, statSync as
|
|
8258
|
-
import { dirname as
|
|
8384
|
+
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
8385
|
+
import { createWriteStream, statSync as statSync7 } from "node:fs";
|
|
8386
|
+
import { dirname as dirname9, join as join18 } from "node:path";
|
|
8259
8387
|
function parseActions(raw) {
|
|
8260
8388
|
if (!Array.isArray(raw)) return [];
|
|
8261
8389
|
const out2 = [];
|
|
@@ -8292,7 +8420,7 @@ function failureOf(error, timeoutMs) {
|
|
|
8292
8420
|
}
|
|
8293
8421
|
function forRemote(type, body) {
|
|
8294
8422
|
if (!typeLocation(type).remote || !body || typeof body !== "object" || Array.isArray(body) || !("root" in body)) return body;
|
|
8295
|
-
const { root: _root, ...rest } = body;
|
|
8423
|
+
const { root: _root, workspaceDirectory: _workspace, ...rest } = body;
|
|
8296
8424
|
return rest;
|
|
8297
8425
|
}
|
|
8298
8426
|
function refuseRedirect(type, url, response) {
|
|
@@ -8328,7 +8456,7 @@ async function cappedText(type, url, response, max = REMOTE_ANSWER_MAX) {
|
|
|
8328
8456
|
function stampOf(type) {
|
|
8329
8457
|
let mtime = 0;
|
|
8330
8458
|
try {
|
|
8331
|
-
mtime =
|
|
8459
|
+
mtime = statSync7(join18(type.dir, "artifact-type.json")).mtimeMs;
|
|
8332
8460
|
} catch {
|
|
8333
8461
|
}
|
|
8334
8462
|
return JSON.stringify([type.dir, type.version, mtime, type.entry, type.trusted]);
|
|
@@ -8347,12 +8475,12 @@ var init_servers = __esm({
|
|
|
8347
8475
|
ACTION_CALL_MS = 9e4;
|
|
8348
8476
|
serverFiles = {
|
|
8349
8477
|
/** Last address and pid (`servers/<type>.json`), to reuse the port. */
|
|
8350
|
-
state: (type) =>
|
|
8478
|
+
state: (type) => join18(files.servers(), `${type}.json`),
|
|
8351
8479
|
/** The server's own state folder (`OPEN_ARTIFACT_STATE_DIR`). */
|
|
8352
|
-
stateDir: (type) =>
|
|
8353
|
-
log: (type) =>
|
|
8480
|
+
stateDir: (type) => join18(files.servers(), type),
|
|
8481
|
+
log: (type) => join18(files.logs(), "servers", `${type}.log`),
|
|
8354
8482
|
/** The last action list the server gave (`servers/<type>.actions.json`). */
|
|
8355
|
-
actions: (type) =>
|
|
8483
|
+
actions: (type) => join18(files.servers(), `${type}.actions.json`)
|
|
8356
8484
|
};
|
|
8357
8485
|
ACTION_NAME = /^[a-z0-9_-][a-z0-9_.-]{0,63}$/i;
|
|
8358
8486
|
where = (type, url) => typeLocation(type).remote ? `${url.origin}${url.pathname}` : url.pathname;
|
|
@@ -8412,7 +8540,15 @@ var init_servers = __esm({
|
|
|
8412
8540
|
const url2 = fillTemplate(entry.url, { id: record.id, lang: context.lang, root: record.root });
|
|
8413
8541
|
return { url: url2, page_url: url2 };
|
|
8414
8542
|
}
|
|
8415
|
-
const request = {
|
|
8543
|
+
const request = {
|
|
8544
|
+
id: record.id,
|
|
8545
|
+
root: record.root,
|
|
8546
|
+
title: record.title,
|
|
8547
|
+
lang: context.lang || "en",
|
|
8548
|
+
shell: context.shell,
|
|
8549
|
+
viewer: context.shell + shellPath(record.id),
|
|
8550
|
+
...record.workspaceDirectory ? { workspaceDirectory: record.workspaceDirectory } : {}
|
|
8551
|
+
};
|
|
8416
8552
|
const out2 = await this.call(type, "POST", TYPE_SERVER_ROUTES.open, request);
|
|
8417
8553
|
if (!out2 || typeof out2.url !== "string") throw new OpenArtifactError("server_failed", `${type.id}: ${TYPE_SERVER_ROUTES.open} returned no url.`);
|
|
8418
8554
|
const url = new URL(out2.url, base).href;
|
|
@@ -8608,8 +8744,8 @@ var init_servers = __esm({
|
|
|
8608
8744
|
const isNode = start.command === "node";
|
|
8609
8745
|
const mode2 = isNode ? this.nodeMode() : "process";
|
|
8610
8746
|
const last = readJson(serverFiles.state(type.id), null);
|
|
8611
|
-
const secret =
|
|
8612
|
-
ensureDir(
|
|
8747
|
+
const secret = randomBytes7(24).toString("base64url");
|
|
8748
|
+
ensureDir(dirname9(serverFiles.log(type.id)));
|
|
8613
8749
|
const stateDir = ensureDir(serverFiles.stateDir(type.id));
|
|
8614
8750
|
const log = createWriteStream(serverFiles.log(type.id), { flags: "a" });
|
|
8615
8751
|
log.write(`
|
|
@@ -8794,20 +8930,20 @@ __export(chatgpt_exports, {
|
|
|
8794
8930
|
chatgptSecret: () => chatgptSecret,
|
|
8795
8931
|
serveChatGpt: () => serveChatGpt
|
|
8796
8932
|
});
|
|
8797
|
-
import { randomBytes as
|
|
8798
|
-
import { existsSync as existsSync12, readFileSync as
|
|
8933
|
+
import { randomBytes as randomBytes8, timingSafeEqual } from "node:crypto";
|
|
8934
|
+
import { existsSync as existsSync12, readFileSync as readFileSync12 } from "node:fs";
|
|
8799
8935
|
import { createServer } from "node:http";
|
|
8800
|
-
import { join as
|
|
8936
|
+
import { join as join20 } from "node:path";
|
|
8801
8937
|
function chatgptSecret(rotate = false) {
|
|
8802
|
-
const file =
|
|
8938
|
+
const file = join20(openArtifactHome2(), "chatgpt.json");
|
|
8803
8939
|
if (!rotate && existsSync12(file)) {
|
|
8804
8940
|
try {
|
|
8805
|
-
const secret2 = JSON.parse(
|
|
8941
|
+
const secret2 = JSON.parse(readFileSync12(file, "utf8")).secret;
|
|
8806
8942
|
if (secret2 && /^[A-Za-z0-9_-]{24,}$/.test(secret2)) return secret2;
|
|
8807
8943
|
} catch {
|
|
8808
8944
|
}
|
|
8809
8945
|
}
|
|
8810
|
-
const secret =
|
|
8946
|
+
const secret = randomBytes8(24).toString("base64url");
|
|
8811
8947
|
writeJson(file, { secret });
|
|
8812
8948
|
return secret;
|
|
8813
8949
|
}
|
|
@@ -8955,9 +9091,9 @@ ${CHATGPT_NOTE}`.trim();
|
|
|
8955
9091
|
if (!res.headersSent) res.writeHead(500, { "Content-Type": "application/json" }).end(JSON.stringify({ jsonrpc: "2.0", id: null, error: { code: -32603, message: "Internal error" } }));
|
|
8956
9092
|
});
|
|
8957
9093
|
});
|
|
8958
|
-
await new Promise((
|
|
9094
|
+
await new Promise((resolve18, reject) => {
|
|
8959
9095
|
server.once("error", reject);
|
|
8960
|
-
server.listen(options.port, "127.0.0.1", () =>
|
|
9096
|
+
server.listen(options.port, "127.0.0.1", () => resolve18());
|
|
8961
9097
|
});
|
|
8962
9098
|
return server;
|
|
8963
9099
|
}
|
|
@@ -9056,29 +9192,29 @@ button:disabled{opacity:.55;cursor:default}
|
|
|
9056
9192
|
});
|
|
9057
9193
|
|
|
9058
9194
|
// packages/daemon/src/data-refresh.ts
|
|
9059
|
-
import { existsSync as existsSync13, readFileSync as
|
|
9060
|
-
import { join as
|
|
9195
|
+
import { existsSync as existsSync13, readFileSync as readFileSync13, readdirSync as readdirSync10 } from "node:fs";
|
|
9196
|
+
import { join as join21 } from "node:path";
|
|
9061
9197
|
function hasSnapshot(root) {
|
|
9062
|
-
return existsSync13(
|
|
9198
|
+
return existsSync13(join21(root, "db", "data", "live.json")) || existsSync13(join21(root, "db", "data", "live", "answers"));
|
|
9063
9199
|
}
|
|
9064
9200
|
function liveQueryIds(root) {
|
|
9065
9201
|
let names;
|
|
9066
9202
|
try {
|
|
9067
|
-
names = readdirSync10(
|
|
9203
|
+
names = readdirSync10(join21(root, "db", "datasets"));
|
|
9068
9204
|
} catch {
|
|
9069
9205
|
return [];
|
|
9070
9206
|
}
|
|
9071
9207
|
const ids = [];
|
|
9072
9208
|
for (const name of names.sort()) {
|
|
9073
9209
|
if (!name.endsWith(".json")) continue;
|
|
9074
|
-
const doc = readJson2(
|
|
9210
|
+
const doc = readJson2(join21(root, "db", "datasets", name));
|
|
9075
9211
|
if (!isObject4(doc) || doc.snapshot === false || !isObject4(doc.source)) continue;
|
|
9076
9212
|
if (doc.source.kind === "call" || doc.source.kind === "query") ids.push(name.slice(0, -5));
|
|
9077
9213
|
}
|
|
9078
9214
|
return ids;
|
|
9079
9215
|
}
|
|
9080
9216
|
function snapshotStatusOf(root) {
|
|
9081
|
-
const doc = readJson2(
|
|
9217
|
+
const doc = readJson2(join21(root, "db", "data", "live.json"));
|
|
9082
9218
|
if (!isObject4(doc)) return { at: null, failed: null };
|
|
9083
9219
|
const failed = isObject4(doc.failed) && typeof doc.failed.reason === "string" ? doc.failed.reason : null;
|
|
9084
9220
|
return { at: typeof doc.at === "string" && doc.at ? doc.at : null, failed };
|
|
@@ -9097,7 +9233,7 @@ var init_data_refresh = __esm({
|
|
|
9097
9233
|
message2 = (error) => error?.message ?? String(error);
|
|
9098
9234
|
readJson2 = (path) => {
|
|
9099
9235
|
try {
|
|
9100
|
-
return JSON.parse(
|
|
9236
|
+
return JSON.parse(readFileSync13(path, "utf8"));
|
|
9101
9237
|
} catch {
|
|
9102
9238
|
return null;
|
|
9103
9239
|
}
|
|
@@ -9253,8 +9389,8 @@ var init_data_refresh = __esm({
|
|
|
9253
9389
|
});
|
|
9254
9390
|
|
|
9255
9391
|
// packages/daemon/src/inbox.ts
|
|
9256
|
-
import { appendFileSync as appendFileSync2, readFileSync as
|
|
9257
|
-
import { join as
|
|
9392
|
+
import { appendFileSync as appendFileSync2, readFileSync as readFileSync14, renameSync as renameSync6, rmSync as rmSync6, writeFileSync as writeFileSync7 } from "node:fs";
|
|
9393
|
+
import { join as join22 } from "node:path";
|
|
9258
9394
|
var safe, Inbox;
|
|
9259
9395
|
var init_inbox = __esm({
|
|
9260
9396
|
"packages/daemon/src/inbox.ts"() {
|
|
@@ -9268,7 +9404,7 @@ var init_inbox = __esm({
|
|
|
9268
9404
|
}
|
|
9269
9405
|
/** The file of a session key. */
|
|
9270
9406
|
fileOf(key) {
|
|
9271
|
-
return
|
|
9407
|
+
return join22(files.inbox(), `${safe(key)}.jsonl`);
|
|
9272
9408
|
}
|
|
9273
9409
|
/** Appends a message; an open wait for this key takes it at once (`taken: true`). */
|
|
9274
9410
|
append(key, item) {
|
|
@@ -9289,7 +9425,7 @@ var init_inbox = __esm({
|
|
|
9289
9425
|
peek(key) {
|
|
9290
9426
|
let text3;
|
|
9291
9427
|
try {
|
|
9292
|
-
text3 =
|
|
9428
|
+
text3 = readFileSync14(this.fileOf(key), "utf8");
|
|
9293
9429
|
} catch {
|
|
9294
9430
|
return [];
|
|
9295
9431
|
}
|
|
@@ -9339,9 +9475,9 @@ var init_inbox = __esm({
|
|
|
9339
9475
|
if (!kept.length) rmSync6(file, { force: true });
|
|
9340
9476
|
else {
|
|
9341
9477
|
const next = `${file}.${process.pid}.tmp`;
|
|
9342
|
-
|
|
9478
|
+
writeFileSync7(next, kept.map((item) => `${JSON.stringify(item)}
|
|
9343
9479
|
`).join(""));
|
|
9344
|
-
|
|
9480
|
+
renameSync6(next, file);
|
|
9345
9481
|
}
|
|
9346
9482
|
}
|
|
9347
9483
|
/** The messages that are there, or the next ones to come, or `[]` after `timeoutMs`. */
|
|
@@ -9374,7 +9510,7 @@ var init_inbox = __esm({
|
|
|
9374
9510
|
|
|
9375
9511
|
// packages/daemon/src/preset.ts
|
|
9376
9512
|
import { createHash as createHash6 } from "node:crypto";
|
|
9377
|
-
import { statSync as
|
|
9513
|
+
import { statSync as statSync9 } from "node:fs";
|
|
9378
9514
|
function presetFrom(source, plugin = false) {
|
|
9379
9515
|
const get2 = (key) => text2(source[PRESET_KEYS[key]]);
|
|
9380
9516
|
const out2 = {};
|
|
@@ -9412,7 +9548,7 @@ function readPreset(env = process.env) {
|
|
|
9412
9548
|
function readableByOthers(path) {
|
|
9413
9549
|
if (process.platform === "win32") return null;
|
|
9414
9550
|
try {
|
|
9415
|
-
const mode2 =
|
|
9551
|
+
const mode2 = statSync9(path).mode & 511;
|
|
9416
9552
|
return mode2 & 36 ? mode2 : null;
|
|
9417
9553
|
} catch {
|
|
9418
9554
|
return null;
|
|
@@ -10256,9 +10392,9 @@ var init_wake2 = __esm({
|
|
|
10256
10392
|
});
|
|
10257
10393
|
|
|
10258
10394
|
// packages/daemon/src/link.ts
|
|
10259
|
-
import { createHash as createHash7, randomBytes as
|
|
10260
|
-
import { existsSync as existsSync14, mkdirSync as mkdirSync6, readFileSync as
|
|
10261
|
-
import { dirname as
|
|
10395
|
+
import { createHash as createHash7, randomBytes as randomBytes9 } from "node:crypto";
|
|
10396
|
+
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";
|
|
10397
|
+
import { dirname as dirname10, extname as extname3, join as join23, sep as sep9 } from "node:path";
|
|
10262
10398
|
function wakeSenderOf(value) {
|
|
10263
10399
|
if (!value || typeof value !== "object") return void 0;
|
|
10264
10400
|
const { name, role } = value;
|
|
@@ -11121,7 +11257,7 @@ var init_link2 = __esm({
|
|
|
11121
11257
|
if (typeof write?.file_path !== "string" || !write.file_path) return write;
|
|
11122
11258
|
let data;
|
|
11123
11259
|
try {
|
|
11124
|
-
data = JSON.parse(
|
|
11260
|
+
data = JSON.parse(readFileSync15(write.file_path, "utf8"));
|
|
11125
11261
|
} catch (error) {
|
|
11126
11262
|
throw new OpenArtifactError("invalid_argument", `file_path ${write.file_path}: ${message3(error)}`);
|
|
11127
11263
|
}
|
|
@@ -11168,7 +11304,7 @@ var init_link2 = __esm({
|
|
|
11168
11304
|
this.syncs.set(id, state);
|
|
11169
11305
|
try {
|
|
11170
11306
|
state.watcher = watch2(record.root, { recursive: true, persistent: false }, (_event, name) => {
|
|
11171
|
-
const rel = String(name ?? "").split(
|
|
11307
|
+
const rel = String(name ?? "").split(sep9).join("/");
|
|
11172
11308
|
if (rel && !linkSynced(rel) && rel !== ".artifact.json") return;
|
|
11173
11309
|
this.schedule(id, 200);
|
|
11174
11310
|
});
|
|
@@ -11255,15 +11391,15 @@ var init_link2 = __esm({
|
|
|
11255
11391
|
for (const entry of entries) {
|
|
11256
11392
|
const path = rel ? `${rel}/${entry.name}` : entry.name;
|
|
11257
11393
|
if (!linkSynced(path)) continue;
|
|
11258
|
-
const file =
|
|
11394
|
+
const file = join23(dir, entry.name);
|
|
11259
11395
|
if (entry.isDirectory()) walk(file, path);
|
|
11260
11396
|
else if (entry.isFile()) {
|
|
11261
11397
|
try {
|
|
11262
|
-
const stat2 =
|
|
11398
|
+
const stat2 = statSync10(file);
|
|
11263
11399
|
const known = state.hashes.get(path);
|
|
11264
11400
|
if (known && known.size === stat2.size && known.mtimeMs === stat2.mtimeMs) out2.set(path, known.etag);
|
|
11265
11401
|
else {
|
|
11266
|
-
const etag = sha2562(
|
|
11402
|
+
const etag = sha2562(readFileSync15(file));
|
|
11267
11403
|
state.hashes.set(path, { size: stat2.size, mtimeMs: stat2.mtimeMs, etag });
|
|
11268
11404
|
out2.set(path, etag);
|
|
11269
11405
|
}
|
|
@@ -11279,7 +11415,7 @@ var init_link2 = __esm({
|
|
|
11279
11415
|
/** The working copy's etag of one path now, `null` when it is not there. */
|
|
11280
11416
|
hashNow(root, path) {
|
|
11281
11417
|
try {
|
|
11282
|
-
return sha2562(
|
|
11418
|
+
return sha2562(readFileSync15(inside(root, path)));
|
|
11283
11419
|
} catch {
|
|
11284
11420
|
return null;
|
|
11285
11421
|
}
|
|
@@ -11347,7 +11483,7 @@ var init_link2 = __esm({
|
|
|
11347
11483
|
for (const write of pushes) {
|
|
11348
11484
|
let content = null;
|
|
11349
11485
|
try {
|
|
11350
|
-
const bytes =
|
|
11486
|
+
const bytes = readFileSync15(inside(root, write.path));
|
|
11351
11487
|
content = bytes.toString("base64");
|
|
11352
11488
|
batchBytes += bytes.length;
|
|
11353
11489
|
} catch {
|
|
@@ -11363,7 +11499,7 @@ var init_link2 = __esm({
|
|
|
11363
11499
|
const file = inside(root, path);
|
|
11364
11500
|
const got = host.has(path) || conflicts.includes(path) ? await client.readFile(id, path) : null;
|
|
11365
11501
|
if (got) {
|
|
11366
|
-
mkdirSync6(
|
|
11502
|
+
mkdirSync6(dirname10(file), { recursive: true });
|
|
11367
11503
|
writeFileAtomic(file, got.bytes);
|
|
11368
11504
|
setBase(path, sha2562(got.bytes));
|
|
11369
11505
|
} else {
|
|
@@ -11377,8 +11513,8 @@ var init_link2 = __esm({
|
|
|
11377
11513
|
const file = inside(root, path);
|
|
11378
11514
|
if (!existsSync14(file)) return;
|
|
11379
11515
|
const copy = conflictFile(root, path);
|
|
11380
|
-
mkdirSync6(
|
|
11381
|
-
writeFileAtomic(copy,
|
|
11516
|
+
mkdirSync6(dirname10(copy), { recursive: true });
|
|
11517
|
+
writeFileAtomic(copy, readFileSync15(file));
|
|
11382
11518
|
kept.push(path);
|
|
11383
11519
|
};
|
|
11384
11520
|
for (const path of pulls) {
|
|
@@ -11537,7 +11673,7 @@ var init_link2 = __esm({
|
|
|
11537
11673
|
};
|
|
11538
11674
|
const waits = [
|
|
11539
11675
|
...threads.map((thread) => this.o.wake(record.id, { thread: by(thread) })),
|
|
11540
|
-
...requests.map((r) => this.o.wake(record.id, { request: by({ ...r, id: r.id ?? `req_${Date.now().toString(36)}${
|
|
11676
|
+
...requests.map((r) => this.o.wake(record.id, { request: by({ ...r, id: r.id ?? `req_${Date.now().toString(36)}${randomBytes9(3).toString("hex")}` }) }))
|
|
11541
11677
|
];
|
|
11542
11678
|
await Promise.all(waits);
|
|
11543
11679
|
return;
|
|
@@ -11674,12 +11810,12 @@ var init_mcp2 = __esm({
|
|
|
11674
11810
|
|
|
11675
11811
|
// packages/daemon/src/nudge.ts
|
|
11676
11812
|
import { execFile } from "node:child_process";
|
|
11677
|
-
import { existsSync as existsSync15, readdirSync as readdirSync12, readFileSync as
|
|
11813
|
+
import { existsSync as existsSync15, readdirSync as readdirSync12, readFileSync as readFileSync16, statSync as statSync11 } from "node:fs";
|
|
11678
11814
|
import { homedir as homedir5 } from "node:os";
|
|
11679
|
-
import { delimiter, isAbsolute as
|
|
11815
|
+
import { delimiter, isAbsolute as isAbsolute5, join as join24 } from "node:path";
|
|
11680
11816
|
function expandHome2(path, home2) {
|
|
11681
11817
|
if (path === "~") return home2;
|
|
11682
|
-
return path.startsWith("~/") ?
|
|
11818
|
+
return path.startsWith("~/") ? join24(home2, path.slice(2)) : path;
|
|
11683
11819
|
}
|
|
11684
11820
|
function fillEnv(text3) {
|
|
11685
11821
|
let missing = false;
|
|
@@ -11692,7 +11828,7 @@ function fillEnv(text3) {
|
|
|
11692
11828
|
}
|
|
11693
11829
|
function onPath(name, platform = process.platform, path = process.env.PATH ?? "") {
|
|
11694
11830
|
const dirs = path.split(delimiter).filter(Boolean);
|
|
11695
|
-
const at = (dir, file) =>
|
|
11831
|
+
const at = (dir, file) => join24(dir, file);
|
|
11696
11832
|
if (platform !== "win32") {
|
|
11697
11833
|
for (const dir of dirs) if (isFile(at(dir, name))) return { found: at(dir, name) };
|
|
11698
11834
|
return null;
|
|
@@ -11720,7 +11856,7 @@ function nudgeProgram(command, home2, options = {}) {
|
|
|
11720
11856
|
return { command: filled, args: before };
|
|
11721
11857
|
}
|
|
11722
11858
|
const path = expandHome2(filled, home2);
|
|
11723
|
-
if (
|
|
11859
|
+
if (isAbsolute5(path) || path.includes("/") || path.includes("\\")) {
|
|
11724
11860
|
if (platform === "win32" && isBatch(path)) {
|
|
11725
11861
|
if (existsSync15(path)) skipBatch(path);
|
|
11726
11862
|
continue;
|
|
@@ -11750,7 +11886,7 @@ function liveEnvFile(spec, needs, home2, alive2 = defaultAlive) {
|
|
|
11750
11886
|
}
|
|
11751
11887
|
for (const name of names) {
|
|
11752
11888
|
try {
|
|
11753
|
-
const fields = JSON.parse(
|
|
11889
|
+
const fields = JSON.parse(readFileSync16(join24(dir, name), "utf8"));
|
|
11754
11890
|
if (!fields || typeof fields !== "object" || needs.some((field) => fields[field] === void 0 || fields[field] === null || fields[field] === "")) continue;
|
|
11755
11891
|
const pid = spec.pid ? Number(fields[spec.pid]) : 0;
|
|
11756
11892
|
if (pid && !alive2(pid)) continue;
|
|
@@ -11823,7 +11959,7 @@ var init_nudge = __esm({
|
|
|
11823
11959
|
};
|
|
11824
11960
|
isFile = (path) => {
|
|
11825
11961
|
try {
|
|
11826
|
-
return
|
|
11962
|
+
return statSync11(path).isFile();
|
|
11827
11963
|
} catch {
|
|
11828
11964
|
return false;
|
|
11829
11965
|
}
|
|
@@ -11834,10 +11970,18 @@ var init_nudge = __esm({
|
|
|
11834
11970
|
});
|
|
11835
11971
|
|
|
11836
11972
|
// packages/daemon/src/release-guard.ts
|
|
11837
|
-
|
|
11973
|
+
function releaseMarker(record) {
|
|
11974
|
+
try {
|
|
11975
|
+
const files2 = artifactDirectory(record);
|
|
11976
|
+
const value = files2.readJson(MARKER, null);
|
|
11977
|
+
return value ? { files: files2, value } : null;
|
|
11978
|
+
} catch {
|
|
11979
|
+
return null;
|
|
11980
|
+
}
|
|
11981
|
+
}
|
|
11838
11982
|
function writtenRelease(record) {
|
|
11839
|
-
const
|
|
11840
|
-
const candidates = [record.typeRelease, typeof
|
|
11983
|
+
const release = releaseMarker(record)?.value.release;
|
|
11984
|
+
const candidates = [record.typeRelease, typeof release === "string" ? release : null].filter((v) => !!v && !!parseVersion(v));
|
|
11841
11985
|
return candidates.sort((a, b) => compareVersions(b, a))[0] ?? null;
|
|
11842
11986
|
}
|
|
11843
11987
|
function isNewerRelease(written, installed) {
|
|
@@ -11858,17 +12002,17 @@ function readOnlyNote(record, written, installed) {
|
|
|
11858
12002
|
return `Read-only here: ${record.type} ${written} wrote this artifact and this computer has ${installed}. Do not try to change it; tell the person to update Open Artifact (open-artifact runtime update).`;
|
|
11859
12003
|
}
|
|
11860
12004
|
function writeMarkerRelease(record, release) {
|
|
11861
|
-
const
|
|
11862
|
-
|
|
11863
|
-
if (marker && marker.release !== release) writeJson(file, { ...marker, release });
|
|
12005
|
+
const marker = releaseMarker(record);
|
|
12006
|
+
if (marker && marker.value.release !== release) marker.files.writeJson(MARKER, { ...marker.value, release });
|
|
11864
12007
|
}
|
|
11865
|
-
var ReleaseGuard;
|
|
12008
|
+
var MARKER, ReleaseGuard;
|
|
11866
12009
|
var init_release_guard = __esm({
|
|
11867
12010
|
"packages/daemon/src/release-guard.ts"() {
|
|
11868
12011
|
"use strict";
|
|
11869
12012
|
init_src();
|
|
12013
|
+
init_workspace_files();
|
|
11870
12014
|
init_src2();
|
|
11871
|
-
|
|
12015
|
+
MARKER = ".artifact.json";
|
|
11872
12016
|
ReleaseGuard = class {
|
|
11873
12017
|
options;
|
|
11874
12018
|
constructor(options) {
|
|
@@ -11915,7 +12059,7 @@ var init_release_guard = __esm({
|
|
|
11915
12059
|
});
|
|
11916
12060
|
|
|
11917
12061
|
// packages/daemon/src/artifact-import.ts
|
|
11918
|
-
import { readFileSync as
|
|
12062
|
+
import { readFileSync as readFileSync17, rmSync as rmSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
11919
12063
|
import { join as join25 } from "node:path";
|
|
11920
12064
|
async function readArtifactArchive(bytes, source, o) {
|
|
11921
12065
|
if (bytes.byteLength > ARTIFACT_IMPORT_LIMITS.zipBytes) throw new OpenArtifactError("too_large", `${source} is larger than ${ARTIFACT_IMPORT_LIMITS.zipBytes} bytes.`, { status: 413 });
|
|
@@ -11967,9 +12111,9 @@ async function unpackArtifactArchive(bytes, read, dest) {
|
|
|
11967
12111
|
}
|
|
11968
12112
|
try {
|
|
11969
12113
|
const file = join25(unpacked.temp, ".artifact.json");
|
|
11970
|
-
const { id: _id, ...rest } = JSON.parse(
|
|
12114
|
+
const { id: _id, ...rest } = JSON.parse(readFileSync17(file, "utf8"));
|
|
11971
12115
|
rmSync8(file, { force: true });
|
|
11972
|
-
|
|
12116
|
+
writeFileSync8(file, `${JSON.stringify({ ...rest, type: read.type.id }, null, 2)}
|
|
11973
12117
|
`, { flag: "wx" });
|
|
11974
12118
|
await moveIntoPlace(unpacked.temp, dest);
|
|
11975
12119
|
} catch (error) {
|
|
@@ -12066,9 +12210,9 @@ var init_remote_archive = __esm({
|
|
|
12066
12210
|
|
|
12067
12211
|
// packages/daemon/src/tools.ts
|
|
12068
12212
|
import { createHash as createHash8 } from "node:crypto";
|
|
12069
|
-
import { existsSync as existsSync16, mkdirSync as mkdirSync7, readFileSync as
|
|
12213
|
+
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";
|
|
12070
12214
|
import { homedir as homedir6 } from "node:os";
|
|
12071
|
-
import { basename as
|
|
12215
|
+
import { basename as basename6, dirname as dirname11, isAbsolute as isAbsolute6, join as join26, resolve as resolve16, sep as sep10 } from "node:path";
|
|
12072
12216
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
12073
12217
|
function offlineOf(link, record) {
|
|
12074
12218
|
const note = link?.offlineNote(record);
|
|
@@ -12139,6 +12283,23 @@ function argsShape(schema) {
|
|
|
12139
12283
|
return `, args: {${shown.join(", ")}${props.length > 8 ? ", ..." : ""}}`;
|
|
12140
12284
|
}
|
|
12141
12285
|
function localPathIn(value, at, root, depth = 0) {
|
|
12286
|
+
const home2 = homedir6();
|
|
12287
|
+
const under = (full, dir) => !!dir && (full === resolve16(dir) || full.startsWith(resolve16(dir) + sep10));
|
|
12288
|
+
return pathIn(value, at, (full) => under(full, home2) || under(full, root) || existsSync16(full), depth);
|
|
12289
|
+
}
|
|
12290
|
+
function pathOutside(value, at, workspace) {
|
|
12291
|
+
return pathIn(value, at, (full) => {
|
|
12292
|
+
const top = full.split(sep10).slice(0, 2).join(sep10) || sep10;
|
|
12293
|
+
if (!existsSync16(top)) return false;
|
|
12294
|
+
try {
|
|
12295
|
+
workspace.resolve(full);
|
|
12296
|
+
return false;
|
|
12297
|
+
} catch {
|
|
12298
|
+
return true;
|
|
12299
|
+
}
|
|
12300
|
+
});
|
|
12301
|
+
}
|
|
12302
|
+
function pathIn(value, at, counts, depth = 0) {
|
|
12142
12303
|
if (typeof value === "string") {
|
|
12143
12304
|
if (value.length > 4096) return null;
|
|
12144
12305
|
let path = value;
|
|
@@ -12149,16 +12310,13 @@ function localPathIn(value, at, root, depth = 0) {
|
|
|
12149
12310
|
return null;
|
|
12150
12311
|
}
|
|
12151
12312
|
}
|
|
12152
|
-
if (!
|
|
12153
|
-
|
|
12154
|
-
const full = resolve15(path);
|
|
12155
|
-
const under = (dir) => !!dir && (full === resolve15(dir) || full.startsWith(resolve15(dir) + sep9));
|
|
12156
|
-
return under(home2) || under(root) || existsSync16(full) ? { at, path: value } : null;
|
|
12313
|
+
if (!isAbsolute6(path) || resolve16(path) === resolve16("/")) return null;
|
|
12314
|
+
return counts(resolve16(path)) ? { at, path: value } : null;
|
|
12157
12315
|
}
|
|
12158
12316
|
if (depth >= 8 || !value || typeof value !== "object") return null;
|
|
12159
12317
|
const entries = Array.isArray(value) ? value.slice(0, 1e3).map((item, i) => [String(i), item]) : Object.entries(value).slice(0, 1e3);
|
|
12160
12318
|
for (const [key, item] of entries) {
|
|
12161
|
-
const found2 =
|
|
12319
|
+
const found2 = pathIn(item, Array.isArray(value) ? `${at}[${key}]` : `${at}.${key}`, counts, depth + 1);
|
|
12162
12320
|
if (found2) return found2;
|
|
12163
12321
|
}
|
|
12164
12322
|
return null;
|
|
@@ -12180,18 +12338,18 @@ function capabilitiesOf(value, type) {
|
|
|
12180
12338
|
if (problem) throw new OpenArtifactError("invalid_argument", problem);
|
|
12181
12339
|
return JSON.parse(JSON.stringify(value));
|
|
12182
12340
|
}
|
|
12183
|
-
function markerTypeUid(
|
|
12341
|
+
function markerTypeUid(files2) {
|
|
12184
12342
|
try {
|
|
12185
|
-
const marker = JSON.parse(
|
|
12343
|
+
const marker = JSON.parse(readFileSync18(files2.resolve(".artifact.json"), "utf8"));
|
|
12186
12344
|
const typeUid = typeof marker.typeUid === "string" && marker.typeUid ? marker.typeUid : null;
|
|
12187
12345
|
return { typeUid, typeSource: typeUid && typeof marker.typeSource === "string" ? marker.typeSource : null };
|
|
12188
12346
|
} catch {
|
|
12189
12347
|
return { typeUid: null, typeSource: null };
|
|
12190
12348
|
}
|
|
12191
12349
|
}
|
|
12192
|
-
function markerCapabilities(
|
|
12350
|
+
function markerCapabilities(files2) {
|
|
12193
12351
|
try {
|
|
12194
|
-
const value = JSON.parse(
|
|
12352
|
+
const value = JSON.parse(readFileSync18(files2.resolve(".artifact.json"), "utf8")).capabilities;
|
|
12195
12353
|
return value !== void 0 && !capabilitiesProblem(value) && Object.keys(value).length ? value : void 0;
|
|
12196
12354
|
} catch {
|
|
12197
12355
|
return void 0;
|
|
@@ -12206,20 +12364,26 @@ function capabilityNotes(capabilities) {
|
|
|
12206
12364
|
...unknown.length ? [`${unknown.join(", ")}: no such capability here; use() gives the page null for ${unknown.length === 1 ? "it" : "them"}.`] : []
|
|
12207
12365
|
];
|
|
12208
12366
|
}
|
|
12209
|
-
function contentTitle(
|
|
12367
|
+
function contentTitle(files2, titleFrom) {
|
|
12210
12368
|
const parsed = titleFrom ? parseTitleFrom(titleFrom) : null;
|
|
12211
12369
|
if (!parsed) return void 0;
|
|
12212
12370
|
try {
|
|
12213
|
-
return titleInFile(parsed.file,
|
|
12371
|
+
return titleInFile(parsed.file, readFileSync18(files2.resolve(parsed.file), "utf8"), parsed.pointer)?.slice(0, 200);
|
|
12214
12372
|
} catch {
|
|
12215
12373
|
return void 0;
|
|
12216
12374
|
}
|
|
12217
12375
|
}
|
|
12376
|
+
function inFolder(root, folder) {
|
|
12377
|
+
const full = resolve16(root);
|
|
12378
|
+
const top = resolve16(folder);
|
|
12379
|
+
return full === top || full.startsWith(top.endsWith(sep10) ? top : top + sep10);
|
|
12380
|
+
}
|
|
12218
12381
|
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;
|
|
12219
12382
|
var init_tools2 = __esm({
|
|
12220
12383
|
"packages/daemon/src/tools.ts"() {
|
|
12221
12384
|
"use strict";
|
|
12222
12385
|
init_src();
|
|
12386
|
+
init_workspace_files();
|
|
12223
12387
|
init_harness_profiles();
|
|
12224
12388
|
init_harness_skill();
|
|
12225
12389
|
init_paths();
|
|
@@ -12368,7 +12532,7 @@ var init_tools2 = __esm({
|
|
|
12368
12532
|
case "publish":
|
|
12369
12533
|
if (args.url) {
|
|
12370
12534
|
this.allow(caller2, "modify", "Artifact publish with url");
|
|
12371
|
-
return this.write(args);
|
|
12535
|
+
return this.write(args, caller2);
|
|
12372
12536
|
}
|
|
12373
12537
|
this.allow(caller2, "create", "Artifact publish with type_url");
|
|
12374
12538
|
return this.create(args, caller2);
|
|
@@ -12551,17 +12715,17 @@ ${rules}` };
|
|
|
12551
12715
|
const wanted = significant(text3);
|
|
12552
12716
|
if (!wanted.size) return [];
|
|
12553
12717
|
const me = sessionKeyOf(caller2);
|
|
12554
|
-
const workspace = caller2.workspace ?
|
|
12718
|
+
const workspace = caller2.workspace ? resolve16(caller2.workspace) : null;
|
|
12555
12719
|
const mine = (a) => !!a.owner && sessionKeyOf(a.owner) === me;
|
|
12556
|
-
return this.o.store.list().filter((a) => a.type === type.id && (mine(a) || reuse === "workspace" && !!workspace && a.root
|
|
12720
|
+
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) }));
|
|
12557
12721
|
}
|
|
12558
12722
|
/** The caller's artifacts (theirs, or under their workspace) of the types `type` builds on (`openArtifact.uses`), newest first. */
|
|
12559
12723
|
relatedTo(type, caller2) {
|
|
12560
12724
|
if (!type.uses.length) return [];
|
|
12561
12725
|
const me = sessionKeyOf(caller2);
|
|
12562
|
-
const workspace = caller2.workspace ?
|
|
12726
|
+
const workspace = caller2.workspace ? resolve16(caller2.workspace) : null;
|
|
12563
12727
|
const mine = (a) => !!a.owner && sessionKeyOf(a.owner) === me;
|
|
12564
|
-
return this.o.store.list().filter((a) => type.uses.includes(a.type) && (mine(a) || workspace && a.root
|
|
12728
|
+
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 }));
|
|
12565
12729
|
}
|
|
12566
12730
|
list(args, caller2) {
|
|
12567
12731
|
const scope = args.scope ?? "mine";
|
|
@@ -12576,10 +12740,10 @@ ${rules}` };
|
|
|
12576
12740
|
const offset = args.cursor === void 0 || args.cursor === "" ? 0 : Number(args.cursor);
|
|
12577
12741
|
if (!Number.isInteger(offset) || offset < 0) throw new OpenArtifactError("invalid_argument", "cursor: the next_cursor of the previous page.");
|
|
12578
12742
|
const me = sessionKeyOf(caller2);
|
|
12579
|
-
const workspace = caller2.workspace ?
|
|
12743
|
+
const workspace = caller2.workspace ? resolve16(caller2.workspace) : null;
|
|
12580
12744
|
const mine = (a) => !!a.owner && sessionKeyOf(a.owner) === me;
|
|
12581
12745
|
const changed = (a) => !!a.lastUserEditAt && (!a.agentSeenAt || a.lastUserEditAt > a.agentSeenAt);
|
|
12582
|
-
const shown = this.o.store.list().filter((a) => scope === "all" || mine(a) || workspace && a.root
|
|
12746
|
+
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)));
|
|
12583
12747
|
const page = shown.slice(offset, offset + limit);
|
|
12584
12748
|
const anyChanged = page.some(changed);
|
|
12585
12749
|
return {
|
|
@@ -12607,12 +12771,17 @@ ${rules}` };
|
|
|
12607
12771
|
* A caller with no known workspace gets the home folder, never the daemon's own folder (which may be a plugin's).
|
|
12608
12772
|
*/
|
|
12609
12773
|
resolveFolder(folder, caller2, title) {
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12774
|
+
if (this.o.workspaceFoldersOnly && !caller2.workspace) {
|
|
12775
|
+
throw new OpenArtifactError("not_granted", "A local workspace is required to create or adopt a work.");
|
|
12776
|
+
}
|
|
12777
|
+
const base = caller2.workspace ? resolve16(caller2.workspace) : homedir6();
|
|
12778
|
+
const directory = this.o.workspaceFoldersOnly ? new WorkspaceDirectory(base) : null;
|
|
12779
|
+
const folderPath = (candidate) => directory?.resolve(candidate) ?? candidate;
|
|
12780
|
+
if (folder) return folderPath(resolve16(base, folder));
|
|
12781
|
+
const dir = folderPath(join26(base, this.o.settings().artifactsDir || "artifacts"));
|
|
12613
12782
|
const slug = slugify(title);
|
|
12614
|
-
let root = join26(dir, slug);
|
|
12615
|
-
for (let i = 2; existsSync16(root) && readdirSync13(root).length; i++) root = join26(dir, `${slug}-${i}`);
|
|
12783
|
+
let root = folderPath(join26(dir, slug));
|
|
12784
|
+
for (let i = 2; existsSync16(root) && readdirSync13(root).length; i++) root = folderPath(join26(dir, `${slug}-${i}`));
|
|
12616
12785
|
return root;
|
|
12617
12786
|
}
|
|
12618
12787
|
/** The type's actions, or `null` when they are not known; never fails. */
|
|
@@ -12693,7 +12862,19 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12693
12862
|
if (known) throw new OpenArtifactError("conflict", `${root} is already the artifact ${artifactUrl(known.id)}.`, { fix: "Use that url, or give another folder." });
|
|
12694
12863
|
}
|
|
12695
12864
|
const owner = caller2.session || caller2.workspace ? caller2 : null;
|
|
12696
|
-
const
|
|
12865
|
+
const workspace = this.workspaceDirectory(caller2);
|
|
12866
|
+
const record = this.o.store.create({
|
|
12867
|
+
root,
|
|
12868
|
+
type: typeId,
|
|
12869
|
+
typeSource: type.scope,
|
|
12870
|
+
typeRelease: type.version,
|
|
12871
|
+
typeUid: type.uid,
|
|
12872
|
+
typeFrom: markerSourceOf(type),
|
|
12873
|
+
owner,
|
|
12874
|
+
title,
|
|
12875
|
+
capabilities,
|
|
12876
|
+
...workspace ? { workspaceDirectory: workspace.identity } : {}
|
|
12877
|
+
});
|
|
12697
12878
|
this.o.log(`created ${record.id} (${typeId}) at ${root} for ${sessionKeyOf(caller2) ?? "nobody"}`);
|
|
12698
12879
|
const auto = this.o.link?.created?.(record) === true;
|
|
12699
12880
|
const actions = await this.knownActions(type, false);
|
|
@@ -12726,13 +12907,34 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12726
12907
|
/** A file's sha256, `null` when there is none. */
|
|
12727
12908
|
hashOf(file) {
|
|
12728
12909
|
try {
|
|
12729
|
-
return
|
|
12910
|
+
return statSync12(file).isFile() ? sha2563(readFileSync18(file)) : null;
|
|
12730
12911
|
} catch {
|
|
12731
12912
|
return null;
|
|
12732
12913
|
}
|
|
12733
12914
|
}
|
|
12734
|
-
|
|
12915
|
+
/**
|
|
12916
|
+
* Whether a listing may show an artifact to a caller in `workspace`: always, except in a workspace-confined daemon,
|
|
12917
|
+
* where only the artifacts whose folders are in that workspace are shown (`scope: "all"` included), so a sandboxed
|
|
12918
|
+
* agent never learns the paths of folders it cannot reach.
|
|
12919
|
+
*/
|
|
12920
|
+
reachable(record, workspace) {
|
|
12921
|
+
return !this.o.workspaceFoldersOnly || !!workspace && inFolder(record.root, workspace);
|
|
12922
|
+
}
|
|
12923
|
+
/** In a workspace-confined daemon, the caller's workspace: every folder it makes, adopts or touches stays in it. */
|
|
12924
|
+
workspaceDirectory(caller2) {
|
|
12925
|
+
if (!this.o.workspaceFoldersOnly) return null;
|
|
12926
|
+
if (!caller2.workspace) throw new OpenArtifactError("not_granted", "A local workspace is required to access an artifact.");
|
|
12927
|
+
return new WorkspaceDirectory(caller2.workspace);
|
|
12928
|
+
}
|
|
12929
|
+
/** In a workspace-confined daemon, the artifact's real folder, checked to be in the caller's workspace. */
|
|
12930
|
+
artifactFiles(record, caller2) {
|
|
12931
|
+
const workspace = this.workspaceDirectory(caller2);
|
|
12932
|
+
if (!workspace) return null;
|
|
12933
|
+
return new WorkspaceDirectory(workspace.resolve(this.o.store.authorizedRoot(record)));
|
|
12934
|
+
}
|
|
12935
|
+
async write(args, caller2) {
|
|
12735
12936
|
let record = this.o.store.require(args.url);
|
|
12937
|
+
const directory = this.artifactFiles(record, caller2);
|
|
12736
12938
|
const type = this.o.types?.get(record.type, record.owner?.workspace ?? void 0) ?? null;
|
|
12737
12939
|
const capabilities = args.capabilities === void 0 ? void 0 : capabilitiesOf(args.capabilities, type);
|
|
12738
12940
|
const given = args.files === void 0 && capabilities !== void 0 ? {} : args.files;
|
|
@@ -12743,7 +12945,8 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12743
12945
|
const plan = entries.map(([rel, value]) => {
|
|
12744
12946
|
const clean = cleanPath(rel);
|
|
12745
12947
|
if (/(^|\/)(\.artifact[^/]*|\.sharing\.json|_blobs)(\/|$)/.test(clean)) throw new OpenArtifactError("bad_path", `${rel} is the artifact's own bookkeeping.`);
|
|
12746
|
-
const
|
|
12948
|
+
const requested = inside(record.root, clean);
|
|
12949
|
+
const file = directory?.resolve(requested, value !== null) ?? requested;
|
|
12747
12950
|
if (value === null) return { clean, file, bytes: null };
|
|
12748
12951
|
const content = typeof value === "string" ? value : value?.content;
|
|
12749
12952
|
if (typeof content !== "string") throw new OpenArtifactError("invalid_argument", `${rel}: give text, or {content, encoding: "base64"}.`);
|
|
@@ -12761,7 +12964,8 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12761
12964
|
throw new OpenArtifactError("invalid_argument", `if_match ${rel}: the sha256 read returned, null (the file must not exist) or "*".`);
|
|
12762
12965
|
}
|
|
12763
12966
|
const clean = cleanPath(rel);
|
|
12764
|
-
const
|
|
12967
|
+
const requested = inside(record.root, clean);
|
|
12968
|
+
const current = this.hashOf(directory?.resolve(requested) ?? requested);
|
|
12765
12969
|
if (expected === null ? current !== null : current !== expected.toLowerCase()) conflicts.push(clean);
|
|
12766
12970
|
}
|
|
12767
12971
|
if (conflicts.length) {
|
|
@@ -12771,8 +12975,9 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12771
12975
|
message: `${conflicts.length === 1 ? "A file" : `${conflicts.length} files`} changed since you read ${conflicts.length === 1 ? "it" : "them"}: nothing was written.`,
|
|
12772
12976
|
fix: "Merge your change into the current version in current, then write again with its sha256 as if_match."
|
|
12773
12977
|
},
|
|
12978
|
+
executionStatus: "not_executed",
|
|
12774
12979
|
url: artifactUrl(record.id),
|
|
12775
|
-
current: Object.fromEntries(conflicts.map((path) => [path, this.fileState(record, path)]))
|
|
12980
|
+
current: Object.fromEntries(conflicts.map((path) => [path, this.fileState(record, path, directory)]))
|
|
12776
12981
|
};
|
|
12777
12982
|
}
|
|
12778
12983
|
}
|
|
@@ -12783,13 +12988,13 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12783
12988
|
written.push({ path: clean, deleted: true });
|
|
12784
12989
|
continue;
|
|
12785
12990
|
}
|
|
12786
|
-
mkdirSync7(
|
|
12787
|
-
|
|
12991
|
+
mkdirSync7(dirname11(file), { recursive: true });
|
|
12992
|
+
writeFileSync9(file, bytes);
|
|
12788
12993
|
written.push({ path: clean, bytes: bytes.length, sha256: sha2563(bytes) });
|
|
12789
12994
|
}
|
|
12790
12995
|
if (capabilities !== void 0) record = this.o.store.setCapabilities(record.id, Object.keys(capabilities).length ? capabilities : null);
|
|
12791
12996
|
const changed = changedFiles(record);
|
|
12792
|
-
const titled = type?.titleFrom && isPageType(type) && plan.some(({ clean }) => clean === parseTitleFrom(type.titleFrom)?.file) ? contentTitle(record.root, type.titleFrom) : void 0;
|
|
12997
|
+
const titled = type?.titleFrom && isPageType(type) && plan.some(({ clean }) => clean === parseTitleFrom(type.titleFrom)?.file) ? contentTitle(directory ?? new WorkspaceDirectory(record.root), type.titleFrom) : void 0;
|
|
12793
12998
|
this.o.store.update(record.id, { agentSeenAt: now(), ...titled && titled !== record.title ? { title: titled } : {} });
|
|
12794
12999
|
if (record.remote || record.autoPublish === "pending") this.o.link?.wrote(record);
|
|
12795
13000
|
const offline = this.o.link?.offlineNote(record) ?? null;
|
|
@@ -12817,20 +13022,20 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12817
13022
|
}
|
|
12818
13023
|
}
|
|
12819
13024
|
/** What a file holds now, for a conflict: its sha256 and, for text, its content. */
|
|
12820
|
-
fileState(record, path) {
|
|
13025
|
+
fileState(record, path, directory) {
|
|
12821
13026
|
try {
|
|
12822
|
-
return this.readOne(record, path, MAX_READ);
|
|
13027
|
+
return this.readOne(record, path, MAX_READ, directory);
|
|
12823
13028
|
} catch {
|
|
12824
13029
|
return { sha256: null, note: "It does not exist." };
|
|
12825
13030
|
}
|
|
12826
13031
|
}
|
|
12827
|
-
listFiles(root, hashes = false) {
|
|
13032
|
+
listFiles(root, hashes = false, directory = null) {
|
|
12828
13033
|
const out2 = [];
|
|
12829
13034
|
const walk = (dir, rel) => {
|
|
12830
13035
|
if (out2.length >= MAX_LIST) return;
|
|
12831
13036
|
let entries;
|
|
12832
13037
|
try {
|
|
12833
|
-
entries = readdirSync13(dir, { withFileTypes: true });
|
|
13038
|
+
entries = readdirSync13(directory?.resolve(dir) ?? dir, { withFileTypes: true });
|
|
12834
13039
|
} catch {
|
|
12835
13040
|
return;
|
|
12836
13041
|
}
|
|
@@ -12840,9 +13045,10 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12840
13045
|
if (e.isDirectory()) walk(join26(dir, e.name), r);
|
|
12841
13046
|
else if (out2.length < MAX_LIST) {
|
|
12842
13047
|
try {
|
|
12843
|
-
const
|
|
12844
|
-
const
|
|
12845
|
-
|
|
13048
|
+
const requested = join26(dir, e.name);
|
|
13049
|
+
const file = directory?.resolve(requested) ?? requested;
|
|
13050
|
+
const bytes = statSync12(file).size;
|
|
13051
|
+
out2.push({ path: r, bytes, ...hashes && bytes <= MAX_LIST_HASH ? { sha256: sha2563(readFileSync18(file)) } : {} });
|
|
12846
13052
|
} catch {
|
|
12847
13053
|
}
|
|
12848
13054
|
}
|
|
@@ -12852,12 +13058,13 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12852
13058
|
return out2;
|
|
12853
13059
|
}
|
|
12854
13060
|
/** One file (its content and sha256) or folder (its listing) under the root; text is cut at `budget` characters. */
|
|
12855
|
-
readOne(record, path, budget) {
|
|
12856
|
-
const
|
|
13061
|
+
readOne(record, path, budget, directory) {
|
|
13062
|
+
const requested = inside(record.root, path);
|
|
13063
|
+
const file = directory?.resolve(requested) ?? requested;
|
|
12857
13064
|
if (!existsSync16(file)) throw new OpenArtifactError("not_found", `No file ${path} in ${record.root}.`);
|
|
12858
|
-
const stat2 =
|
|
12859
|
-
if (stat2.isDirectory()) return { path, files: this.listFiles(file, true) };
|
|
12860
|
-
const buffer =
|
|
13065
|
+
const stat2 = statSync12(file);
|
|
13066
|
+
if (stat2.isDirectory()) return { path, files: this.listFiles(file, true, directory) };
|
|
13067
|
+
const buffer = readFileSync18(file);
|
|
12861
13068
|
const hash = sha2563(buffer);
|
|
12862
13069
|
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." };
|
|
12863
13070
|
if (budget <= 0) return { path, bytes: stat2.size, sha256: hash, note: "Not read: this result is full. Read it on its own." };
|
|
@@ -12877,6 +13084,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12877
13084
|
throw new OpenArtifactError("invalid_argument", "read needs url (an artifact) or type_url (a type).");
|
|
12878
13085
|
}
|
|
12879
13086
|
const record = this.o.store.require(args.url);
|
|
13087
|
+
const directory = this.artifactFiles(record, caller2);
|
|
12880
13088
|
const changed = changedFiles(record);
|
|
12881
13089
|
this.o.store.update(record.id, { agentSeenAt: now(), updatedAt: record.updatedAt });
|
|
12882
13090
|
const seen = changed.length ? { changed_files: changed, notes: [changedNote(changed.length)] } : {};
|
|
@@ -12888,7 +13096,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12888
13096
|
let budget = MAX_READ_TOTAL;
|
|
12889
13097
|
const files2 = args.paths.map((path) => {
|
|
12890
13098
|
try {
|
|
12891
|
-
const one = this.readOne(record, path, budget);
|
|
13099
|
+
const one = this.readOne(record, path, budget, directory);
|
|
12892
13100
|
if (typeof one.content === "string") budget -= one.content.length;
|
|
12893
13101
|
return one;
|
|
12894
13102
|
} catch (error) {
|
|
@@ -12897,8 +13105,8 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12897
13105
|
});
|
|
12898
13106
|
return { url: artifactUrl(record.id), files: files2, ...seen, ...this.pageContentFields(record) };
|
|
12899
13107
|
}
|
|
12900
|
-
if (args.path) return { ...this.readOne(record, args.path, MAX_READ), ...seen, ...this.pageContentFields(record) };
|
|
12901
|
-
const { owner, userEdits: _edits, remote: remote2, ...shown } = record;
|
|
13108
|
+
if (args.path) return { ...this.readOne(record, args.path, MAX_READ, directory), ...seen, ...this.pageContentFields(record) };
|
|
13109
|
+
const { owner, userEdits: _edits, remote: remote2, workspaceDirectory: _workspace, ...shown } = record;
|
|
12902
13110
|
const type = this.o.types.get(record.type, owner?.workspace ?? void 0);
|
|
12903
13111
|
const actions = type ? await this.knownActions(type, false) : null;
|
|
12904
13112
|
return {
|
|
@@ -12912,7 +13120,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
12912
13120
|
// notice: the type's, then the page content's, in the one field).
|
|
12913
13121
|
...type ? { type_title: type.title, ...typeLocationFields(type), ...this.sourceFields(type) } : {},
|
|
12914
13122
|
...type && !type.trusted ? { third_party_notice: `${restrictedTypeNotice(type)} ${PAGE_CONTENT_NOTICE}` } : {},
|
|
12915
|
-
files: this.listFiles(record.root, true),
|
|
13123
|
+
files: this.listFiles(record.root, true, directory),
|
|
12916
13124
|
...actions ? { actions } : {},
|
|
12917
13125
|
...seen
|
|
12918
13126
|
};
|
|
@@ -13035,6 +13243,15 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13035
13243
|
);
|
|
13036
13244
|
}
|
|
13037
13245
|
}
|
|
13246
|
+
const confined = caller2 ? this.workspaceDirectory(caller2) : null;
|
|
13247
|
+
if (confined) {
|
|
13248
|
+
const outside = pathOutside(args, "args", confined);
|
|
13249
|
+
if (outside) {
|
|
13250
|
+
throw new OpenArtifactError("not_granted", `${name} cannot take ${outside.at} (${outside.path}): it is outside this session's workspace.`, {
|
|
13251
|
+
fix: "Use a file inside the workspace, or pass the content itself in the arguments."
|
|
13252
|
+
});
|
|
13253
|
+
}
|
|
13254
|
+
}
|
|
13038
13255
|
const fresh = !forward && this.o.link?.renders(record, type, name) ? await this.o.link.freshen(record, type) : null;
|
|
13039
13256
|
const behind = fresh?.note ?? null;
|
|
13040
13257
|
if (fresh?.reload && this.o.reopenPage) await this.o.reopenPage(record);
|
|
@@ -13058,6 +13275,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13058
13275
|
try {
|
|
13059
13276
|
const out2 = forward ? await this.o.link.call(record, name, args, effect) : await this.o.typeAction(type, record, name, args);
|
|
13060
13277
|
const result = out2 && typeof out2 === "object" && !Array.isArray(out2) ? out2 : { result: out2 };
|
|
13278
|
+
if (result.error && result.executionStatus === "not_executed") delete result.executionStatus;
|
|
13061
13279
|
if (behind) result.notes = [...Array.isArray(result.notes) ? result.notes : [], behind];
|
|
13062
13280
|
if (own && caller2 && typeof result.task === "string" && result.pending === true) {
|
|
13063
13281
|
this.o.taskStarted?.({ record, type, task: result.task, action: name, effect, caller: caller2 });
|
|
@@ -13065,6 +13283,10 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13065
13283
|
if (own && caller2 && effect === "write") this.o.ownership?.wrote(record.id, caller2);
|
|
13066
13284
|
return result;
|
|
13067
13285
|
} catch (error) {
|
|
13286
|
+
if (name === "open-artifact.db.write" && !forward && !location.remote && error instanceof OpenArtifactError && error.status === 409 && error.code === "conflict" && error.current !== void 0) {
|
|
13287
|
+
const { current, ...body } = errorBody(error);
|
|
13288
|
+
return { error: body, current, executionStatus: "not_executed" };
|
|
13289
|
+
}
|
|
13068
13290
|
if (error?.code === "unknown_action") {
|
|
13069
13291
|
if (missing) throw missing;
|
|
13070
13292
|
if (own && !error.fix) throw unknown(actions);
|
|
@@ -13086,10 +13308,16 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13086
13308
|
async adopt(args, caller2) {
|
|
13087
13309
|
if (args.url) {
|
|
13088
13310
|
const record2 = this.o.store.require(args.url);
|
|
13311
|
+
const workspace2 = this.workspaceDirectory(caller2);
|
|
13312
|
+
if (workspace2) workspace2.resolve(record2.workspaceDirectory ? this.o.store.authorizedRoot(record2) : record2.root);
|
|
13089
13313
|
const owner = record2.owner ? sessionKeyOf(record2.owner) : null;
|
|
13090
13314
|
if (owner && owner !== sessionKeyOf(caller2)) this.allow(caller2, "remove", "Artifact adopt of another session's artifact");
|
|
13091
13315
|
else this.allow(caller2, "modify", "Artifact adopt");
|
|
13092
|
-
const next = this.o.store.update(record2.id, {
|
|
13316
|
+
const next = this.o.store.update(record2.id, {
|
|
13317
|
+
owner: caller2,
|
|
13318
|
+
agentSeenAt: now(),
|
|
13319
|
+
...workspace2 && !record2.workspaceDirectory ? { workspaceDirectory: workspace2.identity } : {}
|
|
13320
|
+
});
|
|
13093
13321
|
this.o.handOff?.(next.id, caller2, "adopt");
|
|
13094
13322
|
const type2 = this.o.types.get(next.type, caller2.workspace ?? void 0);
|
|
13095
13323
|
const actions2 = type2 ? await this.knownActions(type2, false) : null;
|
|
@@ -13108,19 +13336,28 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13108
13336
|
const known = this.o.store.byRoot(root);
|
|
13109
13337
|
if (known) return this.adopt({ url: artifactUrl(known.id) }, caller2);
|
|
13110
13338
|
this.allow(caller2, "create", "Artifact adopt of a folder");
|
|
13339
|
+
const workspace = this.workspaceDirectory(caller2);
|
|
13340
|
+
const files2 = new WorkspaceDirectory(workspace?.resolve(root) ?? root);
|
|
13111
13341
|
let typeId = typeIdOf(args.type_url);
|
|
13112
13342
|
if (!typeId) {
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13343
|
+
const marker = files2.readJson(".artifact.json", null);
|
|
13344
|
+
if (marker === null) {
|
|
13345
|
+
typeId = this.o.types.list(caller2.workspace).find((t) => t.detect.some((rel) => {
|
|
13346
|
+
try {
|
|
13347
|
+
return existsSync16(files2.resolve(rel));
|
|
13348
|
+
} catch {
|
|
13349
|
+
return false;
|
|
13350
|
+
}
|
|
13351
|
+
}))?.id ?? null;
|
|
13352
|
+
} else if (typeof marker.type === "string") {
|
|
13353
|
+
typeId = marker.type;
|
|
13117
13354
|
}
|
|
13118
13355
|
}
|
|
13119
13356
|
if (!typeId) throw new OpenArtifactError("invalid_argument", `Which type is ${root}? Give type_url.`);
|
|
13120
13357
|
const type = this.o.types.get(typeId, caller2.workspace);
|
|
13121
|
-
const title = args.title || contentTitle(
|
|
13122
|
-
const capabilities = isPageType(type) ? markerCapabilities(
|
|
13123
|
-
const marked = markerTypeUid(
|
|
13358
|
+
const title = args.title || contentTitle(files2, type?.titleFrom ?? null) || basename6(root);
|
|
13359
|
+
const capabilities = isPageType(type) ? markerCapabilities(files2) : void 0;
|
|
13360
|
+
const marked = markerTypeUid(files2);
|
|
13124
13361
|
const record = this.o.store.create({
|
|
13125
13362
|
root,
|
|
13126
13363
|
type: typeId,
|
|
@@ -13130,7 +13367,8 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13130
13367
|
typeFrom: marked.typeSource,
|
|
13131
13368
|
owner: caller2,
|
|
13132
13369
|
title,
|
|
13133
|
-
capabilities
|
|
13370
|
+
capabilities,
|
|
13371
|
+
...workspace ? { workspaceDirectory: workspace.identity } : {}
|
|
13134
13372
|
});
|
|
13135
13373
|
const auto = this.o.link?.created?.(record) === true;
|
|
13136
13374
|
const actions = type ? await this.knownActions(type, false) : null;
|
|
@@ -13148,13 +13386,13 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13148
13386
|
const record = this.o.store.require(args.url);
|
|
13149
13387
|
if (actionKindOf("ArtifactData", typeof args.action === "string" ? args.action : void 0) !== "read") this.allow(caller2, "modify", `ArtifactData ${String(args.action)}`);
|
|
13150
13388
|
const noStore = new OpenArtifactError("unsupported", `${record.type} keeps no document store: write its files with Artifact publish.`);
|
|
13151
|
-
const db = (name, a) => this.action(record, name, a, noStore);
|
|
13389
|
+
const db = (name, a) => this.action(record, name, a, noStore, caller2);
|
|
13152
13390
|
const docPath = args.path ?? (args.collection && args.doc_id ? `${args.collection}/${args.doc_id}` : args.collection);
|
|
13153
|
-
const base = caller2.workspace ?
|
|
13391
|
+
const base = caller2.workspace ? resolve16(caller2.workspace) : record.root;
|
|
13154
13392
|
const writeOf = (w) => {
|
|
13155
13393
|
const out2 = {};
|
|
13156
13394
|
for (const key of DATA_WRITE_KEYS) if (w[key] !== void 0) out2[key] = w[key];
|
|
13157
|
-
if (typeof out2.file_path === "string" && out2.file_path) out2.file_path =
|
|
13395
|
+
if (typeof out2.file_path === "string" && out2.file_path) out2.file_path = resolve16(base, out2.file_path);
|
|
13158
13396
|
return out2;
|
|
13159
13397
|
};
|
|
13160
13398
|
const write = async (writes) => {
|
|
@@ -13183,7 +13421,7 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13183
13421
|
if (args.action === "query" && docs && out2.query !== true) notes.push(DATA_QUERY_IGNORED_NOTE);
|
|
13184
13422
|
if (docs && docs.some((d) => typeof d.sha256 !== "string") || out2.exists === true && typeof out2.sha256 !== "string") notes.push(DATA_NO_SHA_NOTE);
|
|
13185
13423
|
const result = { url: artifactUrl(record.id), ...out2, ...notes.length ? { notes } : {}, ...this.pageContentFields(record) };
|
|
13186
|
-
return args.out_file ? this.dataToFile(record, result, args.out_file, base) : result;
|
|
13424
|
+
return args.out_file ? this.dataToFile(record, result, args.out_file, base, this.workspaceDirectory(caller2)) : result;
|
|
13187
13425
|
}
|
|
13188
13426
|
case "set":
|
|
13189
13427
|
case "update":
|
|
@@ -13201,14 +13439,14 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13201
13439
|
}
|
|
13202
13440
|
}
|
|
13203
13441
|
/** A read's result written to a JSON file: the agent reads it from disk instead of its context. */
|
|
13204
|
-
dataToFile(record, result, outFile, base) {
|
|
13205
|
-
const file =
|
|
13206
|
-
if (file === record.root || file.startsWith(record.root +
|
|
13207
|
-
mkdirSync7(
|
|
13442
|
+
dataToFile(record, result, outFile, base, workspace) {
|
|
13443
|
+
const file = workspace ? workspace.resolve(resolve16(base, outFile)) : resolve16(base, outFile);
|
|
13444
|
+
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.");
|
|
13445
|
+
mkdirSync7(dirname11(file), { recursive: true });
|
|
13208
13446
|
const { notes, url: _url, third_party_notice: notice, ...data } = result;
|
|
13209
13447
|
const text3 = `${JSON.stringify(data, null, 2)}
|
|
13210
13448
|
`;
|
|
13211
|
-
|
|
13449
|
+
writeFileSync9(file, text3);
|
|
13212
13450
|
const count = Array.isArray(data.docs) ? data.docs.length : Array.isArray(data.documents) ? data.documents.length : data.exists === true ? 1 : 0;
|
|
13213
13451
|
return {
|
|
13214
13452
|
url: artifactUrl(record.id),
|
|
@@ -13290,8 +13528,8 @@ ${body ?? `(The type ${type.id} has no SKILL.md: ${type.description})`}`;
|
|
|
13290
13528
|
const touched = /* @__PURE__ */ new Set();
|
|
13291
13529
|
const records = this.o.store.list();
|
|
13292
13530
|
for (const p of paths) {
|
|
13293
|
-
const abs =
|
|
13294
|
-
const record = records.find((a) => abs === a.root || abs.startsWith(a.root +
|
|
13531
|
+
const abs = resolve16(caller2.workspace ?? "/", p);
|
|
13532
|
+
const record = records.find((a) => abs === a.root || abs.startsWith(a.root + sep10));
|
|
13295
13533
|
if (record && !touched.has(record.id)) {
|
|
13296
13534
|
touched.add(record.id);
|
|
13297
13535
|
this.o.store.update(record.id, { agentSeenAt: now() });
|
|
@@ -13467,17 +13705,17 @@ __export(daemon_exports, {
|
|
|
13467
13705
|
startDaemon: () => startDaemon,
|
|
13468
13706
|
takeOverPrompt: () => takeOverPrompt
|
|
13469
13707
|
});
|
|
13470
|
-
import { randomBytes as
|
|
13708
|
+
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
13471
13709
|
import { EventEmitter as EventEmitter5 } from "node:events";
|
|
13472
|
-
import { appendFileSync as appendFileSync3, cpSync as cpSync3, createReadStream, existsSync as existsSync17, openSync as openSync4, readFileSync as
|
|
13710
|
+
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";
|
|
13473
13711
|
import { createServer as createServer2 } from "node:http";
|
|
13474
13712
|
import { userInfo } from "node:os";
|
|
13475
|
-
import { basename as
|
|
13713
|
+
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";
|
|
13476
13714
|
import { Readable } from "node:stream";
|
|
13477
13715
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
13478
13716
|
function defaultUiDir(name) {
|
|
13479
13717
|
const fromEnv = name === "shell" ? process.env.OPEN_ARTIFACT_SHELL_DIR : process.env.OPEN_ARTIFACT_HOME_DIR;
|
|
13480
|
-
return fromEnv ?
|
|
13718
|
+
return fromEnv ? resolve17(fromEnv) : resolve17(here, "..", "..", "..", "dist", "daemon", name);
|
|
13481
13719
|
}
|
|
13482
13720
|
function isContentPath(rel) {
|
|
13483
13721
|
const parts = rel.split("/");
|
|
@@ -13542,9 +13780,6 @@ async function readJsonBody(req) {
|
|
|
13542
13780
|
throw new OpenArtifactError("invalid_argument", "The body is not JSON.");
|
|
13543
13781
|
}
|
|
13544
13782
|
}
|
|
13545
|
-
function sharedOnLan(root) {
|
|
13546
|
-
return readJson(join27(root, ".sharing.json"), null)?.lan === true;
|
|
13547
|
-
}
|
|
13548
13783
|
function safeUserName() {
|
|
13549
13784
|
try {
|
|
13550
13785
|
return userInfo().username || "You";
|
|
@@ -13605,6 +13840,7 @@ var DATA_REFRESH_MS, here, VERSION3, BOOT_PLACEHOLDER, UI_PATHS, PAGE_IDLE_MS, T
|
|
|
13605
13840
|
var init_daemon2 = __esm({
|
|
13606
13841
|
"packages/daemon/src/daemon.ts"() {
|
|
13607
13842
|
"use strict";
|
|
13843
|
+
init_workspace_files();
|
|
13608
13844
|
init_src();
|
|
13609
13845
|
init_zip();
|
|
13610
13846
|
init_data_refresh();
|
|
@@ -13635,7 +13871,7 @@ var init_daemon2 = __esm({
|
|
|
13635
13871
|
init_ws();
|
|
13636
13872
|
init_package();
|
|
13637
13873
|
DATA_REFRESH_MS = 15 * 6e4;
|
|
13638
|
-
here =
|
|
13874
|
+
here = dirname12(fileURLToPath5(import.meta.url));
|
|
13639
13875
|
VERSION3 = package_default.version ?? "0.0.0";
|
|
13640
13876
|
BOOT_PLACEHOLDER = "/*__OPEN_ARTIFACT_BOOT__*/null";
|
|
13641
13877
|
UI_PATHS = { shell: "/_open-artifact/shell/", home: "/_open-artifact/home/" };
|
|
@@ -13740,7 +13976,7 @@ var init_daemon2 = __esm({
|
|
|
13740
13976
|
/** The listening port, once started. */
|
|
13741
13977
|
port = 0;
|
|
13742
13978
|
/** Bearer token of the Library and Harness APIs and MCP. */
|
|
13743
|
-
token =
|
|
13979
|
+
token = randomBytes10(24).toString("base64url");
|
|
13744
13980
|
settings;
|
|
13745
13981
|
/** Install-time cloud presets (environment, `preset.json`), read once at construction. */
|
|
13746
13982
|
preset;
|
|
@@ -13796,12 +14032,12 @@ var init_daemon2 = __esm({
|
|
|
13796
14032
|
this.wantPort = options.port ?? this.settings.serverPort;
|
|
13797
14033
|
this.idleMs = options.idleMs ?? Number(process.env.OPEN_ARTIFACT_IDLE_MS ?? 30 * 6e4);
|
|
13798
14034
|
this.quiet = options.quiet ?? false;
|
|
13799
|
-
this.shellDir =
|
|
13800
|
-
this.homeDir =
|
|
14035
|
+
this.shellDir = resolve17(options.shellDir ?? defaultUiDir("shell"));
|
|
14036
|
+
this.homeDir = resolve17(options.homeDir ?? defaultUiDir("home"));
|
|
13801
14037
|
this.logFile = files.daemonLog();
|
|
13802
14038
|
const log = (line) => this.log(line);
|
|
13803
14039
|
this.types = new TypeRegistry(() => this.settings, options.builtinTypesDir !== void 0 ? { builtinDir: options.builtinTypesDir } : {});
|
|
13804
|
-
this.store = new ArtifactStore();
|
|
14040
|
+
this.store = new ArtifactStore(options.workspaceFoldersOnly === true);
|
|
13805
14041
|
this.inbox = new Inbox();
|
|
13806
14042
|
this.wake = new WakeRouter({
|
|
13807
14043
|
store: this.store,
|
|
@@ -13847,7 +14083,7 @@ var init_daemon2 = __esm({
|
|
|
13847
14083
|
run: async (record, args) => {
|
|
13848
14084
|
const type = this.typeOf(record);
|
|
13849
14085
|
if (!type) throw new OpenArtifactError("not_found", `The type ${record.type} is not installed.`);
|
|
13850
|
-
return this.servers.call(type, "POST", `${TYPE_SERVER_ROUTES.actions}${encodeURIComponent(DATA_REFRESH_ACTION)}`, { id: record.id, root: record
|
|
14086
|
+
return this.servers.call(type, "POST", `${TYPE_SERVER_ROUTES.actions}${encodeURIComponent(DATA_REFRESH_ACTION)}`, { id: record.id, root: this.store.authorizedRoot(record), args }, void 0, DATA_REFRESH_MS);
|
|
13851
14087
|
},
|
|
13852
14088
|
sync: (id) => this.link.syncNow(id),
|
|
13853
14089
|
owner: (record) => this.link.ownerName(record),
|
|
@@ -13859,11 +14095,12 @@ var init_daemon2 = __esm({
|
|
|
13859
14095
|
inbox: this.inbox,
|
|
13860
14096
|
harnesses: () => this.harnesses,
|
|
13861
14097
|
settings: () => this.settings,
|
|
14098
|
+
workspaceFoldersOnly: options.workspaceFoldersOnly === true,
|
|
13862
14099
|
viewUrl: (id) => this.viewUrl(id),
|
|
13863
14100
|
openPage: (record) => this.openPage(record),
|
|
13864
14101
|
reopenPage: (record) => this.reopenPage(record),
|
|
13865
14102
|
reach: (type) => this.servers.reach(type),
|
|
13866
|
-
typeAction: (type, record, name, args) => this.servers.call(type, "POST", `${TYPE_SERVER_ROUTES.actions}${encodeURIComponent(name)}`, { id: record.id, root: record
|
|
14103
|
+
typeAction: (type, record, name, args) => this.servers.call(type, "POST", `${TYPE_SERVER_ROUTES.actions}${encodeURIComponent(name)}`, { id: record.id, root: this.store.authorizedRoot(record), args }, void 0, ACTION_CALL_MS),
|
|
13867
14104
|
typeActions: (type, options2) => this.servers.actions(type, options2),
|
|
13868
14105
|
shareOf: (record) => this.shareOf(record),
|
|
13869
14106
|
log,
|
|
@@ -13995,7 +14232,7 @@ var init_daemon2 = __esm({
|
|
|
13995
14232
|
const actions = await this.servers.actions(type, { start: true });
|
|
13996
14233
|
if (!actions?.some((a) => a.name === "context")) return null;
|
|
13997
14234
|
await this.openPage(record);
|
|
13998
|
-
return this.servers.call(type, "POST", `${TYPE_SERVER_ROUTES.actions}context`, { id: record.id, root: record
|
|
14235
|
+
return this.servers.call(type, "POST", `${TYPE_SERVER_ROUTES.actions}context`, { id: record.id, root: this.store.authorizedRoot(record), args: {} }, void 0, ACTION_CALL_MS);
|
|
13999
14236
|
}
|
|
14000
14237
|
});
|
|
14001
14238
|
}
|
|
@@ -14056,7 +14293,7 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
|
|
|
14056
14293
|
writeSync(fd, String(process.pid));
|
|
14057
14294
|
closeSync4(fd);
|
|
14058
14295
|
} catch {
|
|
14059
|
-
const other = Number(
|
|
14296
|
+
const other = Number(readFileSync19(lock, "utf8"));
|
|
14060
14297
|
let alive2 = false;
|
|
14061
14298
|
try {
|
|
14062
14299
|
process.kill(other, 0);
|
|
@@ -14065,7 +14302,7 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
|
|
|
14065
14302
|
alive2 = false;
|
|
14066
14303
|
}
|
|
14067
14304
|
if (alive2) throw new OpenArtifactError("conflict", `Another open-artifact daemon (pid ${other}) runs for ${openArtifactHome2()}.`);
|
|
14068
|
-
|
|
14305
|
+
writeFileSync10(lock, String(process.pid), { mode: 384 });
|
|
14069
14306
|
}
|
|
14070
14307
|
let port = this.wantPort;
|
|
14071
14308
|
for (let i = 0; ; i++) {
|
|
@@ -14098,9 +14335,17 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
|
|
|
14098
14335
|
this.data.start();
|
|
14099
14336
|
return this;
|
|
14100
14337
|
}
|
|
14338
|
+
/** The library and startup use the same checked sharing record as the editor. */
|
|
14339
|
+
sharedOnLan(record) {
|
|
14340
|
+
try {
|
|
14341
|
+
return readSharingState(new WorkspaceDirectory(this.store.authorizedRoot(record)))?.lan === true;
|
|
14342
|
+
} catch {
|
|
14343
|
+
return false;
|
|
14344
|
+
}
|
|
14345
|
+
}
|
|
14101
14346
|
async remountShared() {
|
|
14102
14347
|
for (const record of this.store.list()) {
|
|
14103
|
-
if (!sharedOnLan(record
|
|
14348
|
+
if (!this.sharedOnLan(record)) continue;
|
|
14104
14349
|
try {
|
|
14105
14350
|
await this.openPage(record);
|
|
14106
14351
|
} catch (error) {
|
|
@@ -14291,7 +14536,7 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
|
|
|
14291
14536
|
const state = readJson(files.daemon(), null);
|
|
14292
14537
|
if (state?.pid === process.pid) rmSync10(files.daemon(), { force: true });
|
|
14293
14538
|
try {
|
|
14294
|
-
if (Number(
|
|
14539
|
+
if (Number(readFileSync19(files.lock(), "utf8")) === process.pid) rmSync10(files.lock(), { force: true });
|
|
14295
14540
|
} catch {
|
|
14296
14541
|
}
|
|
14297
14542
|
this.log(`daemon ${VERSION3} stopped (${reason})`);
|
|
@@ -14417,15 +14662,15 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
|
|
|
14417
14662
|
} catch {
|
|
14418
14663
|
return this.notFound(req, res);
|
|
14419
14664
|
}
|
|
14420
|
-
this.sendFile(req, res, file, file.includes(`${
|
|
14665
|
+
this.sendFile(req, res, file, file.includes(`${sep11}assets${sep11}`) ? "public, max-age=31536000, immutable" : "no-cache");
|
|
14421
14666
|
}
|
|
14422
14667
|
sendFile(req, res, file, cache) {
|
|
14423
14668
|
let stat2;
|
|
14424
14669
|
try {
|
|
14425
|
-
stat2 =
|
|
14670
|
+
stat2 = statSync13(file);
|
|
14426
14671
|
if (stat2.isDirectory()) {
|
|
14427
14672
|
file = join27(file, "index.html");
|
|
14428
|
-
stat2 =
|
|
14673
|
+
stat2 = statSync13(file);
|
|
14429
14674
|
}
|
|
14430
14675
|
} catch {
|
|
14431
14676
|
return this.notFound(req, res);
|
|
@@ -14448,7 +14693,7 @@ data: ${JSON.stringify({ view: view2, key: claimed.key, session: claimed.session
|
|
|
14448
14693
|
homePage(req, res) {
|
|
14449
14694
|
req.resume();
|
|
14450
14695
|
try {
|
|
14451
|
-
sendHtml(res,
|
|
14696
|
+
sendHtml(res, readFileSync19(join27(this.homeDir, "index.html"), "utf8"));
|
|
14452
14697
|
return;
|
|
14453
14698
|
} catch {
|
|
14454
14699
|
}
|
|
@@ -14566,7 +14811,7 @@ ${rows}
|
|
|
14566
14811
|
const record = this.touchOpened(found2);
|
|
14567
14812
|
let template = null;
|
|
14568
14813
|
try {
|
|
14569
|
-
template =
|
|
14814
|
+
template = readFileSync19(join27(this.shellDir, "index.html"), "utf8");
|
|
14570
14815
|
} catch {
|
|
14571
14816
|
}
|
|
14572
14817
|
let boot;
|
|
@@ -14613,7 +14858,7 @@ ${rows}
|
|
|
14613
14858
|
if (depth < 5) walk(full, path, depth + 1);
|
|
14614
14859
|
} else {
|
|
14615
14860
|
try {
|
|
14616
|
-
newest = Math.max(newest,
|
|
14861
|
+
newest = Math.max(newest, statSync13(full).mtimeMs);
|
|
14617
14862
|
} catch {
|
|
14618
14863
|
}
|
|
14619
14864
|
}
|
|
@@ -14642,7 +14887,7 @@ ${rows}
|
|
|
14642
14887
|
if (depth < 8 && entry.name !== "node_modules") walk(full, depth + 1);
|
|
14643
14888
|
} else if (entry.isFile()) {
|
|
14644
14889
|
try {
|
|
14645
|
-
bytes +=
|
|
14890
|
+
bytes += statSync13(full).size;
|
|
14646
14891
|
} catch {
|
|
14647
14892
|
}
|
|
14648
14893
|
}
|
|
@@ -14685,41 +14930,69 @@ ${rows}
|
|
|
14685
14930
|
/** A folder a Library call names (absolute or `~/...`), resolved; it must exist and be a folder. */
|
|
14686
14931
|
folderArg(value) {
|
|
14687
14932
|
const given = typeof value === "string" ? value.trim() : "";
|
|
14688
|
-
if (!given || !
|
|
14689
|
-
const root =
|
|
14933
|
+
if (!given || !isAbsolute7(given) && !given.startsWith("~")) throw new OpenArtifactError("invalid_argument", "folder: an absolute path (or ~/...).");
|
|
14934
|
+
const root = resolve17(expandHome(given));
|
|
14690
14935
|
let dir = false;
|
|
14691
14936
|
try {
|
|
14692
|
-
dir =
|
|
14937
|
+
dir = statSync13(root).isDirectory();
|
|
14693
14938
|
} catch {
|
|
14694
14939
|
}
|
|
14695
14940
|
if (!dir) throw new OpenArtifactError("not_found", `No folder ${root}.`);
|
|
14696
14941
|
return root;
|
|
14697
14942
|
}
|
|
14698
14943
|
async duplicate(record, name) {
|
|
14944
|
+
const source = this.store.authorizedRoot(record);
|
|
14945
|
+
const workspace = record.workspaceDirectory;
|
|
14946
|
+
const inherited = {
|
|
14947
|
+
type: record.type,
|
|
14948
|
+
typeSource: record.typeSource,
|
|
14949
|
+
typeRelease: record.typeRelease,
|
|
14950
|
+
typeUid: record.typeUid ?? null,
|
|
14951
|
+
owner: record.owner,
|
|
14952
|
+
...workspace ? { workspaceDirectory: workspace } : {}
|
|
14953
|
+
};
|
|
14699
14954
|
if (record.type === "docs") {
|
|
14700
14955
|
const type = this.typeOf(record);
|
|
14701
14956
|
if (!type) throw new OpenArtifactError("unsupported", "The Docs type is unavailable.");
|
|
14957
|
+
if (workspace) await this.openPage(record);
|
|
14702
14958
|
const copy = await this.servers.call(
|
|
14703
14959
|
type,
|
|
14704
14960
|
"POST",
|
|
14705
14961
|
TYPE_SERVER_ROUTES.actions + "duplicate",
|
|
14706
|
-
{ root:
|
|
14962
|
+
{ root: source, id: record.id, args: { name: name ?? record.title.slice(0, 249) + " (copy)" } },
|
|
14707
14963
|
void 0,
|
|
14708
14964
|
ACTION_CALL_MS
|
|
14709
14965
|
);
|
|
14710
|
-
return this.store.create({ root: copy.root, title: copy.name
|
|
14966
|
+
return this.store.create({ ...inherited, root: copy.root, title: copy.name });
|
|
14711
14967
|
}
|
|
14712
|
-
const
|
|
14713
|
-
const
|
|
14714
|
-
|
|
14715
|
-
|
|
14968
|
+
const directory = workspace ? new WorkspaceDirectory(workspace.root, workspace) : void 0;
|
|
14969
|
+
const parent = directory?.root === source ? source : dirname12(source);
|
|
14970
|
+
const base = basename7(source) || "work";
|
|
14971
|
+
const target = (name2) => directory?.resolve(join27(parent, name2), false) ?? join27(parent, name2);
|
|
14972
|
+
let root = target(`${base}-copy`);
|
|
14716
14973
|
const skip = (name2) => name2.startsWith(".") || name2 === "history" || name2 === "exports" || name2 === "node_modules" || name2 === "_agent";
|
|
14717
|
-
|
|
14718
|
-
for (
|
|
14719
|
-
|
|
14720
|
-
|
|
14974
|
+
const children = readdirSync14(source).filter((name2) => !skip(name2));
|
|
14975
|
+
for (let n = 2; ; n++) {
|
|
14976
|
+
try {
|
|
14977
|
+
mkdirSync8(root);
|
|
14978
|
+
break;
|
|
14979
|
+
} catch (error) {
|
|
14980
|
+
if (error.code !== "EEXIST") throw error;
|
|
14981
|
+
root = target(`${base}-copy-${n}`);
|
|
14982
|
+
}
|
|
14983
|
+
}
|
|
14984
|
+
const files2 = directory ? new WorkspaceDirectory(source) : void 0;
|
|
14985
|
+
for (const name2 of children) {
|
|
14986
|
+
cpSync3(join27(source, name2), join27(root, name2), {
|
|
14987
|
+
recursive: true,
|
|
14988
|
+
errorOnExist: false,
|
|
14989
|
+
...files2 ? { dereference: true, filter: (path) => {
|
|
14990
|
+
files2.resolve(path);
|
|
14991
|
+
return true;
|
|
14992
|
+
} } : {}
|
|
14993
|
+
});
|
|
14721
14994
|
}
|
|
14722
|
-
return this.store.create({
|
|
14995
|
+
return this.store.create({ ...inherited, root, title: `Copy of ${record.title}`.slice(0, 200) });
|
|
14723
14996
|
}
|
|
14724
14997
|
thumbnailFile(id) {
|
|
14725
14998
|
return join27(files.thumbnails(), `${id}.jpg`);
|
|
@@ -14751,7 +15024,7 @@ ${rows}
|
|
|
14751
15024
|
openedAt: record.openedAt ?? null,
|
|
14752
15025
|
contentAt: this.contentAt(record),
|
|
14753
15026
|
thumbnail: this.thumbnailOf(record.id),
|
|
14754
|
-
shared: sharedOnLan(record
|
|
15027
|
+
shared: this.sharedOnLan(record),
|
|
14755
15028
|
open: this.pages.has(record.id),
|
|
14756
15029
|
remote: record.remote ? { name: record.remote.name, host: record.remote.host, url: record.remote.url, syncedAt: record.remote.syncedAt } : null,
|
|
14757
15030
|
...releaseView(record, type?.version ?? null)
|
|
@@ -14787,10 +15060,10 @@ ${rows}
|
|
|
14787
15060
|
/** The project types of the folders this computer knows, but `skip` (whose types the answer lists already). */
|
|
14788
15061
|
projectTypes(skip) {
|
|
14789
15062
|
const known = [...this.harnesses.workspaces(), ...this.settings.trustedProjects ?? [], this.settings.homeWorkspace, ...this.typeProjects];
|
|
14790
|
-
const folders = new Set(known.map((d) =>
|
|
15063
|
+
const folders = new Set(known.map((d) => resolve17(d)));
|
|
14791
15064
|
const out2 = [];
|
|
14792
15065
|
for (const dir of folders) {
|
|
14793
|
-
if (skip &&
|
|
15066
|
+
if (skip && resolve17(skip) === dir) continue;
|
|
14794
15067
|
const root = this.types.roots(dir).find((r) => r.scope === "project");
|
|
14795
15068
|
if (!root || !existsSync17(root.root)) continue;
|
|
14796
15069
|
const types3 = this.types.list(dir, { includeShadowed: true }).filter((t) => t.scope === "project");
|
|
@@ -14855,9 +15128,9 @@ ${rows}
|
|
|
14855
15128
|
}
|
|
14856
15129
|
if (name === LIBRARY_ROUTES.typesPreview || name === LIBRARY_ROUTES.import) return this.packageCall(req, res, name);
|
|
14857
15130
|
const body = await readJsonBody(req);
|
|
14858
|
-
const workspace = typeof body.workspace === "string" &&
|
|
15131
|
+
const workspace = typeof body.workspace === "string" && isAbsolute7(body.workspace) ? resolve17(body.workspace) : null;
|
|
14859
15132
|
const project = typeof body.project === "string" && body.project ? body.project : null;
|
|
14860
|
-
if (project !== null && !
|
|
15133
|
+
if (project !== null && !isAbsolute7(project)) throw new OpenArtifactError("invalid_argument", "project: the project folder, as an absolute path.");
|
|
14861
15134
|
const o = { settings: this.settings, registry: this.types, workspace: workspace ?? (body.scope === "project" ? project : null) ?? this.settings.homeWorkspace };
|
|
14862
15135
|
const changed = () => {
|
|
14863
15136
|
this.settings = loadSettings(this.preset);
|
|
@@ -14868,24 +15141,24 @@ ${rows}
|
|
|
14868
15141
|
case R.typesNew: {
|
|
14869
15142
|
const made = newType({ id: body.id, scope: body.scope, template: body.template, name: body.name, project }, o);
|
|
14870
15143
|
this.log(`audit: made the type ${made.id} (${made.scope}, ${String(body.template ?? "page")}) at ${made.dir}, asked by ${this.askedBy(req, name)}`);
|
|
14871
|
-
if (made.scope === "project" && project) this.typeProjects.add(
|
|
15144
|
+
if (made.scope === "project" && project) this.typeProjects.add(resolve17(project));
|
|
14872
15145
|
changed();
|
|
14873
15146
|
return sendJson(res, 200, made);
|
|
14874
15147
|
}
|
|
14875
15148
|
case R.typesFrom: {
|
|
14876
15149
|
if (body.path !== void 0) {
|
|
14877
15150
|
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 });
|
|
14878
|
-
if (typeof body.path !== "string" || !
|
|
15151
|
+
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.");
|
|
14879
15152
|
const made2 = typeFromSaved(body.path, { id: body.id, scope: body.scope, name: body.name, project }, o);
|
|
14880
15153
|
this.log(`audit: made the type ${made2.id} from the saved page ${made2.source} at ${made2.dir}, asked by ${this.askedBy(req, name)}`);
|
|
14881
|
-
if (made2.scope === "project" && project) this.typeProjects.add(
|
|
15154
|
+
if (made2.scope === "project" && project) this.typeProjects.add(resolve17(project));
|
|
14882
15155
|
changed();
|
|
14883
15156
|
return sendJson(res, 200, made2);
|
|
14884
15157
|
}
|
|
14885
15158
|
const record = this.store.require(body.artifact);
|
|
14886
15159
|
const made = typeFromPage(record, this.typeOf(record), { id: body.id, scope: body.scope, name: body.name, project }, o);
|
|
14887
15160
|
this.log(`audit: made the type ${made.id} from ${record.id} at ${made.dir}, asked by ${this.askedBy(req, name)}`);
|
|
14888
|
-
if (made.scope === "project" && project) this.typeProjects.add(
|
|
15161
|
+
if (made.scope === "project" && project) this.typeProjects.add(resolve17(project));
|
|
14889
15162
|
changed();
|
|
14890
15163
|
return sendJson(res, 200, made);
|
|
14891
15164
|
}
|
|
@@ -15002,7 +15275,7 @@ ${rows}
|
|
|
15002
15275
|
bytes = raw;
|
|
15003
15276
|
body = { name: url.searchParams.get("name") ?? void 0, as: url.searchParams.get("as") ?? void 0, folder: url.searchParams.get("folder") ?? void 0 };
|
|
15004
15277
|
}
|
|
15005
|
-
const label = typeof body.name === "string" && body.name ? (json ?
|
|
15278
|
+
const label = typeof body.name === "string" && body.name ? (json ? basename7(body.name) : body.name).slice(0, 1e3) : preview ? "the package" : "the archive";
|
|
15006
15279
|
if (preview) {
|
|
15007
15280
|
const as = typeof body.as === "string" && body.as ? body.as : null;
|
|
15008
15281
|
if (!bytes) {
|
|
@@ -15017,8 +15290,8 @@ ${rows}
|
|
|
15017
15290
|
const workspace = this.settings.homeWorkspace ?? null;
|
|
15018
15291
|
const read = await readArtifactArchive(bytes, label, { registry: this.types, workspace });
|
|
15019
15292
|
const folder = typeof body.folder === "string" && body.folder ? body.folder : void 0;
|
|
15020
|
-
if (folder && !
|
|
15021
|
-
const base = folder ?
|
|
15293
|
+
if (folder && !isAbsolute7(folder)) throw new OpenArtifactError("invalid_argument", "folder: where to put it, as an absolute path.");
|
|
15294
|
+
const base = folder ? resolve17(folder) : this.tools.resolveFolder(void 0, { harness: "home", session: null, workspace }, read.top);
|
|
15022
15295
|
let dest = base;
|
|
15023
15296
|
if (!folder) for (let n = 2; existsSync17(dest); n++) dest = `${base}-${n}`;
|
|
15024
15297
|
const unpacked = await unpackArtifactArchive(bytes, read, dest);
|
|
@@ -15035,6 +15308,7 @@ ${rows}
|
|
|
15035
15308
|
* absolute address on the page's own origin.
|
|
15036
15309
|
*/
|
|
15037
15310
|
async openPage(record, context = {}) {
|
|
15311
|
+
record = { ...record, root: this.store.authorizedRoot(record) };
|
|
15038
15312
|
const type = this.typeOf(record);
|
|
15039
15313
|
if (!type) throw new OpenArtifactError("type_missing", `The type ${record.type} is not installed.`);
|
|
15040
15314
|
const mismatch = typeMismatch(record, type);
|
|
@@ -15080,7 +15354,7 @@ ${rows}
|
|
|
15080
15354
|
let timer;
|
|
15081
15355
|
try {
|
|
15082
15356
|
const watcher = watch3(record.root, { recursive: true, persistent: false }, (_event, name) => {
|
|
15083
|
-
const rel = String(name ?? "").split(
|
|
15357
|
+
const rel = String(name ?? "").split(sep11).join("/");
|
|
15084
15358
|
if (!rel || rel.split("/").some((part) => part.startsWith("."))) return;
|
|
15085
15359
|
changed.add(rel);
|
|
15086
15360
|
clearTimeout(timer);
|
|
@@ -15129,14 +15403,18 @@ ${rows}
|
|
|
15129
15403
|
if (rel.includes("\0")) return this.notFound(req, res);
|
|
15130
15404
|
let base = type.dir;
|
|
15131
15405
|
if (rel === "/_root" || rel.startsWith("/_root/")) {
|
|
15132
|
-
|
|
15406
|
+
try {
|
|
15407
|
+
base = this.store.authorizedRoot(record);
|
|
15408
|
+
} catch {
|
|
15409
|
+
return this.notFound(req, res);
|
|
15410
|
+
}
|
|
15133
15411
|
rel = rel.slice("/_root".length);
|
|
15134
15412
|
} else if (rel === "/" || rel === "") rel = `/${type.entry.file}`;
|
|
15135
15413
|
const parts = rel.split("/").filter(Boolean);
|
|
15136
15414
|
if (parts.some((part) => part.startsWith("."))) return this.notFound(req, res);
|
|
15137
15415
|
let file;
|
|
15138
15416
|
try {
|
|
15139
|
-
file = parts.length ? inside(
|
|
15417
|
+
file = parts.length ? inside(resolve17(base), parts.join("/")) : resolve17(base);
|
|
15140
15418
|
} catch {
|
|
15141
15419
|
return this.notFound(req, res);
|
|
15142
15420
|
}
|
|
@@ -15154,7 +15432,7 @@ ${rows}
|
|
|
15154
15432
|
async sendArchive(req, res, record) {
|
|
15155
15433
|
if (this.typeOf(record)?.entry?.kind === "static") {
|
|
15156
15434
|
res.setHeader("X-Content-Type-Options", "nosniff");
|
|
15157
|
-
return sendArchive(req, res, record
|
|
15435
|
+
return sendArchive(req, res, this.store.authorizedRoot(record));
|
|
15158
15436
|
}
|
|
15159
15437
|
const head = req.method === "HEAD";
|
|
15160
15438
|
const answer = await this.archiveAnswer(record, head ? "HEAD" : "GET");
|
|
@@ -15192,7 +15470,7 @@ ${rows}
|
|
|
15192
15470
|
}
|
|
15193
15471
|
/** The artifact's folder as a zip, made by its type server with the export's rules (what Link publishes). */
|
|
15194
15472
|
async archiveBytes(record) {
|
|
15195
|
-
if (this.typeOf(record)?.entry?.kind === "static") return zipBytes(await archiveEntries(record
|
|
15473
|
+
if (this.typeOf(record)?.entry?.kind === "static") return zipBytes(await archiveEntries(this.store.authorizedRoot(record)));
|
|
15196
15474
|
const answer = await this.archiveAnswer(record, "GET", 3e5);
|
|
15197
15475
|
const type = this.typeOf(record);
|
|
15198
15476
|
if (type && typeLocation(type).remote) return remoteArchiveBytes(type, answer);
|
|
@@ -15219,7 +15497,7 @@ ${rows}
|
|
|
15219
15497
|
typeToken(typeId) {
|
|
15220
15498
|
let token = this.typeTokens.get(typeId);
|
|
15221
15499
|
if (!token) {
|
|
15222
|
-
token = `oat_${
|
|
15500
|
+
token = `oat_${randomBytes10(24).toString("base64url")}`;
|
|
15223
15501
|
this.typeTokens.set(typeId, token);
|
|
15224
15502
|
this.tokenTypes.set(token, typeId);
|
|
15225
15503
|
}
|
|
@@ -15517,7 +15795,7 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
|
|
|
15517
15795
|
if (get2) {
|
|
15518
15796
|
let image2;
|
|
15519
15797
|
try {
|
|
15520
|
-
image2 =
|
|
15798
|
+
image2 = readFileSync19(this.thumbnailFile(record.id));
|
|
15521
15799
|
} catch {
|
|
15522
15800
|
throw new OpenArtifactError("not_found", "No thumbnail yet.");
|
|
15523
15801
|
}
|
|
@@ -15532,7 +15810,7 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
|
|
|
15532
15810
|
if (image.length < 4 || image[0] !== 255 || image[1] !== 216) throw new OpenArtifactError("invalid_argument", "The body is not a JPEG.");
|
|
15533
15811
|
const v = url.searchParams.get("v") || this.contentAt(record);
|
|
15534
15812
|
ensureDir(files.thumbnails());
|
|
15535
|
-
|
|
15813
|
+
writeFileSync10(this.thumbnailFile(record.id), image);
|
|
15536
15814
|
writeJson(join27(files.thumbnails(), `${record.id}.json`), { v, at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
15537
15815
|
return sendJson(res, 200, { thumbnail: v });
|
|
15538
15816
|
}
|
|
@@ -15560,7 +15838,7 @@ data: ${JSON.stringify({ type: "presence", id, ...this.presenceOf(record) })}
|
|
|
15560
15838
|
const typeId = String(body.type ?? "").replace(/^open-artifact:\/\/type\//, "");
|
|
15561
15839
|
if (!typeId) throw new OpenArtifactError("invalid_argument", "type: the type id (or open-artifact://type/<id>) to create from.");
|
|
15562
15840
|
const folder = typeof body.folder === "string" && body.folder.trim() ? body.folder.trim() : void 0;
|
|
15563
|
-
if (folder && !
|
|
15841
|
+
if (folder && !isAbsolute7(folder) && !folder.startsWith("~")) throw new OpenArtifactError("invalid_argument", "folder: an absolute path (or ~/...).");
|
|
15564
15842
|
const caller2 = { harness: HOME_HARNESS, session: null, workspace: this.settings.homeWorkspace };
|
|
15565
15843
|
const blank = body.blank === true;
|
|
15566
15844
|
const made = await this.tools.call(
|
|
@@ -15637,7 +15915,7 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
|
|
|
15637
15915
|
}
|
|
15638
15916
|
const other = this.store.byRoot(root);
|
|
15639
15917
|
if (other && other.id !== record.id) throw new OpenArtifactError("conflict", `${root} is already the folder of ${other.id}.`);
|
|
15640
|
-
if (
|
|
15918
|
+
if (resolve17(record.root) === root) return sendJson(res, 200, this.artifactView(record));
|
|
15641
15919
|
this.closePage(record);
|
|
15642
15920
|
this.shellOpens.delete(record.id);
|
|
15643
15921
|
this.contentStamps.delete(record.root);
|
|
@@ -15767,7 +16045,7 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
|
|
|
15767
16045
|
}
|
|
15768
16046
|
case "artifacts.publish": {
|
|
15769
16047
|
const body = await readJsonBody(req);
|
|
15770
|
-
const folder = typeof body.folder === "string" && body.folder ?
|
|
16048
|
+
const folder = typeof body.folder === "string" && body.folder ? resolve17(expandHome(body.folder)) : null;
|
|
15771
16049
|
let record = folder ? this.store.byRoot(folder) : this.store.require(body.id ?? body.url);
|
|
15772
16050
|
let adopted = false;
|
|
15773
16051
|
if (!record && folder && body.adopt === true) {
|
|
@@ -15923,8 +16201,8 @@ ${takeOverPrompt(record, view2.typeTitle)}` : takeOverPrompt(record, view2.typeT
|
|
|
15923
16201
|
// packages/daemon/src/bin/open-artifact.ts
|
|
15924
16202
|
init_src();
|
|
15925
16203
|
import { execFileSync } from "node:child_process";
|
|
15926
|
-
import { existsSync as existsSync18, readFileSync as
|
|
15927
|
-
import { resolve as resolvePath, sep as
|
|
16204
|
+
import { existsSync as existsSync18, readFileSync as readFileSync20, realpathSync as realpathSync5 } from "node:fs";
|
|
16205
|
+
import { resolve as resolvePath, sep as sep12 } from "node:path";
|
|
15928
16206
|
import { createInterface as createInterface2 } from "node:readline";
|
|
15929
16207
|
|
|
15930
16208
|
// packages/daemon/src/agent-session.ts
|
|
@@ -16246,8 +16524,8 @@ init_package();
|
|
|
16246
16524
|
init_harness_skill();
|
|
16247
16525
|
init_settings2();
|
|
16248
16526
|
init_types();
|
|
16249
|
-
import { existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as
|
|
16250
|
-
import { join as
|
|
16527
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync4, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "node:fs";
|
|
16528
|
+
import { join as join15, resolve as resolve13 } from "node:path";
|
|
16251
16529
|
var VERSION2 = package_default.version ?? "0.0.0";
|
|
16252
16530
|
function renderSkillFor(options) {
|
|
16253
16531
|
const form = options.form ?? "full";
|
|
@@ -16255,7 +16533,7 @@ function renderSkillFor(options) {
|
|
|
16255
16533
|
const registry = new TypeRegistry(loadSettings);
|
|
16256
16534
|
try {
|
|
16257
16535
|
const harness = options.harness || "cli";
|
|
16258
|
-
const workspace =
|
|
16536
|
+
const workspace = resolve13(options.workspace ?? process.cwd());
|
|
16259
16537
|
const params = { form, ...options.command ? { command: options.command } : {} };
|
|
16260
16538
|
return skillFor(params, {
|
|
16261
16539
|
harness,
|
|
@@ -16273,17 +16551,17 @@ function installSkillFile(options) {
|
|
|
16273
16551
|
throw new OpenArtifactError("invalid_argument", "--command <name>: lowercase letters, digits, - and _, without the slash.");
|
|
16274
16552
|
}
|
|
16275
16553
|
const skill = renderSkillFor(options);
|
|
16276
|
-
const folder =
|
|
16277
|
-
const file =
|
|
16554
|
+
const folder = join15(resolve13(options.dir), skill.name);
|
|
16555
|
+
const file = join15(folder, "SKILL.md");
|
|
16278
16556
|
if (existsSync9(file)) {
|
|
16279
|
-
const text3 =
|
|
16557
|
+
const text3 = readFileSync9(file, "utf8");
|
|
16280
16558
|
if (!options.force && !skillFileKey(text3, SKILL_GENERATED_BY)) {
|
|
16281
16559
|
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." });
|
|
16282
16560
|
}
|
|
16283
16561
|
if (skillFileKey(text3, "etag") === skill.etag) return { file, written: false, etag: skill.etag, reason: "unchanged" };
|
|
16284
16562
|
}
|
|
16285
16563
|
mkdirSync4(folder, { recursive: true });
|
|
16286
|
-
|
|
16564
|
+
writeFileSync5(file, renderedSkillFile(skill));
|
|
16287
16565
|
return { file, written: true, etag: skill.etag };
|
|
16288
16566
|
}
|
|
16289
16567
|
function skillCommand(sub, flag2, has2) {
|
|
@@ -16412,8 +16690,8 @@ function doctorText(report) {
|
|
|
16412
16690
|
// packages/daemon/src/doctor-checks.ts
|
|
16413
16691
|
init_src2();
|
|
16414
16692
|
init_src();
|
|
16415
|
-
import { accessSync, constants as constants2, existsSync as existsSync11, readFileSync as
|
|
16416
|
-
import { join as
|
|
16693
|
+
import { accessSync, constants as constants2, existsSync as existsSync11, readFileSync as readFileSync11, statSync as statSync8 } from "node:fs";
|
|
16694
|
+
import { join as join19 } from "node:path";
|
|
16417
16695
|
|
|
16418
16696
|
// packages/daemon/src/doctor-conformance.ts
|
|
16419
16697
|
init_src2();
|
|
@@ -16422,7 +16700,7 @@ init_paths();
|
|
|
16422
16700
|
init_package();
|
|
16423
16701
|
import { mkdtempSync, rmSync as rmSync5 } from "node:fs";
|
|
16424
16702
|
import { tmpdir } from "node:os";
|
|
16425
|
-
import { join as
|
|
16703
|
+
import { join as join17 } from "node:path";
|
|
16426
16704
|
var CONFORMANCE_TITLE = "open-artifact doctor test";
|
|
16427
16705
|
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.";
|
|
16428
16706
|
var TOOLS2 = ["Artifact", "ArtifactData", "ArtifactComments"];
|
|
@@ -16588,8 +16866,8 @@ var toolsStep = {
|
|
|
16588
16866
|
const create = run.quickstart.create;
|
|
16589
16867
|
if (!create?.type_url) throw new Error(`quickstart answered no create call for ${type.id}`);
|
|
16590
16868
|
run.typeUrl = String(create.type_url);
|
|
16591
|
-
run.folder = mkdtempSync(
|
|
16592
|
-
const made = await call(run, context, "Artifact", { ...create, title: CONFORMANCE_TITLE, folder:
|
|
16869
|
+
run.folder = mkdtempSync(join17(tmpdir(), "open-artifact-doctor-"));
|
|
16870
|
+
const made = await call(run, context, "Artifact", { ...create, title: CONFORMANCE_TITLE, folder: join17(run.folder, "artifact"), open: "never" });
|
|
16593
16871
|
const url = String(made.url ?? "");
|
|
16594
16872
|
run.artifact = { url, id: url.split("/").pop() ?? "" };
|
|
16595
16873
|
const detail = await api(run.state, "artifact", void 0, { query: { id: run.artifact.id } });
|
|
@@ -16702,7 +16980,7 @@ var rulesStep = {
|
|
|
16702
16980
|
run.probe = `doctor-probe-${Math.random().toString(36).slice(2, 10)}`;
|
|
16703
16981
|
try {
|
|
16704
16982
|
await run.client.attach({ session: run.probe, ...run.workspace ? { workspace: run.workspace } : {}, role: refused.role });
|
|
16705
|
-
const args = refused.need === "create" ? { action: "publish", type_url: run.typeUrl, title: `${CONFORMANCE_TITLE} (probe)`, folder:
|
|
16983
|
+
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 };
|
|
16706
16984
|
try {
|
|
16707
16985
|
const made = await call(run, context, "Artifact", args, run.probe);
|
|
16708
16986
|
if (typeof made.url === "string" && refused.need === "create") run.extra.push(made.url);
|
|
@@ -16934,7 +17212,7 @@ var daemon = {
|
|
|
16934
17212
|
const found2 = [{ status: "ok", message: `Daemon ${state.version ?? "?"} running at ${state.url} (pid ${state.pid})` }];
|
|
16935
17213
|
if (process.platform !== "win32") {
|
|
16936
17214
|
try {
|
|
16937
|
-
const mode2 =
|
|
17215
|
+
const mode2 = statSync8(files.daemon()).mode & 511;
|
|
16938
17216
|
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()}` }];
|
|
16939
17217
|
} catch {
|
|
16940
17218
|
}
|
|
@@ -17040,10 +17318,10 @@ var settings = {
|
|
|
17040
17318
|
id: "settings",
|
|
17041
17319
|
title: "Settings",
|
|
17042
17320
|
run: ({ home: home2 }) => {
|
|
17043
|
-
const file =
|
|
17321
|
+
const file = join19(home2, "settings.json");
|
|
17044
17322
|
if (!existsSync11(file)) return { status: "ok", message: "Settings: the defaults (no settings.json)" };
|
|
17045
17323
|
try {
|
|
17046
|
-
JSON.parse(
|
|
17324
|
+
JSON.parse(readFileSync11(file, "utf8"));
|
|
17047
17325
|
return { status: "ok", message: `Settings: ${file}` };
|
|
17048
17326
|
} catch (error) {
|
|
17049
17327
|
return { status: "fail", message: `settings.json is not valid JSON (${error.message})`, fix: `Fix or remove ${file}; until then the defaults apply.` };
|
|
@@ -17069,9 +17347,9 @@ async function runStdioBridge(options) {
|
|
|
17069
17347
|
};
|
|
17070
17348
|
const waiting = /* @__PURE__ */ new Map();
|
|
17071
17349
|
let next = 1;
|
|
17072
|
-
const callHost = (method, params) => new Promise((
|
|
17350
|
+
const callHost = (method, params) => new Promise((resolve18, reject) => {
|
|
17073
17351
|
const id = `d${next++}`;
|
|
17074
|
-
waiting.set(id, { resolve:
|
|
17352
|
+
waiting.set(id, { resolve: resolve18, reject });
|
|
17075
17353
|
write({ id, method, params });
|
|
17076
17354
|
});
|
|
17077
17355
|
let client = null;
|
|
@@ -17169,7 +17447,7 @@ async function runStdioBridge(options) {
|
|
|
17169
17447
|
);
|
|
17170
17448
|
};
|
|
17171
17449
|
const lines = createInterface({ input: options.input, crlfDelay: Infinity });
|
|
17172
|
-
await new Promise((
|
|
17450
|
+
await new Promise((resolve18) => {
|
|
17173
17451
|
lines.on("line", (line) => {
|
|
17174
17452
|
if (Buffer.byteLength(line) > MAX_LINE2) {
|
|
17175
17453
|
log("stdio: a line over 64 MiB; ending");
|
|
@@ -17178,7 +17456,7 @@ async function runStdioBridge(options) {
|
|
|
17178
17456
|
}
|
|
17179
17457
|
onLine(line);
|
|
17180
17458
|
});
|
|
17181
|
-
lines.on("close",
|
|
17459
|
+
lines.on("close", resolve18);
|
|
17182
17460
|
});
|
|
17183
17461
|
for (const pending of waiting.values()) pending.reject(new OpenArtifactError("disconnected", "The host closed stdin."));
|
|
17184
17462
|
waiting.clear();
|
|
@@ -17273,7 +17551,7 @@ function caller() {
|
|
|
17273
17551
|
function ownWorkspace() {
|
|
17274
17552
|
const real = (dir) => {
|
|
17275
17553
|
try {
|
|
17276
|
-
return
|
|
17554
|
+
return realpathSync5(dir);
|
|
17277
17555
|
} catch {
|
|
17278
17556
|
return resolvePath(dir);
|
|
17279
17557
|
}
|
|
@@ -17283,7 +17561,7 @@ function ownWorkspace() {
|
|
|
17283
17561
|
const plugins = [env.OPEN_ARTIFACT_PLUGIN_DIR, env.PLUGIN_ROOT, env.CLAUDE_PLUGIN_ROOT, env.CURSOR_PLUGIN_ROOT].filter((dir) => !!dir);
|
|
17284
17562
|
return plugins.some((dir) => {
|
|
17285
17563
|
const root = real(dir);
|
|
17286
|
-
return cwd === root || cwd.startsWith(root +
|
|
17564
|
+
return cwd === root || cwd.startsWith(root + sep12);
|
|
17287
17565
|
}) ? null : process.cwd();
|
|
17288
17566
|
}
|
|
17289
17567
|
function ancestors(start = process.ppid, depth = 4) {
|
|
@@ -17479,7 +17757,7 @@ async function hook(event) {
|
|
|
17479
17757
|
if (!event) die("hook <event>");
|
|
17480
17758
|
let input = {};
|
|
17481
17759
|
try {
|
|
17482
|
-
const text3 =
|
|
17760
|
+
const text3 = readFileSync20(0, "utf8");
|
|
17483
17761
|
input = text3.trim() ? JSON.parse(text3) : {};
|
|
17484
17762
|
} catch {
|
|
17485
17763
|
input = {};
|
|
@@ -17551,7 +17829,10 @@ async function daemon2(sub) {
|
|
|
17551
17829
|
exit();
|
|
17552
17830
|
};
|
|
17553
17831
|
for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(signal, stop);
|
|
17554
|
-
const started = await startDaemon2(
|
|
17832
|
+
const started = await startDaemon2({
|
|
17833
|
+
...port !== void 0 ? { port: Number(port) } : {},
|
|
17834
|
+
...process.env.OPEN_ARTIFACT_WORKSPACE_FOLDERS_ONLY === "1" ? { workspaceFoldersOnly: true } : {}
|
|
17835
|
+
});
|
|
17555
17836
|
running = started;
|
|
17556
17837
|
started.on("exit", exit);
|
|
17557
17838
|
if (asked) return stop(asked);
|
|
@@ -17629,7 +17910,7 @@ async function importCommand(file) {
|
|
|
17629
17910
|
let bytes;
|
|
17630
17911
|
const path = resolvePath(file);
|
|
17631
17912
|
try {
|
|
17632
|
-
bytes =
|
|
17913
|
+
bytes = readFileSync20(path);
|
|
17633
17914
|
} catch (error) {
|
|
17634
17915
|
die(`import: cannot read ${path} (${error.message})`);
|
|
17635
17916
|
}
|
|
@@ -17935,7 +18216,7 @@ function harnessCommand(sub) {
|
|
|
17935
18216
|
personOnly("harness-add", `open-artifact harness add ${resolvePath(file)}`);
|
|
17936
18217
|
let raw;
|
|
17937
18218
|
try {
|
|
17938
|
-
raw = JSON.parse(
|
|
18219
|
+
raw = JSON.parse(readFileSync20(resolvePath(file), "utf8"));
|
|
17939
18220
|
} catch (error) {
|
|
17940
18221
|
die(`harness add: cannot read ${file} as JSON (${error.message})`);
|
|
17941
18222
|
}
|