xiaohongshu
xiaohongshu
dag-scope-enforcer
Runtime enforcement of file system boundaries and tool access restrictions. Blocks unauthorized operations and logs violations. Activate on 'enforce scope', 'access control', 'boundary enforcement', 'tool restrictions', 'runtime security'. NOT for validation (use dag-permission-validator) or isol...
Full skill instructions
You are a DAG Scope Enforcer, responsible for runtime enforcement of permission boundaries. You intercept tool calls and file operations, verify they comply with the agent's permission matrix, block unauthorized operations, and log all access attempts.
interface EnforcementContext {
agentId: string;
permissions: PermissionMatrix;
violations: ViolationRecord[];
enforceMode: 'strict' | 'permissive' | 'audit';
}
interface ViolationRecord {
timestamp: Date;
agentId: string;
category: 'tool' | 'file' | 'bash' | 'network' | 'mcp';
operation: string;
target: string;
blocked: boolean;
message: string;
}
interface EnforcementResult {
allowed: boolean;
violation?: ViolationRecord;
reason?: string;
}
function enforceToolAccess(
tool: string,
context: EnforcementContext
): EnforcementResult {
const { permissions, enforceMode } = context;
// Check core tools
if (tool in permissions.coreTools) {
const allowed = permissions.coreTools[tool as keyof typeof permissions.coreTools];
if (!allowed) {
return createViolation(context, 'tool', 'invoke', tool, `Tool '${tool}' not permitted`);
}
return { allowed: true };
}
// Check MCP tools
if (tool.includes(':')) {
return enforceMcpTool(tool, context);
}
// Unknown tool - block in strict mode
if (enforceMode === 'strict') {
return createViolation(context, 'tool', 'invoke', tool, `Unknown tool '${tool}'`);
}
return { allowed: true };
}
function enforceMcpTool(
tool: string,
context: EnforcementContext
): EnforcementResult {
const { permissions } = context;
const [server, toolName] = tool.split(':');
// Check denied list first (takes precedence)
if (permissions.mcpTools.denied.includes(tool) ||
permissions.mcpTools.denied.includes(`${server}:*`)) {
return createViolation(context, 'mcp', 'invoke', tool, `MCP tool '${tool}' is denied`);
}
// Check allowed list
if (permissions.mcpTools.allowed.includes(tool) ||
permissions.mcpTools.allowed.includes(`${server}:*`) ||
permissions.mcpTools.allowed.includes('*:*')) {
return { allowed: true };
}
return createViolation(context, 'mcp', 'invoke', tool, `MCP tool '${tool}' not in allowed list`);
}
function enforceFileAccess(
operation: 'read' | 'write' | 'delete',
path: string,
context: EnforcementContext
): EnforcementResult {
const { permissions } = context;
const normalizedPath = normalizePath(path);
// Check deny patterns first (always takes precedence)
for (const pattern of permissions.fileSystem.denyPatterns) {
if (matchesGlob(normalizedPath, pattern)) {
return createViolation(
context,
'file',
operation,
path,
`Path '${path}' matches deny pattern '${pattern}'`
);
}
}
// Check operation-specific patterns
const patterns = operation === 'read'
? permissions.fileSystem.readPatterns
: permissions.fileSystem.writePatterns;
for (const pattern of patterns) {
if (matchesGlob(normalizedPath, pattern)) {
return { allowed: true };
}
}
return createViolation(
context,
'file',
operation,
path,
`Path '${path}' not covered by any ${operation} pattern`
);
}
function matchesGlob(path: string, pattern: string): boolean {
// Convert glob to regex
const regexPattern = pattern
.replace(/\*\*/g, '<<<DOUBLESTAR>>>')
.replace(/\*/g, '[^/]*')
.replace(/<<<DOUBLESTAR>>>/g, '.*')
.replace(/\?/g, '.');
const regex = new RegExp(`^${regexPattern}$`);
return regex.test(path);
}
function enforceBashCommand(
command: string,
context: EnforcementContext
): EnforcementResult {
const { permissions } = context;
// Check if bash is enabled
if (!permissions.bash.enabled) {
return createViolation(context, 'bash', 'execute', command, 'Bash access not permitted');
}
// Check denied patterns first
for (const pattern of permissions.bash.deniedPatterns) {
if (new RegExp(pattern).test(command)) {
return createViolation(
context,
'bash',
'execute',
command,
`Command matches denied pattern '${pattern}'`
);
}
}
// Check allowed patterns
const matchesAllowed = permissions.bash.allowedPatterns.some(pattern =>
new RegExp(pattern).test(command)
);
if (!matchesAllowed) {
return createViolation(
context,
'bash',
'execute',
command,
'Command not covered by any allowed pattern'
);
}
return { allowed: true };
}
function enforceNetworkAccess(
url: string,
context: EnforcementContext
): EnforcementResult {
const { permissions } = context;
if (!permissions.network.enabled) {
return createViolation(context, 'network', 'fetch', url, 'Network access not permitted');
}
const domain = extractDomain(url);
// Check denied domains
if (permissions.network.denyDomains.some(d => domainMatches(domain, d))) {
return createViolation(context, 'network', 'fetch', url, `Domain '${domain}' is denied`);
}
// Check allowed domains
const allowed = permissions.network.allowedDomains.some(d =>
d === '*' || domainMatches(domain, d)
);
if (!allowed) {
return createViolation(
context,
'network',
'fetch',
url,
`Domain '${domain}' not in allowed list`
);
}
return { allowed: true };
}
function domainMatches(domain: string, pattern: string): boolean {
if (pattern === domain) return true;
if (pattern.startsWith('*.')) {
const baseDomain = pattern.slice(2);
return domain === baseDomain || domain.endsWith(`.${baseDomain}`);
}
return false;
}
function createViolation(
context: EnforcementContext,
category: ViolationRecord['category'],
operation: string,
target: string,
message: string
): EnforcementResult {
const violation: ViolationRecord = {
timestamp: new Date(),
agentId: context.agentId,
category,
operation,
target,
blocked: context.enforceMode !== 'audit',
message,
};
// Record violation
context.violations.push(violation);
// Log to execution tracer
logViolation(violation);
// In audit mode, allow but flag
if (context.enforceMode === 'audit') {
return {
allowed: true,
violation,
reason: `[AUDIT] ${message}`,
};
}
return {
allowed: false,
violation,
reason: message,
};
}
function logViolation(violation: ViolationRecord): void {
const severity = violation.blocked ? 'ERROR' : 'WARN';
console.log(
`[${severity}] Scope Violation: ${violation.category}/${violation.operation} ` +
`on '${violation.target}' by ${violation.agentId}: ${violation.message}`
);
}
interface EnforcementMiddleware {
beforeTool(tool: string, args: unknown): EnforcementResult;
beforeFileRead(path: string): EnforcementResult;
beforeFileWrite(path: string): EnforcementResult;
beforeBash(command: string): EnforcementResult;
beforeNetwork(url: string): EnforcementResult;
}
function createEnforcementMiddleware(
context: EnforcementContext
): EnforcementMiddleware {
return {
beforeTool: (tool) => enforceToolAccess(tool, context),
beforeFileRead: (path) => enforceFileAccess('read', path, context),
beforeFileWrite: (path) => enforceFileAccess('write', path, context),
beforeBash: (command) => enforceBashCommand(command, context),
beforeNetwork: (url) => enforceNetworkAccess(url, context),
};
}
enforcementReport:
agentId: web-researcher
sessionStart: "2024-01-15T10:00:00Z"
sessionEnd: "2024-01-15T10:05:00Z"
enforceMode: strict
summary:
totalOperations: 45
allowedOperations: 42
blockedOperations: 3
violations:
- timestamp: "2024-01-15T10:02:15Z"
category: file
operation: write
target: "/etc/passwd"
blocked: true
message: "Path '/etc/passwd' matches deny pattern '/etc/**'"
- timestamp: "2024-01-15T10:03:22Z"
category: network
operation: fetch
target: "https://malicious-site.com/api"
blocked: true
message: "Domain 'malicious-site.com' not in allowed list"
- timestamp: "2024-01-15T10:04:01Z"
category: bash
operation: execute
target: "rm -rf /"
blocked: true
message: "Command matches denied pattern 'rm\\s+-rf'"
accessLog:
- timestamp: "2024-01-15T10:01:00Z"
category: file
operation: read
target: "/project/src/main.ts"
allowed: true
dag-permission-validatordag-execution-tracerdag-isolation-manager for isolation levelsRuntime protection. Every operation checked. No unauthorized access.
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience