feat(runtime): default to passthrough and persist execution permissions

This commit is contained in:
Agent Workbench Dev
2026-11-06 04:58:57 +08:00
parent 67c034f4b6
commit 2fa220735d
113 changed files with 1866 additions and 631 deletions
+9 -8
View File
@@ -1,3 +1,4 @@
import { unrestricted, ceiling } from '../../shared/contracts/execution-policy.mjs';
import { randomUUID, createHash } from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';
@@ -128,7 +129,7 @@ export class ProjectMemoryManager {
if (memory.status === 'current' && !inspection.scope.complete) value.status = 'unverified';
presented.push(value);
}
const memories = presented.filter(value => includeExpired || value.status === 'current').slice(0, MAX_MEMORIES);
const memories = presented.filter(value => includeExpired || value.status === 'current').slice(0, ceiling(this.store, MAX_MEMORIES));
return {
projectId, sourceFingerprint: inspection.sourceFingerprint, inspectedAt: inspection.inspectedAt,
scope: inspection.scope, memories,
@@ -141,15 +142,15 @@ export class ProjectMemoryManager {
}
async create(session, input = {}) {
if ([...this.store.core.memory.values()].filter(value => value.projectId === session.projectId).length >= MAX_MEMORIES) throw memoryError('项目记忆已到500条上限。', 409);
if ([...this.store.core.memory.values()].filter(value => value.projectId === session.projectId).length >= ceiling(this.store, MAX_MEMORIES)) throw memoryError('项目记忆已到500条上限。', 409);
const project = this.store.project(session.projectId);
const inspection = await this.inspect(session.projectId);
if (!inspection.scope.complete) throw memoryError('本次工程源码扫描不完整,暂不能保存绑定工程版本的项目记忆;请先缩小工程范围或排除超预算文件。', 409);
const title = text(input.title || '未命名记忆', MAX_TITLE);
const title = text(input.title || '未命名记忆', ceiling(this.store, MAX_TITLE));
const content = String(input.content ?? '').trim();
if (!content || content.length > MAX_CONTENT) throw memoryError('项目记忆内容不能为空且不能超过16000字符。');
if (!content || content.length > ceiling(this.store, MAX_CONTENT)) throw memoryError('项目记忆内容不能为空且不能超过16000字符。');
if (title.length < 1) throw memoryError('项目记忆标题不能为空。');
const tags = Array.isArray(input.tags) ? [...new Set(input.tags.map(value => text(value, MAX_TAG)).filter(Boolean))].slice(0, MAX_TAGS) : [];
const tags = Array.isArray(input.tags) ? [...new Set(input.tags.map(value => text(value, ceiling(this.store, MAX_TAG))).filter(Boolean))].slice(0, ceiling(this.store, MAX_TAGS)) : [];
if (input.tags !== undefined && !Array.isArray(input.tags)) throw memoryError('项目记忆标签需要数组。');
let expiresAt = null;
if (input.expiresAt !== undefined && input.expiresAt !== null && input.expiresAt !== '') {
@@ -189,7 +190,7 @@ export class ProjectMemoryManager {
return false;
}
async context(session, { redact = value => value, maxEntries = MEMORY_CONTEXT_LIMITS.entries, maxBytes = MEMORY_CONTEXT_LIMITS.bytes } = {}) {
async context(session, { redact = value => value, maxEntries = ceiling(this.store, MEMORY_CONTEXT_LIMITS.entries), maxBytes = ceiling(this.store, MEMORY_CONTEXT_LIMITS.bytes) } = {}) {
// No scan or context overhead for projects without memory.
if (![...this.store.core.memory.values()].some(value => value.projectId === session.projectId && value.status === 'current')) return null;
let view;
@@ -201,8 +202,8 @@ export class ProjectMemoryManager {
throw error;
}
if (!view.scope.complete || !view.memories.length) return null;
const entryLimit = Math.max(0, Math.min(MEMORY_CONTEXT_LIMITS.entries, Math.floor(maxEntries) || 0));
const byteLimit = Math.max(0, Math.min(MEMORY_CONTEXT_LIMITS.bytes, Math.floor(maxBytes) || 0));
const entryLimit = Math.max(0, Math.min(ceiling(this.store, MEMORY_CONTEXT_LIMITS.entries), Math.floor(maxEntries) || 0));
const byteLimit = Math.max(0, Math.min(ceiling(this.store, MEMORY_CONTEXT_LIMITS.bytes), Math.floor(maxBytes) || 0));
const document = { schemaVersion: 1, kind: 'source-checked-project-memory', projectId: session.projectId,
sourceFingerprint: view.sourceFingerprint, checkedAt: view.inspectedAt, availableEntries: view.memories.length, entries: [] };
for (const memory of view.memories) {