principles-disciple 1.158.0 → 1.159.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.
@@ -17,7 +17,7 @@ import { AGENT_TOOLS, BASH_TOOLS_SET, WRITE_TOOLS } from '../constants/tools.js'
17
17
  import { getSession, hasRecentThinking } from '../core/session-tracker.js';
18
18
  import { getEvolutionEngine } from '../core/evolution-engine.js';
19
19
  import { EventLogService } from '../core/event-log.js';
20
- import { estimateLineChanges } from '../core/risk-calculator.js';
20
+ import { estimateLineChanges } from '@principles/core/runtime-v2';
21
21
  export function handleBeforeToolCall(event, ctx) {
22
22
  const logger = ctx.logger || console;
23
23
  // 1. Identify tool type
@@ -2,7 +2,7 @@
2
2
  "id": "principles-disciple",
3
3
  "name": "Principles Disciple",
4
4
  "description": "Evolutionary programming agent framework with strategic guardrails and reflection loops.",
5
- "version": "1.158.0",
5
+ "version": "1.159.0",
6
6
  "activation": {
7
7
  "onCapabilities": [
8
8
  "hook"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "principles-disciple",
3
- "version": "1.158.0",
3
+ "version": "1.159.0",
4
4
  "description": "Native OpenClaw plugin for Principles Disciple",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,22 +0,0 @@
1
- export type RiskLevel = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
2
- export interface FileModification {
3
- toolName: string;
4
- params: Record<string, unknown>;
5
- }
6
- export declare function estimateLineChanges(modification: FileModification): number;
7
- export declare function assessRiskLevel(filePath: string, modification: FileModification, riskPaths: string[]): RiskLevel;
8
- /**
9
- * Get the total line count of a target file.
10
- * @param absoluteFilePath - Absolute path to the file
11
- * @returns File line count, or null if file doesn't exist or can't be read
12
- */
13
- export declare function getTargetFileLineCount(absoluteFilePath: string): number | null;
14
- /**
15
- * Calculate the effective line limit based on percentage of target file.
16
- * @param targetLineCount - Total lines in target file
17
- * @param percentage - Allowed percentage (0-100)
18
- * @param minLines - Absolute minimum threshold
19
- * @param maxLines - Optional upper bound to prevent misconfiguration
20
- * @returns Maximum allowed lines (at least minLines, at most maxLines if provided)
21
- */
22
- export declare function calculatePercentageThreshold(targetLineCount: number, percentage: number, minLines: number, maxLines?: number): number;
@@ -1,88 +0,0 @@
1
- /* global NodeJS */
2
- import * as fs from 'fs';
3
- import { isRisky } from '../utils/io.js';
4
- export function estimateLineChanges(modification) {
5
- const { toolName, params } = modification;
6
- if (toolName === 'write_file' || toolName === 'write') {
7
- const content = params.content || '';
8
- return content.split('\n').length;
9
- }
10
- if (toolName === 'replace' || toolName === 'edit') {
11
- const newContent = params.new_string || params.newText || '';
12
- return newContent.split('\n').length;
13
- }
14
- if (toolName === 'apply_patch' || toolName === 'patch') {
15
- const patch = params.patch || '';
16
- // Rough estimate for patch files
17
- return patch.split('\n').filter((l) => l.startsWith('+') || l.startsWith('-')).length;
18
- }
19
- if (toolName === 'delete_file') {
20
- // Deleting a file is considered a significant change, but we don't know the size.
21
- // We'll treat it as a medium-to-large size change.
22
- return 50;
23
- }
24
- return 0;
25
- }
26
- export function assessRiskLevel(filePath, modification, riskPaths) {
27
- const isRiskPath = isRisky(filePath, riskPaths);
28
- const estimatedLines = estimateLineChanges(modification);
29
- if (isRiskPath) {
30
- if (estimatedLines > 100)
31
- return 'CRITICAL';
32
- return 'HIGH';
33
- }
34
- else {
35
- if (estimatedLines > 100)
36
- return 'HIGH';
37
- if (estimatedLines > 10)
38
- return 'MEDIUM';
39
- return 'LOW';
40
- }
41
- }
42
- /**
43
- * Get the total line count of a target file.
44
- * @param absoluteFilePath - Absolute path to the file
45
- * @returns File line count, or null if file doesn't exist or can't be read
46
- */
47
- export function getTargetFileLineCount(absoluteFilePath) {
48
- try {
49
- if (!fs.existsSync(absoluteFilePath)) {
50
- return null; // File genuinely doesn't exist
51
- }
52
- const stats = fs.statSync(absoluteFilePath);
53
- if (!stats.isFile()) {
54
- return null; // Not a regular file (directory, device, etc.)
55
- }
56
- const content = fs.readFileSync(absoluteFilePath, 'utf-8');
57
- return content.split('\n').length;
58
- }
59
- catch (e) {
60
- // Log error before falling back to null - this is intentional for security gates
61
- const error = e instanceof Error ? e : new Error(String(e));
62
- const errorCode = e.code;
63
- console.error(`[PD:RISK_CALC] Failed to read file for line count: ${absoluteFilePath}`, {
64
- code: errorCode,
65
- message: error.message,
66
- });
67
- return null;
68
- }
69
- }
70
- /**
71
- * Calculate the effective line limit based on percentage of target file.
72
- * @param targetLineCount - Total lines in target file
73
- * @param percentage - Allowed percentage (0-100)
74
- * @param minLines - Absolute minimum threshold
75
- * @param maxLines - Optional upper bound to prevent misconfiguration
76
- * @returns Maximum allowed lines (at least minLines, at most maxLines if provided)
77
- */
78
- export function calculatePercentageThreshold(targetLineCount, percentage, minLines, maxLines) {
79
- // Clamp percentage to valid range [0, 100]
80
- const clampedPercentage = Math.max(0, Math.min(100, percentage));
81
- const calculated = Math.round(targetLineCount * (clampedPercentage / 100));
82
- let effectiveLimit = Math.max(calculated, minLines);
83
- // Apply optional upper bound
84
- if (maxLines !== undefined && maxLines > 0) {
85
- effectiveLimit = Math.min(effectiveLimit, maxLines);
86
- }
87
- return effectiveLimit;
88
- }