Documents in a sandbox

A sandbox can give an assistant the workspace's collaborative documents, the ones people write together on the Documents page. The assistant reads them as they are now and edits them through the document's live editing session: whoever has the document open sees the assistant's name and caret and the text arriving, and every edit is saved as a revision that can be restored.

There are two ways to hand them over, and a sandbox can use either or both:

How the assistant works Declared with
The doc command doc cat <uid>, ... \| doc append <uid>, doc replace … ISandbox.Editing
A documents folder cat, grep, sed -i, > on files, one file per document SandboxMount.EditingDocuments

Both act as the person chatting, and only as them. A document they cannot open is not there; one they may read but not change is read-only to the assistant.

The doc command

Return a SandboxEditingAccess from ISandbox.Editing. It decides which documents the command reaches and whether it may change or create any.

public SandboxEditingAccess Editing => SandboxEditingAccess.ForCategories(ReportsCategory);
Factory or method Reach
SandboxEditingAccess.Everything() Every document the person can open, and new ones.
SandboxEditingAccess.ForDocuments(uids…) Only these documents.
SandboxEditingAccess.ForCategories(uids…) Only the documents filed in these categories or the categories under them.
.ReadOnly() Reads and history only.
.AllowCreate() A narrowed reach that may also create documents.
.WithoutTyping() Edits land at once instead of a few words at a time.

The command's subcommands are doc list, doc cat <uid>, … | doc write <uid>, … | doc append <uid>, doc replace <uid> <find> <replace> [--all], doc history <uid>, doc diff <uid> [from] [to] and … | doc create <name>.

A documents folder

SandboxMount.EditingDocuments mounts the documents you name as files. It suits an assistant that works with the shell's own tools better than with a command: it can grep across a set of documents, edit one with sed -i, or write a new version with cat > file.

public SandboxMount[] Mounts => new[]
{
    SandboxMount.EditingDocuments("/documents", "the team's reports; writing a file edits the document live",
        scope => Task.FromResult(scope.Editing.ListDocuments(ReportsCategory)
            .Select(d => SandboxEditingFile.Of(Slug(d.Name) + ".md", d.UID)))),
    SandboxMount.Scratch("/work", "scratch space"),
};

The listing runs before every script, as the person running it. Each entry is a SandboxEditingFile: a path in the folder (slashes make subfolders) and the UID of the document.

How the folder behaves:

  • Reading a file reads the document as it is now, other people's edits included.
  • Writing a file edits the document while the script is still running. The new text replaces the old with the smallest change that gets there, so what someone else is typing elsewhere in the document is kept. Edits land in the order the script made them, and the script's result waits for the last one.
  • Typing. By default an edit arrives a few words at a time, so a person watching sees it typed. Pass typing: false to have it land at once.
  • Read-only documents. A document the person may read but not change is read-only: a write fails with Permission denied.
  • Nothing is created or deleted. Writing a path the listing did not name fails, and so does rm.
  • Failures are reported. An edit that could not be made is written to the script's standard error, and the script exits with a non-zero code.
Writes in this folder change the workspace

Everywhere else in a sandbox, a write stays in the session and the workspace is untouched; a change to the workspace is a command named after what it does. A documents folder, like the conversation's /artifacts, is an exception: a write edits a real document. That is safe for collaborative documents because every write is a revision someone can restore and it is made within the person's own edit rights. For records the application owns, keep to a command that proposes a change for the user to apply.

The EditingDocuments mount kind was added after Curiosity Studio 26.11.74040. A tool that uses it on an earlier workspace does not compile.

  • Artifacts: the conversation's /artifacts folder and publish.
  • Make artifacts available: declaring a custom AI tool sandbox.
  • Skills: teaching an assistant when to change a document and when only to answer.