feat(mindspace): add page quota grace write and local delivery guardrails.
Memind CI / Test, build, and release guards (pull_request) Failing after 18s

Centralize page HTML quota checks with grace-write semantics across page
services and workspace tools, keep localhost MindSpace links clickable in
chat display, and expand Page Data/static-page skill plus local dev docs
for quota, delivery URLs, and native Aider/OpenHands tooling.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
john
2026-07-30 10:27:16 +08:00
parent b553107817
commit 371900bae5
18 changed files with 503 additions and 39 deletions
+35
View File
@@ -13,6 +13,10 @@ import {
import {
UPLOAD_ZONE_CODES,
} from './user-space.mjs';
import {
assertPageWriteQuotaForUser,
isMindSpacePageWriteRelativePath,
} from './mindspace-space-quota.mjs';
function workspaceToolError(message, code) {
return Object.assign(new Error(message), { code });
@@ -330,6 +334,9 @@ export function createMindSpaceWorkspaceToolService({
maxBinaryWriteBytes = 8 * 1024 * 1024,
maxGeneratedBinaryBytes =
40 * 1024 * 1024,
assertPageWriteQuotaForUserFn =
assertPageWriteQuotaForUser,
getQuotaPool = null,
} = {}) {
if (!h5Root) {
throw new Error(
@@ -395,6 +402,23 @@ export function createMindSpaceWorkspaceToolService({
};
};
const ensurePageWriteAllowed = async ({
userId,
relativePath,
requiredBytes,
}) => {
if (
!getQuotaPool ||
typeof assertPageWriteQuotaForUserFn !== 'function' ||
!isMindSpacePageWriteRelativePath(relativePath)
) {
return;
}
const pool = getQuotaPool();
if (!pool) return;
await assertPageWriteQuotaForUserFn(pool, userId, requiredBytes);
};
const registerWrite = async ({
scope,
relativePath,
@@ -523,6 +547,11 @@ export function createMindSpaceWorkspaceToolService({
content,
{ relativePath },
);
await ensurePageWriteAllowed({
userId: scope.userId,
relativePath,
requiredBytes: sizeBytes,
});
const target =
await resolveWritableWorkspacePath(
scope.workspaceRoot,
@@ -620,6 +649,12 @@ export function createMindSpaceWorkspaceToolService({
updated,
{ relativePath },
);
const originalSizeBytes = mimeSafeByteLength(original);
await ensurePageWriteAllowed({
userId: scope.userId,
relativePath,
requiredBytes: Math.max(0, sizeBytes - originalSizeBytes),
});
await fs.writeFile(target, updated, 'utf8');
const registration = await registerWrite({
scope,