@mulmoclaude/core 5.9.0 → 5.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/helps/attachments.md +33 -0
- package/assets/helps/image-references.md +12 -0
- package/assets/helps/index.md +3 -0
- package/assets/helps/scheduling.md +24 -0
- package/dist/prompt-files/index.cjs +209 -0
- package/dist/prompt-files/index.cjs.map +1 -0
- package/dist/prompt-files/index.d.ts +2 -0
- package/dist/prompt-files/index.js +199 -0
- package/dist/prompt-files/index.js.map +1 -0
- package/dist/prompt-files/split.d.ts +30 -0
- package/dist/prompt-files/sync.d.ts +24 -0
- package/package.json +7 -1
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Attached files
|
|
2
|
+
|
|
3
|
+
How to read the `[Attached file: …]` markers on a user message. The system prompt carries the rules; this page has the full detail.
|
|
4
|
+
|
|
5
|
+
When a user message carries one or more lines of the form
|
|
6
|
+
|
|
7
|
+
`[Attached file: <workspace-relative-path>]`
|
|
8
|
+
|
|
9
|
+
the user has attached / pasted / dropped a file (or selected one in the UI) for this turn. **Each line is one file** — when the user attaches multiple files in the same turn, you will see multiple consecutive marker lines, in declaration order. They usually sit before the user's actual message text, but on a slash-command turn they follow it (so the leading `/` stays at the very start for command resolution). Every path always points at a real workspace file:
|
|
10
|
+
|
|
11
|
+
- `data/attachments/YYYY/MM/<id>.<ext>` — paste/drop/file-picker uploads. The extension reflects the actual format (`.png`, `.pdf`, `.docx`, `.xlsx`, `.txt`, etc.). PPTX uploads are converted server-side and the path you receive is the resulting `.pdf`; the original `.pptx` lives next to it under the same `<id>` if you ever need to inspect it.
|
|
12
|
+
- `artifacts/images/YYYY/MM/<id>.png` — a generated / canvas / edited image the user selected from the sidebar.
|
|
13
|
+
|
|
14
|
+
Where possible, each file's bytes are also delivered to you as a vision / document content block on the same turn, so you can look at it directly without a tool round-trip. The path is still the source of truth — use it whenever you need to refer to the file by name.
|
|
15
|
+
|
|
16
|
+
Treat the markers as the source of truth for **which** files the user means when they say "this", "edit this", "summarise this doc", "turn this into …", "combine these", etc. If you call a tool that takes a workspace path (e.g. `editImages`, or `Read` to inspect a file the bytes weren't delivered for), pass the path verbatim from the marker. Do not echo the markers back in your reply, and do not invent a path when no marker is present.
|
|
17
|
+
|
|
18
|
+
When the user wants to transform existing images, call `editImages` with `imagePaths` set to an array of one or more workspace paths (single image: a one-element array). Pull the paths from the `[Attached file: …]` markers, from earlier tool results in this conversation, or from explicit paths the user mentions in plain text. When several markers are present and the request reads as a multi-image instruction ("combine these", "merge", "use both", etc.), include every relevant path in the array, in the order they appeared. `editImages` is fully stateless — it has no concept of a "currently selected" image, so the array is the only signal of which images to edit.
|
|
19
|
+
|
|
20
|
+
## Original filename
|
|
21
|
+
|
|
22
|
+
A marker may also carry the name the file had on the user's machine:
|
|
23
|
+
|
|
24
|
+
`[Attached file: data/attachments/2026/07/b458a5d0.csv (original name: 商品カタログ_v2.csv)]`
|
|
25
|
+
|
|
26
|
+
The stored name is a collision-proof id, so this is the only way you learn what the user actually calls the file. Use it when you **write** something back: "save this as a spreadsheet" should produce `商品カタログ_v2.xlsx`, not `b458a5d0.xlsx`. It is also the name to use when you mention the file in your reply — say the original name, not the id.
|
|
27
|
+
|
|
28
|
+
Two rules:
|
|
29
|
+
|
|
30
|
+
- **Never read or write the original name as a path.** It names the file, it does not locate it. Every filesystem operation goes through the `data/attachments/...` path in the marker.
|
|
31
|
+
- **When the extensions disagree, the path wins for content.** A PPTX upload arrives as `<id>.pdf` with `(original name: deck.pptx)` — the bytes really are a PDF. The original name still tells you what the user handed over, which is what they will call it.
|
|
32
|
+
|
|
33
|
+
Not every marker has one. A file the user selected in the sidebar, or one arriving from a bridge that does not send a name, appears as a bare `[Attached file: <path>]` — then the path is all you have, and asking the user what to call an output is reasonable.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Image references in markdown / HTML
|
|
2
|
+
|
|
3
|
+
When you write a `.md` or `.html` file that embeds images, follow this convention so the file renders correctly both in the app and when opened directly from disk:
|
|
4
|
+
|
|
5
|
+
- ALWAYS use a **relative path** that resolves against the SOURCE FILE you are writing (the .md / .html itself). For images saved by `saveImage` (Gemini / canvas / image edit) the file lives at `artifacts/images/YYYY/MM/<id>.png` — write a relative climb from the source file. Example: from `data/wiki/pages/notes.md` use `../../../artifacts/images/2026/04/foo.png`.
|
|
6
|
+
- NEVER use an **absolute path** like `/artifacts/images/foo.png`. The app serves that prefix as a static mount, so it works in-app, but breaks the moment the same file is opened directly from disk via `file://` (where root-relative URLs resolve against the filesystem root, not the workspace).
|
|
7
|
+
- NEVER use a workspace-rooted, no-leading-slash form like `data/wiki/sources/foo.png` or `artifacts/images/foo.png` (without the leading `/`). The browser resolves it against the page URL and 404s.
|
|
8
|
+
- NEVER write `/api/files/raw?path=...` URLs. That is a runtime serving artifact, not a stored convention — it bakes the current server URL into the file and breaks if the route shape changes.
|
|
9
|
+
|
|
10
|
+
This applies to markdown image syntax (``), HTML `<img src="path">`, and any other element that takes a path to an image (`<source>`, `<video poster>`, CSS `url()`).
|
|
11
|
+
|
|
12
|
+
Raw HTML tags work inside `.md` files too — use them when markdown's `![]()` can't express what you need (e.g. `<picture>` + `<source>` for art-direction / responsive images, `<video poster>` for thumbnailed video, inline `<img width>` for size control). Same path rules apply: write a relative climb from the `.md` file to the asset, not an absolute or workspace-rooted path.
|
package/assets/helps/index.md
CHANGED
|
@@ -67,6 +67,9 @@ See [Wiki](config/helps/wiki.md) for details on how it works.
|
|
|
67
67
|
- [Spreadsheet](config/helps/spreadsheet.md) — cell format, formulas, date handling, and format codes for the presentSpreadsheet plugin
|
|
68
68
|
- [presentHtml](config/helps/presenthtml.md) — self-contained HTML rules and the three-`../` relative-path convention used by the presentHtml plugin to keep generated files portable under `file://`
|
|
69
69
|
- [Sandbox](config/helps/sandbox.md) — how the Docker sandbox isolates the agent, what it can access, and how to disable it
|
|
70
|
+
- [Attached files](config/helps/attachments.md) — the `[Attached file: …]` markers on a user message: where each path lives, PPTX arriving as PDF, multi-image `editImages`, and the original-filename rules
|
|
71
|
+
- [Image references](config/helps/image-references.md) — how a `.md` / `.html` file embeds an image so it renders both in the app and from disk: relative paths only, and the forms that break
|
|
72
|
+
- [Task scheduling](config/helps/scheduling.md) — `schedule:` frontmatter syntax (`daily HH:MM` is UTC), recommended intervals, and changing a system task's frequency via the overrides API
|
|
70
73
|
- [Error recovery](config/helps/error-recovery.md) — the lookup the agent reads on tool failures (sandbox gh/git/SSH, Marp PDF, registry import, build/workspace, plugin runtime, a bridge gone quiet), plus the triage for a “broken” report
|
|
71
74
|
- [Bug-report FAQ](config/helps/bug-report-faq.md) — symptoms that turn out to be configuration or by design (voice input, push, chat titles, journal, connector tools, preset skills, custom views); says where to read the live value, never what it is
|
|
72
75
|
- [Telegram Bridge](config/helps/telegram.md) — how to talk to MulmoClaude from the Telegram app: creating a bot, starting the bridge, allowlisting chat IDs, commands, and troubleshooting
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Task scheduling
|
|
2
|
+
|
|
3
|
+
Skills and tasks can be scheduled via SKILL.md frontmatter (`schedule: "daily HH:MM"` or `schedule: "interval Nh"`). `daily HH:MM` is interpreted in **UTC** — e.g. `daily 08:00` fires at 17:00 JST (UTC+9), so convert when the user asks for a local time. When the user asks to schedule something, recommend an appropriate frequency:
|
|
4
|
+
|
|
5
|
+
- News/RSS feeds: `interval 1h` (content changes often)
|
|
6
|
+
- Daily digests or journal: `daily 23:00` (once per day)
|
|
7
|
+
- Wiki cleanup or maintenance: `interval 168h` (weekly)
|
|
8
|
+
- Calendar/contact sync: `interval 4h`
|
|
9
|
+
- Source monitoring: `interval 2h`
|
|
10
|
+
|
|
11
|
+
Suggest a schedule at registration time; let the user confirm or adjust. Prefer `daily HH:MM` for tasks that should run once per day, and `interval Nh` for polling tasks.
|
|
12
|
+
|
|
13
|
+
## Changing system task frequency
|
|
14
|
+
|
|
15
|
+
System tasks (journal, chat-index) have default schedules. Users can override them by editing `config/scheduler/overrides.json`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"system:journal": { "intervalMs": 7200000 },
|
|
20
|
+
"system:chat-index": { "intervalMs": 3600000 }
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
When the user asks to change a system task's frequency, use the WebFetch tool to PUT to `/api/config/scheduler-overrides` with `{ "overrides": { "system:journal": { "intervalMs": <ms> } } }`. This saves the config and applies the change immediately without a server restart.
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_rolldown_runtime = require("../rolldown-runtime-VH7oDXx4.cjs");
|
|
3
|
+
const require_dist = require("../dist-BZ62pKuU.cjs");
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
7
|
+
let node_crypto = require("node:crypto");
|
|
8
|
+
//#region src/prompt-files/split.ts
|
|
9
|
+
/** Replaced in `promptCompact` with the directory the agent reads the files
|
|
10
|
+
* from — a path only the host knows (cwd-relative in MulmoClaude, absolute in
|
|
11
|
+
* MulmoTerminal). */
|
|
12
|
+
var PROMPT_FILES_DIR_PLACEHOLDER = "{{promptFilesDir}}";
|
|
13
|
+
var SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
14
|
+
/** A file name a plugin may declare: relative, `/`-separated, every segment a
|
|
15
|
+
* plain name — no `..`, no absolute path, no backslash, no hidden file. */
|
|
16
|
+
function isSafePromptFileName(name) {
|
|
17
|
+
if (name.length === 0) return false;
|
|
18
|
+
return name.split("/").every((segment) => SAFE_SEGMENT.test(segment));
|
|
19
|
+
}
|
|
20
|
+
/** Where one package's files go, relative to the host's root: the
|
|
21
|
+
* `node_modules` layout (`@scope/name`, or `name`), so two packages can never
|
|
22
|
+
* share a directory. Null for a name that could escape it. */
|
|
23
|
+
function promptFilesSubdir(packageName) {
|
|
24
|
+
const segments = packageName.split("/");
|
|
25
|
+
if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;
|
|
26
|
+
const [scope = "", name = ""] = segments;
|
|
27
|
+
return segments.length === 2 && scope.startsWith("@") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name) ? packageName : null;
|
|
28
|
+
}
|
|
29
|
+
function isStringRecord(value) {
|
|
30
|
+
return require_dist.isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
31
|
+
}
|
|
32
|
+
/** Characters that end a file reference in prose: whitespace and the
|
|
33
|
+
* punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */
|
|
34
|
+
var REFERENCE_TERMINATORS = /* @__PURE__ */ new Set([
|
|
35
|
+
" ",
|
|
36
|
+
" ",
|
|
37
|
+
"\n",
|
|
38
|
+
"\r",
|
|
39
|
+
"`",
|
|
40
|
+
"'",
|
|
41
|
+
"\"",
|
|
42
|
+
")",
|
|
43
|
+
"]",
|
|
44
|
+
">",
|
|
45
|
+
",",
|
|
46
|
+
";",
|
|
47
|
+
":",
|
|
48
|
+
"!",
|
|
49
|
+
"?",
|
|
50
|
+
"。",
|
|
51
|
+
"、",
|
|
52
|
+
")",
|
|
53
|
+
"」"
|
|
54
|
+
]);
|
|
55
|
+
function trimTrailingDots(token) {
|
|
56
|
+
let end = token.length;
|
|
57
|
+
while (end > 0 && token[end - 1] === ".") end -= 1;
|
|
58
|
+
return token.slice(0, end);
|
|
59
|
+
}
|
|
60
|
+
/** The text after one placeholder up to where the reference ends. */
|
|
61
|
+
function referenceToken(afterPlaceholder) {
|
|
62
|
+
const chars = [...afterPlaceholder];
|
|
63
|
+
const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));
|
|
64
|
+
return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(""));
|
|
65
|
+
}
|
|
66
|
+
/** The files the compact text points at (`{{promptFilesDir}}/<name>`),
|
|
67
|
+
* sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the
|
|
68
|
+
* directory itself and contributes nothing. Null when a reference is not a
|
|
69
|
+
* safe file name — the agent would be sent to a path that cannot exist. */
|
|
70
|
+
function referencedPromptFiles(compact) {
|
|
71
|
+
const references = compact.split(PROMPT_FILES_DIR_PLACEHOLDER).slice(1).filter((afterPlaceholder) => afterPlaceholder.startsWith("/")).map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));
|
|
72
|
+
return references.every(isSafePromptFileName) ? references : null;
|
|
73
|
+
}
|
|
74
|
+
/** The split a definition declares, or null when it declares none — or one
|
|
75
|
+
* that would leave the agent pointed at a missing file: no files, an unsafe
|
|
76
|
+
* name, or a reference in the compact text to a file it does not declare.
|
|
77
|
+
* The host then injects the full `prompt`. */
|
|
78
|
+
function readPromptSplit(definition) {
|
|
79
|
+
if (!require_dist.isRecord(definition)) return null;
|
|
80
|
+
const { promptCompact, promptFiles } = definition;
|
|
81
|
+
if (typeof promptCompact !== "string" || promptCompact.trim().length === 0) return null;
|
|
82
|
+
if (!isStringRecord(promptFiles)) return null;
|
|
83
|
+
const names = Object.keys(promptFiles);
|
|
84
|
+
if (names.length === 0 || !names.every(isSafePromptFileName)) return null;
|
|
85
|
+
if (!referencedPromptFiles(promptCompact)?.every((name) => Object.hasOwn(promptFiles, name))) return null;
|
|
86
|
+
return {
|
|
87
|
+
compact: promptCompact,
|
|
88
|
+
files: promptFiles
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** The text to inject for one tool. `agentFilesDir` is where the agent can
|
|
92
|
+
* read this package's files, or null when they were not written — then the
|
|
93
|
+
* full `prompt` is the only safe choice. */
|
|
94
|
+
function renderToolPrompt(definition, agentFilesDir) {
|
|
95
|
+
const fullPrompt = require_dist.isRecord(definition) && typeof definition.prompt === "string" ? definition.prompt : void 0;
|
|
96
|
+
const split = readPromptSplit(definition);
|
|
97
|
+
if (!split || agentFilesDir === null) return fullPrompt;
|
|
98
|
+
return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/prompt-files/sync.ts
|
|
102
|
+
function mergeFiles(target, files) {
|
|
103
|
+
for (const [name, content] of Object.entries(files)) {
|
|
104
|
+
if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;
|
|
105
|
+
target[name] = content;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
/** Every file each package declares across its tools. */
|
|
110
|
+
function collectPackageFiles(sources) {
|
|
111
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
112
|
+
for (const { packageName, definition } of sources) {
|
|
113
|
+
const split = readPromptSplit(definition);
|
|
114
|
+
if (!split) continue;
|
|
115
|
+
const current = byPackage.get(packageName) ?? { files: {} };
|
|
116
|
+
if (!("files" in current)) continue;
|
|
117
|
+
const problem = mergeFiles(current.files, split.files);
|
|
118
|
+
byPackage.set(packageName, problem ? { problem } : current);
|
|
119
|
+
}
|
|
120
|
+
return byPackage;
|
|
121
|
+
}
|
|
122
|
+
function writeStaging(staging, files) {
|
|
123
|
+
(0, node_fs.mkdirSync)(staging, { recursive: true });
|
|
124
|
+
for (const [name, content] of Object.entries(files)) {
|
|
125
|
+
const filePath = node_path.default.join(staging, ...name.split("/"));
|
|
126
|
+
(0, node_fs.mkdirSync)(node_path.default.dirname(filePath), { recursive: true });
|
|
127
|
+
(0, node_fs.writeFileSync)(filePath, content);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Swap `staging` in for `target`, keeping the old copy until the swap
|
|
131
|
+
* lands — another instance sharing the root may be reading it. */
|
|
132
|
+
function swapIn(staging, target) {
|
|
133
|
+
const backup = `${target}.old-${(0, node_crypto.randomUUID)()}`;
|
|
134
|
+
const hadTarget = (0, node_fs.existsSync)(target);
|
|
135
|
+
if (hadTarget) (0, node_fs.renameSync)(target, backup);
|
|
136
|
+
try {
|
|
137
|
+
(0, node_fs.renameSync)(staging, target);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (hadTarget) (0, node_fs.renameSync)(backup, target);
|
|
140
|
+
throw err;
|
|
141
|
+
}
|
|
142
|
+
(0, node_fs.rmSync)(backup, {
|
|
143
|
+
recursive: true,
|
|
144
|
+
force: true
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** Refuse when the root or a scope directory is a symlink: the swap renames
|
|
148
|
+
* and deletes `<scope>/<name>`, which through a link pointing outside the
|
|
149
|
+
* root would hit an unrelated directory. */
|
|
150
|
+
function assertNoSymlinkedParent(root, subdir) {
|
|
151
|
+
const segments = subdir.split("/").slice(0, -1);
|
|
152
|
+
const parents = segments.map((_, index) => node_path.default.join(root, ...segments.slice(0, index + 1)));
|
|
153
|
+
for (const parent of [root, ...parents]) if ((0, node_fs.existsSync)(parent) && (0, node_fs.lstatSync)(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);
|
|
154
|
+
}
|
|
155
|
+
/** Write into a fresh sibling directory, then swap it in, so a reader never
|
|
156
|
+
* sees a half-written package. */
|
|
157
|
+
function writePackageDir(root, subdir, files) {
|
|
158
|
+
assertNoSymlinkedParent(root, subdir);
|
|
159
|
+
const target = node_path.default.join(root, ...subdir.split("/"));
|
|
160
|
+
const staging = `${target}.tmp-${(0, node_crypto.randomUUID)()}`;
|
|
161
|
+
try {
|
|
162
|
+
writeStaging(staging, files);
|
|
163
|
+
swapIn(staging, target);
|
|
164
|
+
} finally {
|
|
165
|
+
(0, node_fs.rmSync)(staging, {
|
|
166
|
+
recursive: true,
|
|
167
|
+
force: true
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function syncPromptFiles(root, sources) {
|
|
172
|
+
const written = /* @__PURE__ */ new Map();
|
|
173
|
+
const problems = [];
|
|
174
|
+
for (const [packageName, entry] of collectPackageFiles(sources)) {
|
|
175
|
+
const subdir = promptFilesSubdir(packageName);
|
|
176
|
+
if (!subdir) problems.push({
|
|
177
|
+
packageName,
|
|
178
|
+
problem: "package name is not a safe directory name"
|
|
179
|
+
});
|
|
180
|
+
else if ("problem" in entry) problems.push({
|
|
181
|
+
packageName,
|
|
182
|
+
problem: entry.problem
|
|
183
|
+
});
|
|
184
|
+
else try {
|
|
185
|
+
writePackageDir(root, subdir, entry.files);
|
|
186
|
+
written.set(packageName, subdir);
|
|
187
|
+
} catch (err) {
|
|
188
|
+
problems.push({
|
|
189
|
+
packageName,
|
|
190
|
+
problem: `could not write ${node_path.default.join(root, subdir)}: ${String(err)}`
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
written,
|
|
196
|
+
problems
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
exports.PROMPT_FILES_DIR_PLACEHOLDER = PROMPT_FILES_DIR_PLACEHOLDER;
|
|
201
|
+
exports.collectPackageFiles = collectPackageFiles;
|
|
202
|
+
exports.isSafePromptFileName = isSafePromptFileName;
|
|
203
|
+
exports.promptFilesSubdir = promptFilesSubdir;
|
|
204
|
+
exports.readPromptSplit = readPromptSplit;
|
|
205
|
+
exports.referencedPromptFiles = referencedPromptFiles;
|
|
206
|
+
exports.renderToolPrompt = renderToolPrompt;
|
|
207
|
+
exports.syncPromptFiles = syncPromptFiles;
|
|
208
|
+
|
|
209
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isRecord","path","randomUUID","existsSync","lstatSync"],"sources":["../../src/prompt-files/split.ts","../../src/prompt-files/sync.ts"],"sourcesContent":["// A tool definition may split its LLM instructions in two: `promptCompact`,\n// injected inline, and `promptFiles`, reference files the host writes to disk\n// for the agent to Read. `prompt` stays the full text, so a host that knows\n// nothing of the split keeps working. Pure — the file writing is `./sync`.\n\nimport { isRecord } from \"@mulmoclaude/common\";\n\n/** Replaced in `promptCompact` with the directory the agent reads the files\n * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in\n * MulmoTerminal). */\nexport const PROMPT_FILES_DIR_PLACEHOLDER = \"{{promptFilesDir}}\";\n\nexport interface PromptSplit {\n compact: string;\n /** file name (may contain `/`) → file content */\n files: Readonly<Record<string, string>>;\n}\n\nconst SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\n/** A file name a plugin may declare: relative, `/`-separated, every segment a\n * plain name — no `..`, no absolute path, no backslash, no hidden file. */\nexport function isSafePromptFileName(name: string): boolean {\n if (name.length === 0) return false;\n return name.split(\"/\").every((segment) => SAFE_SEGMENT.test(segment));\n}\n\n/** Where one package's files go, relative to the host's root: the\n * `node_modules` layout (`@scope/name`, or `name`), so two packages can never\n * share a directory. Null for a name that could escape it. */\nexport function promptFilesSubdir(packageName: string): string | null {\n const segments = packageName.split(\"/\");\n if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;\n const [scope = \"\", name = \"\"] = segments;\n const isScoped = segments.length === 2 && scope.startsWith(\"@\") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name);\n return isScoped ? packageName : null;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\n/** Characters that end a file reference in prose: whitespace and the\n * punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */\nconst REFERENCE_TERMINATORS = new Set([\" \", \"\\t\", \"\\n\", \"\\r\", \"`\", \"'\", '\"', \")\", \"]\", \">\", \",\", \";\", \":\", \"!\", \"?\", \"。\", \"、\", \")\", \"」\"]);\n\nfunction trimTrailingDots(token: string): string {\n let end = token.length;\n while (end > 0 && token[end - 1] === \".\") end -= 1;\n return token.slice(0, end);\n}\n\n/** The text after one placeholder up to where the reference ends. */\nfunction referenceToken(afterPlaceholder: string): string {\n const chars = [...afterPlaceholder];\n const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));\n return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(\"\"));\n}\n\n/** The files the compact text points at (`{{promptFilesDir}}/<name>`),\n * sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the\n * directory itself and contributes nothing. Null when a reference is not a\n * safe file name — the agent would be sent to a path that cannot exist. */\nexport function referencedPromptFiles(compact: string): string[] | null {\n const references = compact\n .split(PROMPT_FILES_DIR_PLACEHOLDER)\n .slice(1)\n .filter((afterPlaceholder) => afterPlaceholder.startsWith(\"/\"))\n .map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));\n return references.every(isSafePromptFileName) ? references : null;\n}\n\n/** The split a definition declares, or null when it declares none — or one\n * that would leave the agent pointed at a missing file: no files, an unsafe\n * name, or a reference in the compact text to a file it does not declare.\n * The host then injects the full `prompt`. */\nexport function readPromptSplit(definition: unknown): PromptSplit | null {\n if (!isRecord(definition)) return null;\n const { promptCompact, promptFiles } = definition;\n if (typeof promptCompact !== \"string\" || promptCompact.trim().length === 0) return null;\n if (!isStringRecord(promptFiles)) return null;\n const names = Object.keys(promptFiles);\n if (names.length === 0 || !names.every(isSafePromptFileName)) return null;\n const references = referencedPromptFiles(promptCompact);\n if (!references?.every((name) => Object.hasOwn(promptFiles, name))) return null;\n return { compact: promptCompact, files: promptFiles };\n}\n\n/** The text to inject for one tool. `agentFilesDir` is where the agent can\n * read this package's files, or null when they were not written — then the\n * full `prompt` is the only safe choice. */\nexport function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined {\n const fullPrompt = isRecord(definition) && typeof definition.prompt === \"string\" ? definition.prompt : undefined;\n const split = readPromptSplit(definition);\n if (!split || agentFilesDir === null) return fullPrompt;\n return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);\n}\n","// Writes each package's prompt reference files under `<root>/<package>/`.\n// Only the packages passed in are touched: a MulmoTerminal root is shared by\n// every instance, and one with a different plugin set must not delete the\n// others' files.\n\nimport { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { promptFilesSubdir, readPromptSplit } from \"./split\";\n\nexport interface PromptFilesSource {\n /** Package name supplied by the HOST (never read from the definition), so\n * one plugin cannot claim another's directory. */\n packageName: string;\n definition: unknown;\n}\n\nexport interface PromptFilesSyncResult {\n /** package name → its subdir under the root, for every package written. */\n written: ReadonlyMap<string, string>;\n /** packages skipped, with why — their tools keep the full `prompt`. */\n problems: { packageName: string; problem: string }[];\n}\n\ntype PackageFiles = { files: Record<string, string> } | { problem: string };\n\nfunction mergeFiles(target: Record<string, string>, files: Readonly<Record<string, string>>): string | null {\n for (const [name, content] of Object.entries(files)) {\n if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;\n target[name] = content;\n }\n return null;\n}\n\n/** Every file each package declares across its tools. */\nexport function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles> {\n const byPackage = new Map<string, PackageFiles>();\n for (const { packageName, definition } of sources) {\n const split = readPromptSplit(definition);\n if (!split) continue;\n const current = byPackage.get(packageName) ?? { files: {} };\n if (!(\"files\" in current)) continue;\n const problem = mergeFiles(current.files, split.files);\n byPackage.set(packageName, problem ? { problem } : current);\n }\n return byPackage;\n}\n\nfunction writeStaging(staging: string, files: Readonly<Record<string, string>>): void {\n mkdirSync(staging, { recursive: true });\n for (const [name, content] of Object.entries(files)) {\n const filePath = path.join(staging, ...name.split(\"/\"));\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content);\n }\n}\n\n/** Swap `staging` in for `target`, keeping the old copy until the swap\n * lands — another instance sharing the root may be reading it. */\nfunction swapIn(staging: string, target: string): void {\n const backup = `${target}.old-${randomUUID()}`;\n const hadTarget = existsSync(target);\n if (hadTarget) renameSync(target, backup);\n try {\n renameSync(staging, target);\n } catch (err) {\n if (hadTarget) renameSync(backup, target);\n throw err;\n }\n rmSync(backup, { recursive: true, force: true });\n}\n\n/** Refuse when the root or a scope directory is a symlink: the swap renames\n * and deletes `<scope>/<name>`, which through a link pointing outside the\n * root would hit an unrelated directory. */\nfunction assertNoSymlinkedParent(root: string, subdir: string): void {\n const segments = subdir.split(\"/\").slice(0, -1);\n const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));\n for (const parent of [root, ...parents]) {\n if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);\n }\n}\n\n/** Write into a fresh sibling directory, then swap it in, so a reader never\n * sees a half-written package. */\nfunction writePackageDir(root: string, subdir: string, files: Readonly<Record<string, string>>): void {\n assertNoSymlinkedParent(root, subdir);\n const target = path.join(root, ...subdir.split(\"/\"));\n const staging = `${target}.tmp-${randomUUID()}`;\n try {\n writeStaging(staging, files);\n swapIn(staging, target);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n}\n\nexport function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult {\n const written = new Map<string, string>();\n const problems: PromptFilesSyncResult[\"problems\"] = [];\n for (const [packageName, entry] of collectPackageFiles(sources)) {\n const subdir = promptFilesSubdir(packageName);\n if (!subdir) problems.push({ packageName, problem: \"package name is not a safe directory name\" });\n else if (\"problem\" in entry) problems.push({ packageName, problem: entry.problem });\n else {\n try {\n writePackageDir(root, subdir, entry.files);\n written.set(packageName, subdir);\n } catch (err) {\n problems.push({ packageName, problem: `could not write ${path.join(root, subdir)}: ${String(err)}` });\n }\n }\n }\n return { written, problems };\n}\n"],"mappings":";;;;;;;;;;;AAUA,IAAa,+BAA+B;AAQ5C,IAAM,eAAe;;;AAIrB,SAAgB,qBAAqB,MAAuB;CAC1D,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,aAAa,KAAK,OAAO,CAAC;AACtE;;;;AAKA,SAAgB,kBAAkB,aAAoC;CACpE,MAAM,WAAW,YAAY,MAAM,GAAG;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plit, } from './split';
|
|
2
|
+
export { collectPackageFiles, syncPromptFiles, type PromptFilesSource, type PromptFilesSyncResult } from './sync';
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { c as isRecord } from "../dist-MFUV9FYo.js";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
//#region src/prompt-files/split.ts
|
|
6
|
+
/** Replaced in `promptCompact` with the directory the agent reads the files
|
|
7
|
+
* from — a path only the host knows (cwd-relative in MulmoClaude, absolute in
|
|
8
|
+
* MulmoTerminal). */
|
|
9
|
+
var PROMPT_FILES_DIR_PLACEHOLDER = "{{promptFilesDir}}";
|
|
10
|
+
var SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
11
|
+
/** A file name a plugin may declare: relative, `/`-separated, every segment a
|
|
12
|
+
* plain name — no `..`, no absolute path, no backslash, no hidden file. */
|
|
13
|
+
function isSafePromptFileName(name) {
|
|
14
|
+
if (name.length === 0) return false;
|
|
15
|
+
return name.split("/").every((segment) => SAFE_SEGMENT.test(segment));
|
|
16
|
+
}
|
|
17
|
+
/** Where one package's files go, relative to the host's root: the
|
|
18
|
+
* `node_modules` layout (`@scope/name`, or `name`), so two packages can never
|
|
19
|
+
* share a directory. Null for a name that could escape it. */
|
|
20
|
+
function promptFilesSubdir(packageName) {
|
|
21
|
+
const segments = packageName.split("/");
|
|
22
|
+
if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;
|
|
23
|
+
const [scope = "", name = ""] = segments;
|
|
24
|
+
return segments.length === 2 && scope.startsWith("@") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name) ? packageName : null;
|
|
25
|
+
}
|
|
26
|
+
function isStringRecord(value) {
|
|
27
|
+
return isRecord(value) && Object.values(value).every((entry) => typeof entry === "string");
|
|
28
|
+
}
|
|
29
|
+
/** Characters that end a file reference in prose: whitespace and the
|
|
30
|
+
* punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */
|
|
31
|
+
var REFERENCE_TERMINATORS = /* @__PURE__ */ new Set([
|
|
32
|
+
" ",
|
|
33
|
+
" ",
|
|
34
|
+
"\n",
|
|
35
|
+
"\r",
|
|
36
|
+
"`",
|
|
37
|
+
"'",
|
|
38
|
+
"\"",
|
|
39
|
+
")",
|
|
40
|
+
"]",
|
|
41
|
+
">",
|
|
42
|
+
",",
|
|
43
|
+
";",
|
|
44
|
+
":",
|
|
45
|
+
"!",
|
|
46
|
+
"?",
|
|
47
|
+
"。",
|
|
48
|
+
"、",
|
|
49
|
+
")",
|
|
50
|
+
"」"
|
|
51
|
+
]);
|
|
52
|
+
function trimTrailingDots(token) {
|
|
53
|
+
let end = token.length;
|
|
54
|
+
while (end > 0 && token[end - 1] === ".") end -= 1;
|
|
55
|
+
return token.slice(0, end);
|
|
56
|
+
}
|
|
57
|
+
/** The text after one placeholder up to where the reference ends. */
|
|
58
|
+
function referenceToken(afterPlaceholder) {
|
|
59
|
+
const chars = [...afterPlaceholder];
|
|
60
|
+
const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));
|
|
61
|
+
return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(""));
|
|
62
|
+
}
|
|
63
|
+
/** The files the compact text points at (`{{promptFilesDir}}/<name>`),
|
|
64
|
+
* sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the
|
|
65
|
+
* directory itself and contributes nothing. Null when a reference is not a
|
|
66
|
+
* safe file name — the agent would be sent to a path that cannot exist. */
|
|
67
|
+
function referencedPromptFiles(compact) {
|
|
68
|
+
const references = compact.split(PROMPT_FILES_DIR_PLACEHOLDER).slice(1).filter((afterPlaceholder) => afterPlaceholder.startsWith("/")).map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));
|
|
69
|
+
return references.every(isSafePromptFileName) ? references : null;
|
|
70
|
+
}
|
|
71
|
+
/** The split a definition declares, or null when it declares none — or one
|
|
72
|
+
* that would leave the agent pointed at a missing file: no files, an unsafe
|
|
73
|
+
* name, or a reference in the compact text to a file it does not declare.
|
|
74
|
+
* The host then injects the full `prompt`. */
|
|
75
|
+
function readPromptSplit(definition) {
|
|
76
|
+
if (!isRecord(definition)) return null;
|
|
77
|
+
const { promptCompact, promptFiles } = definition;
|
|
78
|
+
if (typeof promptCompact !== "string" || promptCompact.trim().length === 0) return null;
|
|
79
|
+
if (!isStringRecord(promptFiles)) return null;
|
|
80
|
+
const names = Object.keys(promptFiles);
|
|
81
|
+
if (names.length === 0 || !names.every(isSafePromptFileName)) return null;
|
|
82
|
+
if (!referencedPromptFiles(promptCompact)?.every((name) => Object.hasOwn(promptFiles, name))) return null;
|
|
83
|
+
return {
|
|
84
|
+
compact: promptCompact,
|
|
85
|
+
files: promptFiles
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** The text to inject for one tool. `agentFilesDir` is where the agent can
|
|
89
|
+
* read this package's files, or null when they were not written — then the
|
|
90
|
+
* full `prompt` is the only safe choice. */
|
|
91
|
+
function renderToolPrompt(definition, agentFilesDir) {
|
|
92
|
+
const fullPrompt = isRecord(definition) && typeof definition.prompt === "string" ? definition.prompt : void 0;
|
|
93
|
+
const split = readPromptSplit(definition);
|
|
94
|
+
if (!split || agentFilesDir === null) return fullPrompt;
|
|
95
|
+
return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/prompt-files/sync.ts
|
|
99
|
+
function mergeFiles(target, files) {
|
|
100
|
+
for (const [name, content] of Object.entries(files)) {
|
|
101
|
+
if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;
|
|
102
|
+
target[name] = content;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
/** Every file each package declares across its tools. */
|
|
107
|
+
function collectPackageFiles(sources) {
|
|
108
|
+
const byPackage = /* @__PURE__ */ new Map();
|
|
109
|
+
for (const { packageName, definition } of sources) {
|
|
110
|
+
const split = readPromptSplit(definition);
|
|
111
|
+
if (!split) continue;
|
|
112
|
+
const current = byPackage.get(packageName) ?? { files: {} };
|
|
113
|
+
if (!("files" in current)) continue;
|
|
114
|
+
const problem = mergeFiles(current.files, split.files);
|
|
115
|
+
byPackage.set(packageName, problem ? { problem } : current);
|
|
116
|
+
}
|
|
117
|
+
return byPackage;
|
|
118
|
+
}
|
|
119
|
+
function writeStaging(staging, files) {
|
|
120
|
+
mkdirSync(staging, { recursive: true });
|
|
121
|
+
for (const [name, content] of Object.entries(files)) {
|
|
122
|
+
const filePath = path.join(staging, ...name.split("/"));
|
|
123
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
124
|
+
writeFileSync(filePath, content);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Swap `staging` in for `target`, keeping the old copy until the swap
|
|
128
|
+
* lands — another instance sharing the root may be reading it. */
|
|
129
|
+
function swapIn(staging, target) {
|
|
130
|
+
const backup = `${target}.old-${randomUUID()}`;
|
|
131
|
+
const hadTarget = existsSync(target);
|
|
132
|
+
if (hadTarget) renameSync(target, backup);
|
|
133
|
+
try {
|
|
134
|
+
renameSync(staging, target);
|
|
135
|
+
} catch (err) {
|
|
136
|
+
if (hadTarget) renameSync(backup, target);
|
|
137
|
+
throw err;
|
|
138
|
+
}
|
|
139
|
+
rmSync(backup, {
|
|
140
|
+
recursive: true,
|
|
141
|
+
force: true
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/** Refuse when the root or a scope directory is a symlink: the swap renames
|
|
145
|
+
* and deletes `<scope>/<name>`, which through a link pointing outside the
|
|
146
|
+
* root would hit an unrelated directory. */
|
|
147
|
+
function assertNoSymlinkedParent(root, subdir) {
|
|
148
|
+
const segments = subdir.split("/").slice(0, -1);
|
|
149
|
+
const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));
|
|
150
|
+
for (const parent of [root, ...parents]) if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);
|
|
151
|
+
}
|
|
152
|
+
/** Write into a fresh sibling directory, then swap it in, so a reader never
|
|
153
|
+
* sees a half-written package. */
|
|
154
|
+
function writePackageDir(root, subdir, files) {
|
|
155
|
+
assertNoSymlinkedParent(root, subdir);
|
|
156
|
+
const target = path.join(root, ...subdir.split("/"));
|
|
157
|
+
const staging = `${target}.tmp-${randomUUID()}`;
|
|
158
|
+
try {
|
|
159
|
+
writeStaging(staging, files);
|
|
160
|
+
swapIn(staging, target);
|
|
161
|
+
} finally {
|
|
162
|
+
rmSync(staging, {
|
|
163
|
+
recursive: true,
|
|
164
|
+
force: true
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function syncPromptFiles(root, sources) {
|
|
169
|
+
const written = /* @__PURE__ */ new Map();
|
|
170
|
+
const problems = [];
|
|
171
|
+
for (const [packageName, entry] of collectPackageFiles(sources)) {
|
|
172
|
+
const subdir = promptFilesSubdir(packageName);
|
|
173
|
+
if (!subdir) problems.push({
|
|
174
|
+
packageName,
|
|
175
|
+
problem: "package name is not a safe directory name"
|
|
176
|
+
});
|
|
177
|
+
else if ("problem" in entry) problems.push({
|
|
178
|
+
packageName,
|
|
179
|
+
problem: entry.problem
|
|
180
|
+
});
|
|
181
|
+
else try {
|
|
182
|
+
writePackageDir(root, subdir, entry.files);
|
|
183
|
+
written.set(packageName, subdir);
|
|
184
|
+
} catch (err) {
|
|
185
|
+
problems.push({
|
|
186
|
+
packageName,
|
|
187
|
+
problem: `could not write ${path.join(root, subdir)}: ${String(err)}`
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
written,
|
|
193
|
+
problems
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
//#endregion
|
|
197
|
+
export { PROMPT_FILES_DIR_PLACEHOLDER, collectPackageFiles, isSafePromptFileName, promptFilesSubdir, readPromptSplit, referencedPromptFiles, renderToolPrompt, syncPromptFiles };
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/prompt-files/split.ts","../../src/prompt-files/sync.ts"],"sourcesContent":["// A tool definition may split its LLM instructions in two: `promptCompact`,\n// injected inline, and `promptFiles`, reference files the host writes to disk\n// for the agent to Read. `prompt` stays the full text, so a host that knows\n// nothing of the split keeps working. Pure — the file writing is `./sync`.\n\nimport { isRecord } from \"@mulmoclaude/common\";\n\n/** Replaced in `promptCompact` with the directory the agent reads the files\n * from — a path only the host knows (cwd-relative in MulmoClaude, absolute in\n * MulmoTerminal). */\nexport const PROMPT_FILES_DIR_PLACEHOLDER = \"{{promptFilesDir}}\";\n\nexport interface PromptSplit {\n compact: string;\n /** file name (may contain `/`) → file content */\n files: Readonly<Record<string, string>>;\n}\n\nconst SAFE_SEGMENT = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;\n\n/** A file name a plugin may declare: relative, `/`-separated, every segment a\n * plain name — no `..`, no absolute path, no backslash, no hidden file. */\nexport function isSafePromptFileName(name: string): boolean {\n if (name.length === 0) return false;\n return name.split(\"/\").every((segment) => SAFE_SEGMENT.test(segment));\n}\n\n/** Where one package's files go, relative to the host's root: the\n * `node_modules` layout (`@scope/name`, or `name`), so two packages can never\n * share a directory. Null for a name that could escape it. */\nexport function promptFilesSubdir(packageName: string): string | null {\n const segments = packageName.split(\"/\");\n if (segments.length === 1) return SAFE_SEGMENT.test(packageName) ? packageName : null;\n const [scope = \"\", name = \"\"] = segments;\n const isScoped = segments.length === 2 && scope.startsWith(\"@\") && SAFE_SEGMENT.test(scope.slice(1)) && SAFE_SEGMENT.test(name);\n return isScoped ? packageName : null;\n}\n\nfunction isStringRecord(value: unknown): value is Record<string, string> {\n return isRecord(value) && Object.values(value).every((entry) => typeof entry === \"string\");\n}\n\n/** Characters that end a file reference in prose: whitespace and the\n * punctuation that wraps or follows a path (`…/guide.md`, (…/guide.md)). */\nconst REFERENCE_TERMINATORS = new Set([\" \", \"\\t\", \"\\n\", \"\\r\", \"`\", \"'\", '\"', \")\", \"]\", \">\", \",\", \";\", \":\", \"!\", \"?\", \"。\", \"、\", \")\", \"」\"]);\n\nfunction trimTrailingDots(token: string): string {\n let end = token.length;\n while (end > 0 && token[end - 1] === \".\") end -= 1;\n return token.slice(0, end);\n}\n\n/** The text after one placeholder up to where the reference ends. */\nfunction referenceToken(afterPlaceholder: string): string {\n const chars = [...afterPlaceholder];\n const end = chars.findIndex((char) => REFERENCE_TERMINATORS.has(char));\n return trimTrailingDots(chars.slice(0, end === -1 ? chars.length : end).join(\"\"));\n}\n\n/** The files the compact text points at (`{{promptFilesDir}}/<name>`),\n * sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the\n * directory itself and contributes nothing. Null when a reference is not a\n * safe file name — the agent would be sent to a path that cannot exist. */\nexport function referencedPromptFiles(compact: string): string[] | null {\n const references = compact\n .split(PROMPT_FILES_DIR_PLACEHOLDER)\n .slice(1)\n .filter((afterPlaceholder) => afterPlaceholder.startsWith(\"/\"))\n .map((afterPlaceholder) => referenceToken(afterPlaceholder.slice(1)));\n return references.every(isSafePromptFileName) ? references : null;\n}\n\n/** The split a definition declares, or null when it declares none — or one\n * that would leave the agent pointed at a missing file: no files, an unsafe\n * name, or a reference in the compact text to a file it does not declare.\n * The host then injects the full `prompt`. */\nexport function readPromptSplit(definition: unknown): PromptSplit | null {\n if (!isRecord(definition)) return null;\n const { promptCompact, promptFiles } = definition;\n if (typeof promptCompact !== \"string\" || promptCompact.trim().length === 0) return null;\n if (!isStringRecord(promptFiles)) return null;\n const names = Object.keys(promptFiles);\n if (names.length === 0 || !names.every(isSafePromptFileName)) return null;\n const references = referencedPromptFiles(promptCompact);\n if (!references?.every((name) => Object.hasOwn(promptFiles, name))) return null;\n return { compact: promptCompact, files: promptFiles };\n}\n\n/** The text to inject for one tool. `agentFilesDir` is where the agent can\n * read this package's files, or null when they were not written — then the\n * full `prompt` is the only safe choice. */\nexport function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined {\n const fullPrompt = isRecord(definition) && typeof definition.prompt === \"string\" ? definition.prompt : undefined;\n const split = readPromptSplit(definition);\n if (!split || agentFilesDir === null) return fullPrompt;\n return split.compact.split(PROMPT_FILES_DIR_PLACEHOLDER).join(agentFilesDir);\n}\n","// Writes each package's prompt reference files under `<root>/<package>/`.\n// Only the packages passed in are touched: a MulmoTerminal root is shared by\n// every instance, and one with a different plugin set must not delete the\n// others' files.\n\nimport { existsSync, lstatSync, mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { randomUUID } from \"node:crypto\";\nimport { promptFilesSubdir, readPromptSplit } from \"./split\";\n\nexport interface PromptFilesSource {\n /** Package name supplied by the HOST (never read from the definition), so\n * one plugin cannot claim another's directory. */\n packageName: string;\n definition: unknown;\n}\n\nexport interface PromptFilesSyncResult {\n /** package name → its subdir under the root, for every package written. */\n written: ReadonlyMap<string, string>;\n /** packages skipped, with why — their tools keep the full `prompt`. */\n problems: { packageName: string; problem: string }[];\n}\n\ntype PackageFiles = { files: Record<string, string> } | { problem: string };\n\nfunction mergeFiles(target: Record<string, string>, files: Readonly<Record<string, string>>): string | null {\n for (const [name, content] of Object.entries(files)) {\n if (Object.hasOwn(target, name) && target[name] !== content) return `two tools declare '${name}' with different content`;\n target[name] = content;\n }\n return null;\n}\n\n/** Every file each package declares across its tools. */\nexport function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles> {\n const byPackage = new Map<string, PackageFiles>();\n for (const { packageName, definition } of sources) {\n const split = readPromptSplit(definition);\n if (!split) continue;\n const current = byPackage.get(packageName) ?? { files: {} };\n if (!(\"files\" in current)) continue;\n const problem = mergeFiles(current.files, split.files);\n byPackage.set(packageName, problem ? { problem } : current);\n }\n return byPackage;\n}\n\nfunction writeStaging(staging: string, files: Readonly<Record<string, string>>): void {\n mkdirSync(staging, { recursive: true });\n for (const [name, content] of Object.entries(files)) {\n const filePath = path.join(staging, ...name.split(\"/\"));\n mkdirSync(path.dirname(filePath), { recursive: true });\n writeFileSync(filePath, content);\n }\n}\n\n/** Swap `staging` in for `target`, keeping the old copy until the swap\n * lands — another instance sharing the root may be reading it. */\nfunction swapIn(staging: string, target: string): void {\n const backup = `${target}.old-${randomUUID()}`;\n const hadTarget = existsSync(target);\n if (hadTarget) renameSync(target, backup);\n try {\n renameSync(staging, target);\n } catch (err) {\n if (hadTarget) renameSync(backup, target);\n throw err;\n }\n rmSync(backup, { recursive: true, force: true });\n}\n\n/** Refuse when the root or a scope directory is a symlink: the swap renames\n * and deletes `<scope>/<name>`, which through a link pointing outside the\n * root would hit an unrelated directory. */\nfunction assertNoSymlinkedParent(root: string, subdir: string): void {\n const segments = subdir.split(\"/\").slice(0, -1);\n const parents = segments.map((_, index) => path.join(root, ...segments.slice(0, index + 1)));\n for (const parent of [root, ...parents]) {\n if (existsSync(parent) && lstatSync(parent).isSymbolicLink()) throw new Error(`${parent} is a symlink`);\n }\n}\n\n/** Write into a fresh sibling directory, then swap it in, so a reader never\n * sees a half-written package. */\nfunction writePackageDir(root: string, subdir: string, files: Readonly<Record<string, string>>): void {\n assertNoSymlinkedParent(root, subdir);\n const target = path.join(root, ...subdir.split(\"/\"));\n const staging = `${target}.tmp-${randomUUID()}`;\n try {\n writeStaging(staging, files);\n swapIn(staging, target);\n } finally {\n rmSync(staging, { recursive: true, force: true });\n }\n}\n\nexport function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult {\n const written = new Map<string, string>();\n const problems: PromptFilesSyncResult[\"problems\"] = [];\n for (const [packageName, entry] of collectPackageFiles(sources)) {\n const subdir = promptFilesSubdir(packageName);\n if (!subdir) problems.push({ packageName, problem: \"package name is not a safe directory name\" });\n else if (\"problem\" in entry) problems.push({ packageName, problem: entry.problem });\n else {\n try {\n writePackageDir(root, subdir, entry.files);\n written.set(packageName, subdir);\n } catch (err) {\n problems.push({ packageName, problem: `could not write ${path.join(root, subdir)}: ${String(err)}` });\n }\n }\n }\n return { written, problems };\n}\n"],"mappings":";;;;;;;;AAUA,IAAa,+BAA+B;AAQ5C,IAAM,eAAe;;;AAIrB,SAAgB,qBAAqB,MAAuB;CAC1D,IAAI,KAAK,WAAW,GAAG,OAAO;CAC9B,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,YAAY,aAAa,KAAK,OAAO,CAAC;AACtE;;;;AAKA,SAAgB,kBAAkB,aAAoC;CACpE,MAAM,WAAW,YAAY,MAAM,GAAG;CACtC,IAAI,SAAS,WAAW,GAAG,OAAO,aAAa,KAAK,WAAW,IAAI,cAAc;CACjF,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM;CAEhC,OADiB,SAAS,WAAW,KAAK,MAAM,WAAW,GAAG,KAAK,aAAa,KAAK,MAAM,MAAM,CAAC,CAAC,KAAK,aAAa,KAAK,IAAI,IAC5G,cAAc;AAClC;AAEA,SAAS,eAAe,OAAiD;CACvE,OAAO,SAAS,KAAK,KAAK,OAAO,OAAO,KAAK,CAAC,CAAC,OAAO,UAAU,OAAO,UAAU,QAAQ;AAC3F;;;AAIA,IAAM,wCAAwB,IAAI,IAAI;CAAC;CAAK;CAAM;CAAM;CAAM;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;CAAK;AAAG,CAAC;AAExI,SAAS,iBAAiB,OAAuB;CAC/C,IAAI,MAAM,MAAM;CAChB,OAAO,MAAM,KAAK,MAAM,MAAM,OAAO,KAAK,OAAO;CACjD,OAAO,MAAM,MAAM,GAAG,GAAG;AAC3B;;AAGA,SAAS,eAAe,kBAAkC;CACxD,MAAM,QAAQ,CAAC,GAAG,gBAAgB;CAClC,MAAM,MAAM,MAAM,WAAW,SAAS,sB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ompact` with the directory the agent reads the files
|
|
2
|
+
* from — a path only the host knows (cwd-relative in MulmoClaude, absolute in
|
|
3
|
+
* MulmoTerminal). */
|
|
4
|
+
export declare const PROMPT_FILES_DIR_PLACEHOLDER = "{{promptFilesDir}}";
|
|
5
|
+
export interface PromptSplit {
|
|
6
|
+
compact: string;
|
|
7
|
+
/** file name (may contain `/`) → file content */
|
|
8
|
+
files: Readonly<Record<string, string>>;
|
|
9
|
+
}
|
|
10
|
+
/** A file name a plugin may declare: relative, `/`-separated, every segment a
|
|
11
|
+
* plain name — no `..`, no absolute path, no backslash, no hidden file. */
|
|
12
|
+
export declare function isSafePromptFileName(name: string): boolean;
|
|
13
|
+
/** Where one package's files go, relative to the host's root: the
|
|
14
|
+
* `node_modules` layout (`@scope/name`, or `name`), so two packages can never
|
|
15
|
+
* share a directory. Null for a name that could escape it. */
|
|
16
|
+
export declare function promptFilesSubdir(packageName: string): string | null;
|
|
17
|
+
/** The files the compact text points at (`{{promptFilesDir}}/<name>`),
|
|
18
|
+
* sentence-ending dots dropped. A bare `{{promptFilesDir}}` names the
|
|
19
|
+
* directory itself and contributes nothing. Null when a reference is not a
|
|
20
|
+
* safe file name — the agent would be sent to a path that cannot exist. */
|
|
21
|
+
export declare function referencedPromptFiles(compact: string): string[] | null;
|
|
22
|
+
/** The split a definition declares, or null when it declares none — or one
|
|
23
|
+
* that would leave the agent pointed at a missing file: no files, an unsafe
|
|
24
|
+
* name, or a reference in the compact text to a file it does not declare.
|
|
25
|
+
* The host then injects the full `prompt`. */
|
|
26
|
+
export declare function readPromptSplit(definition: unknown): PromptSplit | null;
|
|
27
|
+
/** The text to inject for one tool. `agentFilesDir` is where the agent can
|
|
28
|
+
* read this package's files, or null when they were not written — then the
|
|
29
|
+
* full `prompt` is the only safe choice. */
|
|
30
|
+
export declare function renderToolPrompt(definition: unknown, agentFilesDir: string | null): string | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface PromptFilesSource {
|
|
2
|
+
/** Package name supplied by the HOST (never read from the definition), so
|
|
3
|
+
* one plugin cannot claim another's directory. */
|
|
4
|
+
packageName: string;
|
|
5
|
+
definition: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface PromptFilesSyncResult {
|
|
8
|
+
/** package name → its subdir under the root, for every package written. */
|
|
9
|
+
written: ReadonlyMap<string, string>;
|
|
10
|
+
/** packages skipped, with why — their tools keep the full `prompt`. */
|
|
11
|
+
problems: {
|
|
12
|
+
packageName: string;
|
|
13
|
+
problem: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
type PackageFiles = {
|
|
17
|
+
files: Record<string, string>;
|
|
18
|
+
} | {
|
|
19
|
+
problem: string;
|
|
20
|
+
};
|
|
21
|
+
/** Every file each package declares across its tools. */
|
|
22
|
+
export declare function collectPackageFiles(sources: readonly PromptFilesSource[]): Map<string, PackageFiles>;
|
|
23
|
+
export declare function syncPromptFiles(root: string, sources: readonly PromptFilesSource[]): PromptFilesSyncResult;
|
|
24
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mulmoclaude/core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.10.0",
|
|
4
4
|
"description": "Shared server-side core for MulmoClaude and MulmoTerminal — the always-shipped-together subsystems consolidated behind subpath exports so the two hosts can't drift. Server-only except the browser-safe ./artifacts, ./whisper/client, ./workspace-setup/slug, ./translation/client, ./remote-view, ./remote-host and ./plugin-vue entries. All host specifics are injected.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -145,6 +145,12 @@
|
|
|
145
145
|
"require": "./dist/notifier/index.cjs",
|
|
146
146
|
"default": "./dist/notifier/index.js"
|
|
147
147
|
},
|
|
148
|
+
"./prompt-files": {
|
|
149
|
+
"types": "./dist/prompt-files/index.d.ts",
|
|
150
|
+
"import": "./dist/prompt-files/index.js",
|
|
151
|
+
"require": "./dist/prompt-files/index.cjs",
|
|
152
|
+
"default": "./dist/prompt-files/index.js"
|
|
153
|
+
},
|
|
148
154
|
"./scheduler": {
|
|
149
155
|
"types": "./dist/scheduler/index.d.ts",
|
|
150
156
|
"import": "./dist/scheduler/index.js",
|